2024-08-28 00:23:29 +02:00
|
|
|
import type { Client } from "@versia/client";
|
2025-05-26 11:19:15 +02:00
|
|
|
import type { Instance, TermsOfService } from "@versia/client/schemas";
|
|
|
|
|
import type { z } from "zod";
|
2024-04-27 03:28:12 +02:00
|
|
|
|
2024-05-17 08:25:59 +02:00
|
|
|
export const useInstance = () => {
|
2024-06-15 23:18:58 +02:00
|
|
|
return computed(() => identity.value?.instance);
|
2024-04-22 09:38:51 +02:00
|
|
|
};
|
2024-06-16 08:34:35 +02:00
|
|
|
|
2024-08-28 00:23:29 +02:00
|
|
|
export const useInstanceFromClient = (client: MaybeRef<Client>) => {
|
2024-06-16 08:34:35 +02:00
|
|
|
if (!client) {
|
2025-05-26 11:19:15 +02:00
|
|
|
return ref(null as z.infer<typeof Instance> | null);
|
2024-06-16 08:34:35 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-26 11:19:15 +02:00
|
|
|
const output = ref(null as z.infer<typeof Instance> | null);
|
2024-06-16 08:34:35 +02:00
|
|
|
|
|
|
|
|
watchEffect(() => {
|
|
|
|
|
toValue(client)
|
|
|
|
|
?.getInstance()
|
|
|
|
|
.then((res) => {
|
|
|
|
|
output.value = res.data;
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-06-20 04:54:55 +02:00
|
|
|
|
|
|
|
|
return output;
|
2024-06-16 08:34:35 +02:00
|
|
|
};
|
|
|
|
|
|
2024-08-28 00:23:29 +02:00
|
|
|
export const useTos = (client: MaybeRef<Client>) => {
|
2024-06-16 08:34:35 +02:00
|
|
|
if (!client) {
|
2025-05-26 11:19:15 +02:00
|
|
|
return ref(null as z.infer<typeof TermsOfService> | null);
|
2024-06-16 08:34:35 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-26 11:19:15 +02:00
|
|
|
const output = ref(null as z.infer<typeof TermsOfService> | null);
|
2024-06-16 08:34:35 +02:00
|
|
|
|
|
|
|
|
watchEffect(() => {
|
|
|
|
|
toValue(client)
|
|
|
|
|
?.getInstanceTermsOfService()
|
|
|
|
|
.then((res) => {
|
|
|
|
|
output.value = res.data;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
};
|