magnetar/fe_calckey/frontend/client/src/instance.ts

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-07-07 19:22:30 +00:00
import { computed, reactive } from "vue";
import { api } from "./os";
import type * as Misskey from "calckey-js";
// TODO: 他のタブと永続化されたstateを同期
const instanceData = localStorage.getItem("instance");
// TODO: instanceをリアクティブにするかは再考の余地あり
export const instance: Misskey.entities.DetailedInstanceMetadata = reactive(
instanceData
? JSON.parse(instanceData)
: {
// TODO: set default values
2024-04-08 01:10:23 +00:00
},
2023-07-07 19:22:30 +00:00
);
export async function fetchInstance() {
const meta = await api("meta", {
detail: true,
});
2023-07-07 19:22:30 +00:00
for (const [k, v] of Object.entries(meta)) {
instance[k] = v;
}
2023-07-07 19:22:30 +00:00
localStorage.setItem("instance", JSON.stringify(instance));
2023-07-07 19:22:30 +00:00
}
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);
2023-07-07 19:22:30 +00:00
});
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);
2023-07-07 19:22:30 +00:00
});
// このファイルに書きたくないけどここに書かないと何故かVeturが認識しない
declare module "@vue/runtime-core" {
interface ComponentCustomProperties {
$instance: typeof instance;
}
2023-07-07 19:22:30 +00:00
}