refactor(login/identites): identities improvements

- only one GraphQL call to Identities
- LoginView is no more responsible for identities : App.vue is now reactively monitoring identities changes to initializeCurrentActor
- Remove useLazyCurrentUserIdentities we now use useCurrentUserIdentities everywhere
- Change identities to be possibly undefined instead of null to remove a useless trigger to watch in App.vue

Related to #1806
This commit is contained in:
Massedil
2025-06-29 14:47:47 +02:00
parent 6020ad26af
commit 26186e96fc
3 changed files with 26 additions and 92 deletions

View File

@@ -6,7 +6,7 @@ import {
} from "@/graphql/actor";
import { IPerson } from "@/types/actor";
import { ICurrentUser } from "@/types/current-user.model";
import { useLazyQuery, useQuery } from "@vue/apollo-composable";
import { useQuery } from "@vue/apollo-composable";
import { computed, Ref, unref } from "vue";
import { useCurrentUserClient } from "./user";
@@ -22,26 +22,6 @@ export function useCurrentActorClient() {
return { currentActor, error, loading };
}
export function useLazyCurrentUserIdentities() {
const { currentUser } = useCurrentUserClient();
return useLazyQuery<{
loggedUser: Pick<ICurrentUser, "actors">;
}>(
IDENTITIES,
{
// To ensure the request is re-executed when the user changes,
// we include a dummy `_user` parameter that's ignored by the server.
// This function does not depend on the user, the server identifies them by the token.
// So without this dummy parameter, the GraphQL call is not automatically reloaded
// when the actor changes.
_user: currentUser?.value?.id,
},
{
fetchPolicy: "network-only",
}
);
}
export function useCurrentUserIdentities() {
const { currentUser } = useCurrentUserClient();
@@ -71,7 +51,7 @@ export function useCurrentUserIdentities() {
);
const identities = computed(() =>
enabled.value ? result.value?.loggedUser?.actors : null
enabled.value ? result.value?.loggedUser?.actors : undefined
);
return { identities, error, loading };