Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/entity-text.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import type { GetENSNames } from './ens-helpers.js'; | import type { GetENSNames } from './ens-helpers.js'; | ||||
import { useENSNames } from '../hooks/ens-cache.js'; | import { useENSNames } from '../hooks/ens-cache.js'; | ||||
import { threadNoun } from '../shared/thread-utils.js'; | import { threadNoun } from '../shared/thread-utils.js'; | ||||
import { stringForUser } from '../shared/user-utils.js'; | import { stringForUser } from '../shared/user-utils.js'; | ||||
import type { ClientAvatar } from '../types/avatar-types.js'; | |||||
import { | import { | ||||
threadTypes, | threadTypes, | ||||
type ThreadType, | type ThreadType, | ||||
type RawThreadInfo, | type RawThreadInfo, | ||||
type ThreadInfo, | type ThreadInfo, | ||||
} from '../types/thread-types.js'; | } from '../types/thread-types.js'; | ||||
import { basePluralize } from '../utils/text-utils.js'; | import { basePluralize } from '../utils/text-utils.js'; | ||||
type UserEntity = { | type UserEntity = { | ||||
+type: 'user', | +type: 'user', | ||||
+id: string, | +id: string, | ||||
+username?: ?string, | +username?: ?string, | ||||
+avatar?: ?ClientAvatar, | |||||
+isViewer?: ?boolean, | +isViewer?: ?boolean, | ||||
+possessive?: ?boolean, // eg. `user's` instead of `user` | +possessive?: ?boolean, // eg. `user's` instead of `user` | ||||
}; | }; | ||||
// Comments explain how thread name will appear from user4's perspective | // Comments explain how thread name will appear from user4's perspective | ||||
export type ThreadEntity = | export type ThreadEntity = | ||||
| { | | { | ||||
+type: 'thread', | +type: 'thread', | ||||
Show All 18 Lines | | { | ||||
+possessive?: ?boolean, // eg. `this thread's` instead of `this thread` | +possessive?: ?boolean, // eg. `this thread's` instead of `this thread` | ||||
}; | }; | ||||
type ColorEntity = { | type ColorEntity = { | ||||
+type: 'color', | +type: 'color', | ||||
+hex: string, | +hex: string, | ||||
}; | }; | ||||
type EntityTextComponent = UserEntity | ThreadEntity | ColorEntity | string; | export type EntityTextComponent = | ||||
| UserEntity | |||||
| ThreadEntity | |||||
| ColorEntity | |||||
| string; | |||||
export type EntityText = $ReadOnlyArray<EntityTextComponent>; | export type EntityText = $ReadOnlyArray<EntityTextComponent>; | ||||
const entityTextFunction = ( | const entityTextFunction = ( | ||||
strings: $ReadOnlyArray<string>, | strings: $ReadOnlyArray<string>, | ||||
...entities: $ReadOnlyArray<EntityTextComponent | EntityText> | ...entities: $ReadOnlyArray<EntityTextComponent | EntityText> | ||||
) => { | ) => { | ||||
const result = []; | const result = []; | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | entityTextFunction.thread = (input: EntityTextThreadInput) => { | ||||
} | } | ||||
invariant( | invariant( | ||||
false, | false, | ||||
`ET.thread passed unexpected display type: ${input.display}`, | `ET.thread passed unexpected display type: ${input.display}`, | ||||
); | ); | ||||
}; | }; | ||||
type EntityTextUserInput = { | type EntityTextUserInput = { | ||||
+userInfo: { | +userInfo: { | ||||
ashoat: Do you need to update this to include avatar? | |||||
+id: string, | +id: string, | ||||
+username?: ?string, | +username?: ?string, | ||||
+isViewer?: ?boolean, | +isViewer?: ?boolean, | ||||
... | ... | ||||
}, | }, | ||||
+possessive?: ?boolean, | +possessive?: ?boolean, | ||||
}; | }; | ||||
entityTextFunction.user = (input: EntityTextUserInput) => ({ | entityTextFunction.user = (input: EntityTextUserInput) => ({ | ||||
type: 'user', | type: 'user', | ||||
id: input.userInfo.id, | id: input.userInfo.id, | ||||
username: input.userInfo.username, | username: input.userInfo.username, | ||||
isViewer: input.userInfo.isViewer, | isViewer: input.userInfo.isViewer, | ||||
possessive: input.possessive, | possessive: input.possessive, | ||||
ashoatUnsubmitted Not Done Inline ActionsThis returns a UserEntity (see type on line 215). Do you need to update this to include avatar? ashoat: This returns a `UserEntity` (see type on line 215). Do you need to update this to include… | |||||
}); | }); | ||||
type EntityTextColorInput = { +hex: string }; | type EntityTextColorInput = { +hex: string }; | ||||
entityTextFunction.color = (input: EntityTextColorInput) => ({ | entityTextFunction.color = (input: EntityTextColorInput) => ({ | ||||
type: 'color', | type: 'color', | ||||
hex: input.hex, | hex: input.hex, | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 328 Lines • Show Last 20 Lines |
Do you need to update this to include avatar?