mirror of
https://github.com/versia-pub/frontend.git
synced 2026-06-14 07:29:15 +02:00
refactor: ♻️ Rewrite state system to use Pinia for composer and auth
This commit is contained in:
parent
a6db9e059d
commit
b510782a30
80 changed files with 999 additions and 1011 deletions
|
|
@ -1,22 +1,19 @@
|
|||
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>,
|
||||
) => {
|
||||
export const useRelationship = (accountId: MaybeRef<string | null>) => {
|
||||
const relationship = ref(null as z.infer<typeof Relationship> | null);
|
||||
const isLoading = ref(false);
|
||||
const authStore = useAuthStore();
|
||||
|
||||
if (!identity.value) {
|
||||
if (!authStore.isSignedIn) {
|
||||
return { relationship, isLoading };
|
||||
}
|
||||
|
||||
watchEffect(() => {
|
||||
if (toValue(accountId)) {
|
||||
toValue(client)
|
||||
?.getRelationship(toValue(accountId) ?? "")
|
||||
authStore.client
|
||||
.getRelationship(toValue(accountId) ?? "")
|
||||
.then((res) => {
|
||||
relationship.value = res.data;
|
||||
});
|
||||
|
|
@ -28,14 +25,14 @@ export const useRelationship = (
|
|||
if (newOutput?.following !== oldOutput?.following) {
|
||||
isLoading.value = true;
|
||||
if (newOutput?.following) {
|
||||
toValue(client)
|
||||
?.followAccount(toValue(accountId) ?? "")
|
||||
authStore.client
|
||||
.followAccount(toValue(accountId) ?? "")
|
||||
.finally(() => {
|
||||
isLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
toValue(client)
|
||||
?.unfollowAccount(toValue(accountId) ?? "")
|
||||
authStore.client
|
||||
.unfollowAccount(toValue(accountId) ?? "")
|
||||
.finally(() => {
|
||||
isLoading.value = false;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue