Echo 5a3920215f [Glitch] Keep trying to load emojis if data isn't available yet
Port 708fe319080c92f2763e1d14fdce7bd132050237 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-05-04 21:10:47 +02:00

36 lines
803 B
TypeScript

import { useEffect, useState } from 'react';
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
let emojis: ExtraCustomEmojiMap | null = null;
export function useCustomEmojis() {
const [, setLoaded] = useState(emojis !== null);
useEffect(() => {
if (!emojis) {
void loadEmojisIntoCache().then(() => {
setLoaded(true);
});
}
}, []);
return emojis;
}
async function loadEmojisIntoCache() {
const { loadAllCustomEmoji } = await import('../features/emoji/database');
const emojisRaw = await loadAllCustomEmoji();
if (emojisRaw === null) {
return;
}
emojis = {};
for (const emoji of emojisRaw) {
emojis[emoji.shortcode] = {
url: emoji.url,
shortcode: emoji.shortcode,
static_url: emoji.static_url,
};
}
}