- Added hooks for listing, creating, updating, deleting, sharing, and merging people. - Introduced a new route for person details and media. - Implemented clustering faces functionality. - Created services for person-related API interactions. feat: Introduce tag management functionality - Added hooks for listing, adding, and removing tags from media. - Created services for tag-related API interactions. feat: Enhance user authentication handling - Added a hook to fetch current user details. - Updated auth storage to manage user state more effectively. feat: Update album management features - Enhanced album service to return created album details. - Updated API handlers to return album responses upon creation. - Modified album repository to return created album. feat: Implement media management improvements - Added media details fetching and processing of media URLs. - Enhanced media upload functionality to return processed media. feat: Introduce face management features - Added services for listing faces for media and assigning faces to persons. fix: Update API client to clear authentication state on 401 errors.
140 lines
3.6 KiB
TypeScript
140 lines
3.6 KiB
TypeScript
import {
|
|
useInfiniteQuery,
|
|
useMutation,
|
|
useQuery,
|
|
useQueryClient,
|
|
} from "@tanstack/react-query";
|
|
import {
|
|
createPerson,
|
|
deletePerson,
|
|
getPerson,
|
|
listMediaForPerson,
|
|
listPeople,
|
|
mergePerson,
|
|
setPersonThumbnail,
|
|
sharePerson,
|
|
unsharePerson,
|
|
updatePerson,
|
|
clusterFaces,
|
|
type CreatePersonPayload,
|
|
type MergePersonPayload,
|
|
type SetPersonThumbnailPayload,
|
|
type SharePersonPayload,
|
|
type UnsharePersonPayload,
|
|
type UpdatePersonPayload,
|
|
} from "@/services/person-service";
|
|
import { useNavigate } from "@tanstack/react-router";
|
|
|
|
const PERSON_KEY = ["people"];
|
|
|
|
export const useListPeople = () => {
|
|
return useQuery({
|
|
queryKey: [PERSON_KEY, "list"],
|
|
queryFn: listPeople,
|
|
});
|
|
};
|
|
|
|
export const useGetPerson = (personId: string) => {
|
|
return useQuery({
|
|
queryKey: [PERSON_KEY, "details", personId],
|
|
queryFn: () => getPerson(personId),
|
|
enabled: !!personId,
|
|
});
|
|
};
|
|
|
|
export const useListPersonMedia = (personId: string) => {
|
|
return useInfiniteQuery({
|
|
queryKey: [PERSON_KEY, "details", personId, "media"],
|
|
queryFn: ({ pageParam = 1 }) => listMediaForPerson({personId, page: pageParam, limit: 20} ),
|
|
getNextPageParam: (lastPage) => {
|
|
return lastPage.has_next_page ? lastPage.page + 1 : undefined;
|
|
},
|
|
initialPageParam: 1,
|
|
enabled: !!personId,
|
|
});
|
|
};
|
|
|
|
export const useCreatePerson = () => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: CreatePersonPayload) => createPerson(payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: [PERSON_KEY, "list"] });
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useUpdatePerson = (personId: string) => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: UpdatePersonPayload) =>
|
|
updatePerson(personId, payload),
|
|
onSuccess: (updatedPerson) => {
|
|
queryClient.invalidateQueries({ queryKey: [PERSON_KEY, "list"] });
|
|
queryClient.setQueryData(
|
|
[PERSON_KEY, "details", personId],
|
|
updatedPerson,
|
|
);
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useDeletePerson = (personId: string) => {
|
|
const queryClient = useQueryClient();
|
|
const navigate = useNavigate();
|
|
|
|
return useMutation({
|
|
mutationFn: () => deletePerson(personId),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: [PERSON_KEY, "list"] });
|
|
queryClient.removeQueries({
|
|
queryKey: [PERSON_KEY, "details", personId],
|
|
});
|
|
navigate({ to: "/people" });
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useSharePerson = (personId: string) => {
|
|
return useMutation({
|
|
mutationFn: (payload: SharePersonPayload) => sharePerson(personId, payload),
|
|
});
|
|
};
|
|
|
|
export const useUnsharePerson = (personId: string) => {
|
|
return useMutation({
|
|
mutationFn: (payload: UnsharePersonPayload) =>
|
|
unsharePerson(personId, payload),
|
|
});
|
|
};
|
|
|
|
export const useMergePerson = (targetPersonId: string) => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: MergePersonPayload) =>
|
|
mergePerson(targetPersonId, payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: [PERSON_KEY] });
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useSetPersonThumbnail = (personId: string) => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: SetPersonThumbnailPayload) =>
|
|
setPersonThumbnail(personId, payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: [PERSON_KEY, "details", personId],
|
|
});
|
|
queryClient.invalidateQueries({ queryKey: [PERSON_KEY, "list"] });
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useClusterFaces = () => {
|
|
return useMutation({
|
|
mutationFn: clusterFaces,
|
|
});
|
|
}; |