mirror of
https://github.com/nimbusdotstorage/Nimbus
synced 2026-04-22 17:45:03 +02:00
feat: merged pr #89.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { CreateFolderParams, DeleteFileParams, RenameFileParams } from "@/lib/types";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { CreateFolderParams, DeleteFileParams } from "@/lib/types";
|
||||
import { clientEnv } from "@/lib/env/client-env";
|
||||
import axios, { type AxiosError } from "axios";
|
||||
import { toast } from "sonner";
|
||||
@@ -54,7 +54,6 @@ export function useDeleteFile() {
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: async () => {
|
||||
toast.success("File deleted successfully");
|
||||
await queryClient.invalidateQueries({ queryKey: ["files"] });
|
||||
},
|
||||
onError: (error: AxiosError) => {
|
||||
@@ -65,6 +64,31 @@ export function useDeleteFile() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useRenameFile() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ fileId, name }: RenameFileParams) => {
|
||||
const response = await axios.put(API_BASE, null, {
|
||||
params: { fileId, name },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
withCredentials: true,
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["files"] });
|
||||
},
|
||||
onError: (error: AxiosError) => {
|
||||
console.error("Error renaming file:", error);
|
||||
const errorMessage = error.message || "Failed to rename file";
|
||||
toast.error(errorMessage);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateFile() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
Reference in New Issue
Block a user