Echo abc86b8704 [Glitch] Emoji loading performance
Port 5bc69ea668192f253ff032dbdc5c9213e2b0c03e to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-04-25 09:26:24 +02:00

36 lines
807 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.length === 0) {
return;
}
emojis = {};
for (const emoji of emojisRaw) {
emojis[emoji.shortcode] = {
url: emoji.url,
shortcode: emoji.shortcode,
static_url: emoji.static_url,
};
}
}