2025-05-26 11:19:15 +02:00
|
|
|
import type { Status } from "@versia/client/schemas";
|
|
|
|
|
import type { z } from "zod";
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2025-08-28 07:41:51 +02:00
|
|
|
export const useNote = (noteId: MaybeRef<string | null>) => {
|
|
|
|
|
if (!toValue(noteId)) {
|
2025-05-26 11:19:15 +02:00
|
|
|
return ref(null as z.infer<typeof Status> | null);
|
2024-04-22 09:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-28 07:41:51 +02:00
|
|
|
const authStore = useAuthStore();
|
|
|
|
|
|
2025-05-26 11:19:15 +02:00
|
|
|
const output = ref(null as z.infer<typeof Status> | null);
|
2024-04-27 03:28:12 +02:00
|
|
|
|
2024-11-04 23:55:02 +01:00
|
|
|
watchEffect(() => {
|
|
|
|
|
toValue(noteId) &&
|
2025-08-28 07:41:51 +02:00
|
|
|
authStore.client
|
|
|
|
|
.getStatus(toValue(noteId) as string)
|
2024-11-04 23:55:02 +01:00
|
|
|
.then((res) => {
|
|
|
|
|
output.value = res.data;
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-04-27 03:28:12 +02:00
|
|
|
|
|
|
|
|
return output;
|
2024-04-22 09:38:51 +02:00
|
|
|
};
|