frontend/composables/NoteContext.ts
2025-05-26 11:19:15 +02:00

27 lines
689 B
TypeScript

import type { Client } from "@versia/client";
import type { Context } from "@versia/client/schemas";
import type { z } from "zod";
export const useNoteContext = (
client: MaybeRef<Client | null>,
noteId: MaybeRef<string | null>,
) => {
if (!ref(client).value) {
return ref(null as z.infer<typeof Context> | null);
}
const output = ref(null as z.infer<typeof Context> | null);
watchEffect(() => {
if (toValue(noteId)) {
ref(client)
.value?.getStatusContext(toValue(noteId) ?? "")
.then((res) => {
output.value = res.data;
});
}
});
return output;
};