Echo f6cf58039c [Glitch] Emojis: Fix bug with search + improve custom tokenization
Port c39072ad9d2b531a04c0192f06018fbd8d737f69 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-05-26 22:13:10 +02:00

41 lines
1.0 KiB
TypeScript

import { useEffect, useState } from 'react';
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
import { emojiLogger } from '../features/emoji/utils';
let emojis: ExtraCustomEmojiMap | null = null;
const log = emojiLogger('useCustomEmojis');
export function useCustomEmojis() {
const [, setLoaded] = useState(emojis !== null);
useEffect(() => {
if (!emojis) {
void loadEmojisIntoCache().then(() => {
setLoaded(true);
});
}
}, []);
return emojis;
}
export async function loadEmojisIntoCache() {
const { loadAllCustomEmoji } = await import('../features/emoji/database');
const emojisRaw = await loadAllCustomEmoji();
if (emojisRaw === null) {
log('Custom emojis not loaded yet');
return;
}
emojis = {};
for (const emoji of emojisRaw) {
emojis[emoji.shortcode] = {
url: emoji.url,
shortcode: emoji.shortcode,
static_url: emoji.static_url,
};
}
log('Loaded %d custom emojis into cache', Object.keys(emojis).length);
}