mirror of
https://github.com/nimbusdotstorage/Nimbus
synced 2026-04-22 17:45:03 +02:00
refactor(API): removed generate Google Drive client, reorganized provders, added typing, ran knip and removed unused types, import and files. Made the getFiles hook and implemented it in the file browser. Renamed env validation files for domain specific naming
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { DeleteFileParams } from "@/lib/types";
|
||||
import { clientEnv } from "@/lib/env/client-env";
|
||||
import axios, { type AxiosError } from "axios";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function useFileOperations() {
|
||||
export function useFileOperations(parentId: string, nextPageToken?: string) {
|
||||
const queryClient = useQueryClient();
|
||||
const filesQuery = useQuery({
|
||||
queryKey: ["files", parentId, nextPageToken],
|
||||
queryFn: async () => {
|
||||
const response = await axios.get(`${clientEnv.NEXT_PUBLIC_BACKEND_URL}/api/files`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
retry: 2,
|
||||
});
|
||||
|
||||
const deleteFileMutation = useMutation({
|
||||
mutationFn: async ({ id }: DeleteFileParams) => {
|
||||
const response = await axios.delete(`${clientEnv.NEXT_PUBLIC_BACKEND_URL}/api/files`, {
|
||||
@@ -17,8 +33,10 @@ export function useFileOperations() {
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: async () => {
|
||||
toast.success("File deleted successfully");
|
||||
// Invalidate files queries to refetch the data
|
||||
await queryClient.invalidateQueries({ queryKey: ["files"] });
|
||||
},
|
||||
onError: (error: AxiosError) => {
|
||||
console.error("Error deleting file:", error);
|
||||
@@ -32,6 +50,7 @@ export function useFileOperations() {
|
||||
};
|
||||
|
||||
return {
|
||||
filesQuery,
|
||||
handleDeleteFile,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user