mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-28 14:30:39 +01:00
customEmojiCategories as computed
This commit is contained in:
parent
f2a9194c79
commit
43956f3ffb
4 changed files with 12 additions and 21 deletions
|
@ -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>();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue