customEmojiCategories as computed

This commit is contained in:
tamaina
2023-01-16 10:36:29 +00:00
parent f2a9194c79
commit 43956f3ffb
4 changed files with 12 additions and 21 deletions

View File

@@ -1,10 +1,17 @@
import { apiGet } from './os';
import { miLocalStorage } from './local-storage';
import { shallowRef } from 'vue';
import { shallowRef, computed, markRaw } from 'vue';
import * as Misskey from 'misskey-js';
const storageCache = miLocalStorage.getItem('emojis');
export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(storageCache ? JSON.parse(storageCache) : []);
export const customEmojiCategories = computed<string[]>(() => {
const categories = new Set<string>();
for (const emoji of customEmojis.value) {
categories.add(emoji.category);
}
return markRaw(Array.from(categories));
});
fetchCustomEmojis();
window.setInterval(fetchCustomEmojis, 1000 * 60 * 10);
@@ -21,19 +28,6 @@ export async function fetchCustomEmojis() {
miLocalStorage.setItem('lastEmojisFetchedAt', now.toString());
}
let cachedCategories;
export function getCustomEmojiCategories() {
if (cachedCategories) return cachedCategories;
const categories = new Set();
for (const emoji of customEmojis.value) {
categories.add(emoji.category);
}
const res = Array.from(categories);
cachedCategories = res;
return res;
}
let cachedTags;
export function getCustomEmojiTags() {
if (cachedTags) return cachedTags;