This commit is contained in:
syuilo 2023-01-09 16:45:05 +09:00
parent 8cc80faf20
commit 39c3995c74
7 changed files with 20 additions and 36 deletions

View File

@ -47,9 +47,7 @@ import { emojilist } from '@/scripts/emojilist';
import { instance } from '@/instance'; import { instance } from '@/instance';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { miLocalStorage } from '@/local-storage'; import { miLocalStorage } from '@/local-storage';
import { getCustomEmojis } from '@/custom-emojis'; import { customEmojis } from '@/custom-emojis';
const customEmojis = await getCustomEmojis();
type EmojiDef = { type EmojiDef = {
emoji: string; emoji: string;

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="omfetrab" :class="['s' + size, 'w' + width, 'h' + height, { asDrawer, asWindow }]" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : undefined }"> <div class="omfetrab" :class="['s' + size, 'w' + width, 'h' + height, { asDrawer, asWindow }]" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : undefined }">
<input ref="search" :value="q" class="search" data-prevent-emoji-insert :class="{ filled: q != null && q != '' }" :placeholder="i18n.ts.search" type="search" @input="input()" @paste.stop="paste" @keyup.enter="done()"> <input ref="search" :value="q" class="search" data-prevent-emoji-insert :class="{ filled: q != null && q != '' }" :placeholder="i18n.ts.search" type="search" @input="input()" @paste.stop="paste" @keyup.enter="done()">
<div v-if="customEmojis != null && customEmojiCategories != null" ref="emojisEl" class="emojis"> <div ref="emojisEl" class="emojis">
<section class="result"> <section class="result">
<div v-if="searchResultCustom.length > 0" class="body"> <div v-if="searchResultCustom.length > 0" class="body">
<button <button
@ -88,7 +88,7 @@ import { deviceKind } from '@/scripts/device-kind';
import { instance } from '@/instance'; import { instance } from '@/instance';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { defaultStore } from '@/store'; import { defaultStore } from '@/store';
import { getCustomEmojiCategories, getCustomEmojis } from '@/custom-emojis'; import { getCustomEmojiCategories, customEmojis } from '@/custom-emojis';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
showPinned?: boolean; showPinned?: boolean;
@ -104,15 +104,7 @@ const emit = defineEmits<{
(ev: 'chosen', v: string): void; (ev: 'chosen', v: string): void;
}>(); }>();
let customEmojis = $ref(null); const customEmojiCategories = getCustomEmojiCategories();
getCustomEmojis().then((x) => {
customEmojis = x;
});
let customEmojiCategories = $ref(null);
getCustomEmojiCategories().then((x) => {
customEmojiCategories = x;
});
const search = shallowRef<HTMLInputElement>(); const search = shallowRef<HTMLInputElement>();
const emojisEl = shallowRef<HTMLDivElement>(); const emojisEl = shallowRef<HTMLDivElement>();

View File

@ -2,25 +2,26 @@ import { api } from './os';
import { miLocalStorage } from './local-storage'; import { miLocalStorage } from './local-storage';
const storageCache = miLocalStorage.getItem('emojis'); const storageCache = miLocalStorage.getItem('emojis');
let cached = storageCache ? JSON.parse(storageCache) : null; export let customEmojis = storageCache ? JSON.parse(storageCache) : [];
export async function getCustomEmojis() {
fetchCustomEmojis();
export async function fetchCustomEmojis() {
const now = Date.now(); const now = Date.now();
const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt'); const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt');
if (cached && lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return cached; if (lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return;
const res = await api('emojis', {}); const res = await api('emojis', {});
cached = res.emojis; customEmojis = res.emojis;
miLocalStorage.setItem('emojis', JSON.stringify(cached)); miLocalStorage.setItem('emojis', JSON.stringify(customEmojis));
miLocalStorage.setItem('lastEmojisFetchedAt', now.toString()); miLocalStorage.setItem('lastEmojisFetchedAt', now.toString());
} }
let cachedCategories; let cachedCategories;
export async function getCustomEmojiCategories() { export function getCustomEmojiCategories() {
if (cachedCategories) return cachedCategories; if (cachedCategories) return cachedCategories;
const customEmojis = await getCustomEmojis();
const categories = new Set(); const categories = new Set();
for (const emoji of customEmojis) { for (const emoji of customEmojis) {
categories.add(emoji.category); categories.add(emoji.category);
@ -31,11 +32,9 @@ export async function getCustomEmojiCategories() {
} }
let cachedTags; let cachedTags;
export async function getCustomEmojiTags() { export function getCustomEmojiTags() {
if (cachedTags) return cachedTags; if (cachedTags) return cachedTags;
const customEmojis = await getCustomEmojis();
const tags = new Set(); const tags = new Set();
for (const emoji of customEmojis) { for (const emoji of customEmojis) {
for (const tag of emoji.aliases) { for (const tag of emoji.aliases) {

View File

@ -37,11 +37,10 @@ import MkSelect from '@/components/MkSelect.vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue'; import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkTab from '@/components/MkTab.vue'; import MkTab from '@/components/MkTab.vue';
import * as os from '@/os'; import * as os from '@/os';
import { getCustomEmojis, getCustomEmojiCategories, getCustomEmojiTags } from '@/custom-emojis'; import { customEmojis, getCustomEmojiCategories, getCustomEmojiTags } from '@/custom-emojis';
const customEmojis = await getCustomEmojis(); const customEmojiCategories = getCustomEmojiCategories();
const customEmojiCategories = await getCustomEmojiCategories(); const customEmojiTags = getCustomEmojiTags();
const customEmojiTags = await getCustomEmojiTags();
let q = $ref(''); let q = $ref('');
let searchEmojis = $ref(null); let searchEmojis = $ref(null);
let selectedTags = $ref(new Set()); let selectedTags = $ref(new Set());

View File

@ -46,7 +46,7 @@ let dialog = $ref(null);
let name: string = $ref(props.emoji.name); let name: string = $ref(props.emoji.name);
let category: string = $ref(props.emoji.category); let category: string = $ref(props.emoji.category);
let aliases: string = $ref(props.emoji.aliases.join(' ')); let aliases: string = $ref(props.emoji.aliases.join(' '));
const categories = await getCustomEmojiCategories(); const categories = getCustomEmojiCategories();
const emit = defineEmits<{ const emit = defineEmits<{
(ev: 'done', v: { deleted?: boolean, updated?: any }): void, (ev: 'done', v: { deleted?: boolean, updated?: any }): void,

View File

@ -63,9 +63,7 @@ import number from '@/filters/number';
import MkNumberDiff from '@/components/MkNumberDiff.vue'; import MkNumberDiff from '@/components/MkNumberDiff.vue';
import MkNumber from '@/components/MkNumber.vue'; import MkNumber from '@/components/MkNumber.vue';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { getCustomEmojis } from '@/custom-emojis'; import { customEmojis } from '@/custom-emojis';
const customEmojis = await getCustomEmojis();
let stats: any = $ref(null); let stats: any = $ref(null);
let usersComparedToThePrevDay = $ref<number>(); let usersComparedToThePrevDay = $ref<number>();

View File

@ -317,9 +317,7 @@ import MkTextarea from '@/components/MkTextarea.vue';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { instance } from '@/instance'; import { instance } from '@/instance';
import { getCustomEmojis } from '@/custom-emojis'; import { customEmojis } from '@/custom-emojis';
const customEmojis = await getCustomEmojis();
let preview_mention = $ref('@example'); let preview_mention = $ref('@example');
let preview_hashtag = $ref('#test'); let preview_hashtag = $ref('#test');