mirror of
https://github.com/versia-pub/frontend.git
synced 2026-06-14 07:29:15 +02:00
chore: ⬆️ Upgrade to Nuxt 4
Some checks failed
Some checks failed
This commit is contained in:
parent
8debe97f63
commit
7f7cf20311
386 changed files with 2376 additions and 2332 deletions
49
app/composables/Relationship.ts
Normal file
49
app/composables/Relationship.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import type { Client } from "@versia/client";
|
||||
import type { Relationship } from "@versia/client/schemas";
|
||||
import type { z } from "zod";
|
||||
|
||||
export const useRelationship = (
|
||||
client: MaybeRef<Client | null>,
|
||||
accountId: MaybeRef<string | null>,
|
||||
) => {
|
||||
const relationship = ref(null as z.infer<typeof Relationship> | null);
|
||||
const isLoading = ref(false);
|
||||
|
||||
if (!identity.value) {
|
||||
return { relationship, isLoading };
|
||||
}
|
||||
|
||||
watchEffect(() => {
|
||||
if (toValue(accountId)) {
|
||||
toValue(client)
|
||||
?.getRelationship(toValue(accountId) ?? "")
|
||||
.then((res) => {
|
||||
relationship.value = res.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
watch(relationship, (newOutput, oldOutput) => {
|
||||
if (newOutput !== oldOutput && newOutput && oldOutput) {
|
||||
if (newOutput?.following !== oldOutput?.following) {
|
||||
isLoading.value = true;
|
||||
if (newOutput?.following) {
|
||||
toValue(client)
|
||||
?.followAccount(toValue(accountId) ?? "")
|
||||
.finally(() => {
|
||||
isLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
toValue(client)
|
||||
?.unfollowAccount(toValue(accountId) ?? "")
|
||||
.finally(() => {
|
||||
isLoading.value = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
// FIXME: Add more relationship changes
|
||||
}
|
||||
});
|
||||
|
||||
return { relationship, isLoading };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue