Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { entrySeenApi } from '@/api/entry-seen';
|
||||
import { entryKeys } from './useEntries';
|
||||
|
||||
export const entrySeenKeys = {
|
||||
all: ['entry-seen'] as const,
|
||||
byEntry: (entryId: number) => ['entry-seen', 'by-entry', entryId] as const,
|
||||
};
|
||||
|
||||
export function useEntrySeenByEntry(entryId: number) {
|
||||
return useQuery({
|
||||
queryKey: entrySeenKeys.byEntry(entryId),
|
||||
queryFn: () => entrySeenApi.getByEntry(entryId),
|
||||
enabled: !!entryId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateEntrySeen() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: {
|
||||
entry_id: number;
|
||||
date_seen: string;
|
||||
seen_with?: string;
|
||||
}) => entrySeenApi.create(data),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entrySeenKeys.byEntry(variables.entry_id),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entryKeys.detail(variables.entry_id),
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: entryKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateEntrySeen() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
data,
|
||||
}: {
|
||||
id: number;
|
||||
data: { entry_id: number; date_seen?: string; seen_with?: string };
|
||||
}) => entrySeenApi.update(id, data),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entrySeenKeys.byEntry(variables.data.entry_id),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteEntrySeen() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, entryId }: { id: number; entryId: number }) =>
|
||||
entrySeenApi.delete(id),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entrySeenKeys.byEntry(variables.entryId),
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: entryKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user