Skip to content
Snippets Groups Projects
Commit 43956f3f authored by tamaina's avatar tamaina
Browse files

customEmojiCategories as computed

parent f2a9194c
No related branches found
No related tags found
No related merge requests found
......@@ -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<HTMLInputElement>();
const emojisEl = shallowRef<HTMLDivElement>();
......
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;
......
......@@ -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<Misskey.entities.CustomEmoji[]>(null);
......
......@@ -15,7 +15,7 @@
<MkInput v-model="name">
<template #label>{{ i18n.ts.name }}</template>
</MkInput>
<MkInput v-model="category" :datalist="categories">
<MkInput v-model="category" :datalist="customEmojiCategories">
<template #label>{{ i18n.ts.category }}</template>
</MkInput>
<MkInput v-model="aliases">
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment