screaming

This commit is contained in:
sam 2023-12-20 17:13:48 +01:00
parent a06dd22da4
commit 91f3f71d8d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
9 changed files with 86 additions and 16 deletions

View file

@ -1,12 +0,0 @@
import { ref, computed } from "vue";
import { defineStore } from "pinia";
export const useCounterStore = defineStore("counter", () => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}
return { count, doubleCount, increment };
});

18
src/stores/instance.ts Normal file
View file

@ -0,0 +1,18 @@
import apiFetch from "@/lib/api-fetch";
import type Instance from "@/lib/api/entities/instance";
import { defineStore } from "pinia";
export const useInstanceStore = defineStore("instance", {
state: () => ({
instance: undefined as Instance | undefined,
}),
actions: {
async fetchInstance() {
const resp = await apiFetch<Instance>("/api/v1/instance");
this.instance = resp;
},
},
getters: {
instanceName: (state) => state.instance?.title || "Akkoma",
},
});

17
src/stores/title.ts Normal file
View file

@ -0,0 +1,17 @@
import { watch } from "vue";
import { useInstanceStore } from "./instance";
export default function watchTitle<T extends object | undefined>(
callback: (obj: T | undefined) => string | undefined,
obj: T | undefined = undefined,
) {
const instanceStore = useInstanceStore();
watch(
() => ({ obj, instanceName: instanceStore.instanceName }),
({ obj, instanceName }) => {
const text = callback(obj);
document.title = text ? `${text} - ${instanceName}` : instanceName;
},
{ immediate: true },
);
}