refactor(frontend): boot分割したり副作用減らしたりとか

#10838
This commit is contained in:
syuilo
2023-05-15 19:08:46 +09:00
parent a7ee4aabcb
commit 23f106a0c1
26 changed files with 628 additions and 573 deletions

View File

@@ -1,8 +1,7 @@
import { shallowRef, computed, markRaw } from 'vue';
import * as Misskey from 'misskey-js';
import { api, apiGet } from './os';
import { miLocalStorage } from './local-storage';
import { stream } from '@/stream';
import { useStream } from '@/stream';
import { get, set } from '@/scripts/idb-proxy';
const storageCache = await get('emojis');
@@ -17,6 +16,9 @@ export const customEmojiCategories = computed<[ ...string[], null ]>(() => {
return markRaw([...Array.from(categories), null]);
});
// TODO: ここら辺副作用なのでいい感じにする
const stream = useStream();
stream.on('emojiAdded', emojiData => {
customEmojis.value = [emojiData.emoji, ...customEmojis.value];
set('emojis', customEmojis.value);
@@ -34,10 +36,9 @@ stream.on('emojiDeleted', emojiData => {
export async function fetchCustomEmojis(force = false) {
const now = Date.now();
const needsMigration = miLocalStorage.getItem('emojis') != null;
let res;
if (force || needsMigration) {
if (force) {
res = await api('emojis', {});
} else {
const lastFetchedAt = await get('lastEmojisFetchedAt');
@@ -48,10 +49,6 @@ export async function fetchCustomEmojis(force = false) {
customEmojis.value = res.emojis;
set('emojis', res.emojis);
set('lastEmojisFetchedAt', now);
if (needsMigration) {
miLocalStorage.removeItem('emojis');
miLocalStorage.removeItem('lastEmojisFetchedAt');
}
}
let cachedTags;