- 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.
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
assignFaceToPerson,
|
|
listFacesForMedia,
|
|
type AssignFacePayload,
|
|
} from "@/services/face-service";
|
|
import type { FaceRegion } from "@/domain/types";
|
|
|
|
const FACE_KEY = ["faces"];
|
|
const PERSON_KEY = ["people"];
|
|
|
|
/**
|
|
* Query hook to fetch all faces for a specific media item.
|
|
*/
|
|
export const useListMediaFaces = (mediaId: string) => {
|
|
return useQuery({
|
|
queryKey: [FACE_KEY, "list", mediaId],
|
|
queryFn: () => listFacesForMedia(mediaId),
|
|
enabled: !!mediaId,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Mutation hook to assign a face to a person.
|
|
*/
|
|
export const useAssignFace = (faceId: string, mediaId: string) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (payload: AssignFacePayload) =>
|
|
assignFaceToPerson(faceId, payload),
|
|
onSuccess: (updatedFace) => {
|
|
// Update the list of faces for this media
|
|
queryClient.setQueryData(
|
|
[FACE_KEY, "list", mediaId],
|
|
(oldData: FaceRegion[] | undefined) => {
|
|
return oldData?.map((face) =>
|
|
face.id === faceId ? updatedFace : face,
|
|
);
|
|
},
|
|
);
|
|
// Invalidate the media list for the person
|
|
if (updatedFace.person_id) {
|
|
queryClient.invalidateQueries({
|
|
queryKey: [PERSON_KEY, "details", updatedFace.person_id, "media"],
|
|
});
|
|
}
|
|
},
|
|
});
|
|
}; |