удаление неиспользуемого
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import {
|
||||
createSheet,
|
||||
getSheet,
|
||||
getSheets,
|
||||
getSheetsByTemplate,
|
||||
patchSheet,
|
||||
type ApiSheet,
|
||||
@@ -18,16 +16,6 @@ export const sheetKeys = {
|
||||
detail: (sheetId: string) => [...sheetKeys.all, 'detail', sheetId] as const,
|
||||
}
|
||||
|
||||
// Хук для получения всех листов
|
||||
export function useSheets() {
|
||||
return useQuery({
|
||||
queryKey: sheetKeys.all,
|
||||
queryFn: getSheets,
|
||||
staleTime: 2 * 60 * 1000, // 2 минуты
|
||||
gcTime: 10 * 60 * 1000, // 10 минут кеш
|
||||
})
|
||||
}
|
||||
|
||||
// Хук для получения листов по template_id с кешированием
|
||||
export function useSheetsByTemplate(templateId: string | undefined) {
|
||||
return useQuery({
|
||||
@@ -40,17 +28,6 @@ export function useSheetsByTemplate(templateId: string | undefined) {
|
||||
})
|
||||
}
|
||||
|
||||
// Хук для получения конкретного листа
|
||||
export function useSheet(sheetId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: sheetKeys.detail(sheetId || ''),
|
||||
queryFn: () => getSheet(sheetId!),
|
||||
enabled: !!sheetId,
|
||||
staleTime: 5 * 60 * 1000, // 5 минут
|
||||
gcTime: 10 * 60 * 1000, // 10 минут кеш
|
||||
})
|
||||
}
|
||||
|
||||
// Хук для создания листа
|
||||
export function useCreateSheet() {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -149,48 +126,3 @@ export function usePatchSheet() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Хук для массового обновления листов (для автосохранения)
|
||||
export function useBatchUpdateSheets() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (
|
||||
updates: Array<{
|
||||
sheetId: string
|
||||
data: PatchSheetInput
|
||||
templateId: string
|
||||
}>
|
||||
) => {
|
||||
// Выполняем все обновления параллельно
|
||||
const results = await Promise.allSettled(
|
||||
updates.map(({ sheetId, data }) => patchSheet(sheetId, data))
|
||||
)
|
||||
|
||||
return results
|
||||
},
|
||||
onSuccess: (results, variables) => {
|
||||
// Обновляем кеши для всех затронутых шаблонов
|
||||
const templateIds = new Set(variables.map(v => v.templateId))
|
||||
|
||||
templateIds.forEach(templateId => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: sheetKeys.byTemplate(templateId),
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Хук для предзагрузки листов шаблона
|
||||
export function usePrefetchSheetsByTemplate() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return (templateId: string) => {
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: sheetKeys.byTemplate(templateId),
|
||||
queryFn: () => getSheetsByTemplate(templateId),
|
||||
staleTime: 1 * 60 * 1000,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user