frontend/composables/NoteContext.ts
2024-06-11 15:02:30 -10:00

25 lines
633 B
TypeScript

import type { LysandClient } from "@lysand-org/client";
import type { Context } from "~/types/mastodon/context";
export const useNoteContext = (
client: MaybeRef<LysandClient | null>,
noteId: MaybeRef<string | null>,
) => {
if (!ref(client).value) {
return ref(null as Context | null);
}
const output = ref(null as Context | null);
watchEffect(() => {
if (toValue(noteId))
ref(client)
.value?.getStatusContext(toValue(noteId) ?? "")
.then((res) => {
output.value = res.data;
});
});
return output;
};