diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2023-01-16 09:39:58 +0000 |
|---|---|---|
| committer | tamaina <tamaina@hotmail.co.jp> | 2023-01-16 09:39:58 +0000 |
| commit | 21e4c3dfe9b439a76782ab86be93298de2878ab9 (patch) | |
| tree | b8684d49b8b8e17f4199133b4a7ec76affc6fede /packages/frontend/src/custom-emojis.ts | |
| parent | 13.0.0 (diff) | |
| download | misskey-21e4c3dfe9b439a76782ab86be93298de2878ab9.tar.gz misskey-21e4c3dfe9b439a76782ab86be93298de2878ab9.tar.bz2 misskey-21e4c3dfe9b439a76782ab86be93298de2878ab9.zip | |
wip
Diffstat (limited to 'packages/frontend/src/custom-emojis.ts')
| -rw-r--r-- | packages/frontend/src/custom-emojis.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/packages/frontend/src/custom-emojis.ts b/packages/frontend/src/custom-emojis.ts index 19469999b6..52a1148236 100644 --- a/packages/frontend/src/custom-emojis.ts +++ b/packages/frontend/src/custom-emojis.ts @@ -1,20 +1,22 @@ -import { api } from './os'; +import { apiGet } from './os'; import { miLocalStorage } from './local-storage'; +import { shallowRef } from 'vue'; +import * as Misskey from 'misskey-js'; const storageCache = miLocalStorage.getItem('emojis'); -export let customEmojis = storageCache ? JSON.parse(storageCache) : []; +export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(storageCache ? JSON.parse(storageCache) : []); fetchCustomEmojis(); export async function fetchCustomEmojis() { const now = Date.now(); const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt'); - if (lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return; + if (lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60) return; - const res = await api('emojis', {}); + const res = await apiGet('emojis', {}); - customEmojis = res.emojis; - miLocalStorage.setItem('emojis', JSON.stringify(customEmojis)); + customEmojis.value = res.emojis; + miLocalStorage.setItem('emojis', JSON.stringify(res.emojis)); miLocalStorage.setItem('lastEmojisFetchedAt', now.toString()); } @@ -23,7 +25,7 @@ export function getCustomEmojiCategories() { if (cachedCategories) return cachedCategories; const categories = new Set(); - for (const emoji of customEmojis) { + for (const emoji of customEmojis.value) { categories.add(emoji.category); } const res = Array.from(categories); @@ -36,7 +38,7 @@ export function getCustomEmojiTags() { if (cachedTags) return cachedTags; const tags = new Set(); - for (const emoji of customEmojis) { + for (const emoji of customEmojis.value) { for (const tag of emoji.aliases) { tags.add(tag); } |