diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /packages/client/src/instance.ts | |
| parent | update deps (diff) | |
| download | sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'packages/client/src/instance.ts')
| -rw-r--r-- | packages/client/src/instance.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/client/src/instance.ts b/packages/client/src/instance.ts new file mode 100644 index 0000000000..6e912aa2e5 --- /dev/null +++ b/packages/client/src/instance.ts @@ -0,0 +1,52 @@ +import { computed, reactive } from 'vue'; +import * as Misskey from 'misskey-js'; +import { api } from './os'; + +// TODO: 他のタブと永続化されたstateを同期 + +const data = localStorage.getItem('instance'); + +// TODO: instanceをリアクティブにするかは再考の余地あり + +export const instance: Misskey.entities.InstanceMetadata = reactive(data ? JSON.parse(data) : { + // TODO: set default values +}); + +export async function fetchInstance() { + const meta = await api('meta', { + detail: false + }); + + for (const [k, v] of Object.entries(meta)) { + instance[k] = v; + } + + localStorage.setItem('instance', JSON.stringify(instance)); +} + +export const emojiCategories = computed(() => { + if (instance.emojis == null) return []; + const categories = new Set(); + for (const emoji of instance.emojis) { + categories.add(emoji.category); + } + return Array.from(categories); +}); + +export const emojiTags = computed(() => { + if (instance.emojis == null) return []; + const tags = new Set(); + for (const emoji of instance.emojis) { + for (const tag of emoji.aliases) { + tags.add(tag); + } + } + return Array.from(tags); +}); + +// このファイルに書きたくないけどここに書かないと何故かVeturが認識しない +declare module '@vue/runtime-core' { + interface ComponentCustomProperties { + $instance: typeof instance; + } +} |