Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'EmojiUtils.js' lib to TypeScript #28589

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions assets/emojis/common.js → assets/emojis/common.ts
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Objects from '../images/emojiCategoryIcons/light-bulb.svg';
import Symbols from '../images/emojiCategoryIcons/peace-sign.svg';
import Flags from '../images/emojiCategoryIcons/flag.svg';
import FrequentlyUsed from '../images/history.svg';
import {PickerEmojis} from './types';

const skinTones = [
{
Expand All @@ -33,9 +34,9 @@ const skinTones = [
code: '🖐🏿',
skinTone: 0,
},
];
] as const;

const emojis = [
const emojis: PickerEmojis = [
{
header: true,
icon: Smiley,
Expand Down
5 changes: 4 additions & 1 deletion assets/emojis/en.js → assets/emojis/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const enEmojis = {
import {EmojisList} from './types';

/* eslint-disable @typescript-eslint/naming-convention */
const enEmojis: EmojisList = {
'😀': {
keywords: ['smile', 'happy', 'face', 'grin'],
},
Expand Down
5 changes: 4 additions & 1 deletion assets/emojis/es.js → assets/emojis/es.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const esEmojis = {
import {EmojisList} from './types';

/* eslint-disable @typescript-eslint/naming-convention */
const esEmojis: EmojisList = {
'😀': {
name: 'sonriendo',
keywords: ['cara', 'divertido', 'feliz', 'sonrisa', 'cara sonriendo'],
Expand Down
41 changes: 0 additions & 41 deletions assets/emojis/index.js

This file was deleted.

35 changes: 35 additions & 0 deletions assets/emojis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import emojis from './common';
import enEmojis from './en';
import esEmojis from './es';
import {Emoji} from './types';

type EmojiTable = Record<string, Emoji>;

const emojiNameTable: EmojiTable = emojis.reduce((prev, cur) => {
const newValue: EmojiTable = prev;
if (!('header' in cur) && cur.name) {
newValue[cur.name] = cur;
}
return newValue;
}, {});
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved

const emojiCodeTableWithSkinTones: EmojiTable = emojis.reduce((prev, cur) => {
const newValue: EmojiTable = prev;
if (!('header' in cur)) {
newValue[cur.code] = cur;
}
if ('types' in cur && cur.types) {
cur.types.forEach((type) => {
newValue[type] = cur;
});
}
return newValue;
}, {});

const localeEmojis = {
en: enEmojis,
es: esEmojis,
} as const;

export {emojiNameTable, emojiCodeTableWithSkinTones, localeEmojis};
export {skinTones, categoryFrequentlyUsed, default} from './common';
19 changes: 19 additions & 0 deletions assets/emojis/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {SvgProps} from 'react-native-svg';

type Emoji = {
code: string;
name: string;
types?: string[];
};

type HeaderEmoji = {
header: true;
icon: React.FC<SvgProps>;
code: string;
};

type PickerEmojis = Array<Emoji | HeaderEmoji>;

type EmojisList = Record<string, {keywords: string[]; name?: string}>;
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved

export type {Emoji, HeaderEmoji, EmojisList, PickerEmojis};
5 changes: 4 additions & 1 deletion src/libs/EmojiTrie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ type LocalizedEmojis = Record<string, LocalizedEmoji>;
type Suggestion = {
code: string;
types?: string[];
name?: string;
name: string;
};

type EmojiMetaData = {
suggestions?: Suggestion[];
code?: string;
types?: string[];
name?: string;
};

Timing.start(CONST.TIMING.TRIE_INITIALIZATION);
Expand Down
Loading
Loading