Convert polls to Typescript / Immutable Records (#29789)
This commit is contained in:
parent
e4e35ab134
commit
ded799f913
15 changed files with 272 additions and 186 deletions
|
@ -1,15 +1,32 @@
|
|||
import type { RecordOf } from 'immutable';
|
||||
import { Record } from 'immutable';
|
||||
import type { RecordOf, List as ImmutableList } from 'immutable';
|
||||
import { Record as ImmutableRecord, isList } from 'immutable';
|
||||
|
||||
import type { ApiCustomEmojiJSON } from 'mastodon/api_types/custom_emoji';
|
||||
|
||||
type CustomEmojiShape = Required<ApiCustomEmojiJSON>; // no changes from server shape
|
||||
export type CustomEmoji = RecordOf<CustomEmojiShape>;
|
||||
|
||||
export const CustomEmojiFactory = Record<CustomEmojiShape>({
|
||||
export const CustomEmojiFactory = ImmutableRecord<CustomEmojiShape>({
|
||||
shortcode: '',
|
||||
static_url: '',
|
||||
url: '',
|
||||
category: '',
|
||||
visible_in_picker: false,
|
||||
});
|
||||
|
||||
export type EmojiMap = Record<string, ApiCustomEmojiJSON>;
|
||||
|
||||
export function makeEmojiMap(
|
||||
emojis: ApiCustomEmojiJSON[] | ImmutableList<CustomEmoji>,
|
||||
) {
|
||||
if (isList(emojis)) {
|
||||
return emojis.reduce<EmojiMap>((obj, emoji) => {
|
||||
obj[`:${emoji.shortcode}:`] = emoji.toJS();
|
||||
return obj;
|
||||
}, {});
|
||||
} else
|
||||
return emojis.reduce<EmojiMap>((obj, emoji) => {
|
||||
obj[`:${emoji.shortcode}:`] = emoji;
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue