diff --git a/packages/frontend/src/components/MkEmojiPicker.vue b/packages/frontend/src/components/MkEmojiPicker.vue index abb14564fb..3399124e85 100644 --- a/packages/frontend/src/components/MkEmojiPicker.vue +++ b/packages/frontend/src/components/MkEmojiPicker.vue @@ -88,7 +88,7 @@ import { deviceKind } from '@/scripts/device-kind'; import { instance } from '@/instance'; import { i18n } from '@/i18n'; import { defaultStore } from '@/store'; -import { getCustomEmojiCategories, customEmojis } from '@/custom-emojis'; +import { customEmojiCategories, customEmojis } from '@/custom-emojis'; const props = withDefaults(defineProps<{ showPinned?: boolean; @@ -104,7 +104,6 @@ const emit = defineEmits<{ (ev: 'chosen', v: string): void; }>(); -const customEmojiCategories = getCustomEmojiCategories(); const searchEl = shallowRef(); const emojisEl = shallowRef(); diff --git a/packages/frontend/src/custom-emojis.ts b/packages/frontend/src/custom-emojis.ts index 8fd5078bde..57842459bd 100644 --- a/packages/frontend/src/custom-emojis.ts +++ b/packages/frontend/src/custom-emojis.ts @@ -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(storageCache ? JSON.parse(storageCache) : []); +export const customEmojiCategories = computed(() => { + const categories = new Set(); + 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; diff --git a/packages/frontend/src/pages/about.emojis.vue b/packages/frontend/src/pages/about.emojis.vue index 7d146d1fdb..d964e48b31 100644 --- a/packages/frontend/src/pages/about.emojis.vue +++ b/packages/frontend/src/pages/about.emojis.vue @@ -39,11 +39,10 @@ import MkSelect from '@/components/MkSelect.vue'; import MkFoldableSection from '@/components/MkFoldableSection.vue'; import MkTab from '@/components/MkTab.vue'; import * as os from '@/os'; -import { customEmojis, getCustomEmojiCategories, getCustomEmojiTags } from '@/custom-emojis'; +import { customEmojis, customEmojiCategories, getCustomEmojiTags } from '@/custom-emojis'; import { i18n } from '@/i18n'; import * as Misskey from 'misskey-js'; -const customEmojiCategories = getCustomEmojiCategories(); const customEmojiTags = getCustomEmojiTags(); let q = $ref(''); let searchEmojis = $ref(null); diff --git a/packages/frontend/src/pages/emoji-edit-dialog.vue b/packages/frontend/src/pages/emoji-edit-dialog.vue index b2880b60b1..4d84ed7f16 100644 --- a/packages/frontend/src/pages/emoji-edit-dialog.vue +++ b/packages/frontend/src/pages/emoji-edit-dialog.vue @@ -15,7 +15,7 @@ - + @@ -36,7 +36,7 @@ import MkInput from '@/components/MkInput.vue'; import * as os from '@/os'; import { unique } from '@/scripts/array'; import { i18n } from '@/i18n'; -import { getCustomEmojiCategories } from '@/custom-emojis'; +import { customEmojiCategories } from '@/custom-emojis'; const props = defineProps<{ emoji: any, @@ -46,7 +46,6 @@ let dialog = $ref(null); let name: string = $ref(props.emoji.name); let category: string = $ref(props.emoji.category); let aliases: string = $ref(props.emoji.aliases.join(' ')); -const categories = getCustomEmojiCategories(); const emit = defineEmits<{ (ev: 'done', v: { deleted?: boolean, updated?: any }): void,