From bd9a33201ab5fac9992dd92c52b9cbd6787e269b Mon Sep 17 00:00:00 2001 From: ewwwwwwww Date: Mon, 4 Jul 2022 20:59:39 -0700 Subject: [PATCH] convert type to union --- app/soapbox/components/autosuggest_emoji.tsx | 4 +--- app/soapbox/features/emoji/index.ts | 13 +++++++------ app/soapbox/features/emoji/search.ts | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/soapbox/components/autosuggest_emoji.tsx b/app/soapbox/components/autosuggest_emoji.tsx index 34d7c0dbf..363790684 100644 --- a/app/soapbox/components/autosuggest_emoji.tsx +++ b/app/soapbox/components/autosuggest_emoji.tsx @@ -20,7 +20,7 @@ const AutosuggestEmoji: React.FC = ({ emoji }) => { if (isCustomEmoji(emoji)) { url = emoji.imageUrl; alt = emoji.colons; - } else if (isNativeEmoji(emoji)) { + } else { const mapping = unicodeMapping[emoji.native] || unicodeMapping[emoji.native.replace(/\uFE0F$/, '')]; if (!mapping) { @@ -29,8 +29,6 @@ const AutosuggestEmoji: React.FC = ({ emoji }) => { url = joinPublicPath(`packs/emoji/${mapping.unified}.svg`); alt = emoji.native; - } else { - return
} return ( diff --git a/app/soapbox/features/emoji/index.ts b/app/soapbox/features/emoji/index.ts index 88420149c..b9cc3fd8f 100644 --- a/app/soapbox/features/emoji/index.ts +++ b/app/soapbox/features/emoji/index.ts @@ -21,22 +21,23 @@ import type { Emoji as EmojiMart, CustomEmoji as EmojiMartCustom } from 'emoji-m * and one type that is used everywhere that the above two are converted into */ -export interface Emoji { +export interface CustomEmoji { id: string, colons: string, - custom?: boolean, -} - -export interface CustomEmoji extends Emoji { custom: true, imageUrl: string, } -export interface NativeEmoji extends Emoji { +export interface NativeEmoji { + id: string, + colons: string, + custom?: boolean, unified: string, native: string, } +export type Emoji = CustomEmoji | NativeEmoji; + export function isCustomEmoji(emoji: Emoji): emoji is CustomEmoji { return (emoji as CustomEmoji).imageUrl !== undefined; } diff --git a/app/soapbox/features/emoji/search.ts b/app/soapbox/features/emoji/search.ts index eff9b347a..339debced 100644 --- a/app/soapbox/features/emoji/search.ts +++ b/app/soapbox/features/emoji/search.ts @@ -2,6 +2,8 @@ import { Index } from 'flexsearch'; import data from './data'; +import { Emoji as EmojiType } from './index'; + import type { Emoji, CustomEmoji } from 'emoji-mart'; const index = new Index({ @@ -25,7 +27,7 @@ export const addCustomToPool = (customEmojis: Emoji[]) => { } }; -const search = (str: string, options: searchOptions, custom_emojis: any) => { +const search = (str: string, options: searchOptions, custom_emojis: any): EmojiType[] => { return index.search(str, options.maxResults) .flatMap(id => { if (Number.isInteger(id)) {