Skip to content

Commit 8e5d11b

Browse files
committed
fit delete video dialog not updating total storage used
1 parent 738fedc commit 8e5d11b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/components/dialogs/delete-video-dialog.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
import { toast } from "sonner";
1010
import { usageDataQueryOptions, videosQueryOptions } from "@/lib/query-utils";
1111
import { notNanOrDefault } from "@/lib/utils";
12-
import { queryClient } from "@/routes/__root";
1312
import { deleteVideoServerFn } from "@/server-fns/videos";
1413
import { useDialogsStore } from "@/lib/stores/dialogs";
14+
import { useQueryClient } from "@tanstack/react-query";
1515

1616
export function DeleteVideoDialog() {
17+
const queryClient = useQueryClient();
18+
1719
const closeDeleteVideoDialog = useDialogsStore(
1820
(state) => state.closeDeleteVideoDialog
1921
);
@@ -54,21 +56,30 @@ export function DeleteVideoDialog() {
5456
const video = videos.find((v) => v.id === deleteVideoDialogData.videoId);
5557

5658
queryClient.setQueryData(usageDataQueryOptions.queryKey, (old) => {
57-
console.log(old);
59+
if (!old) {
60+
return;
61+
}
62+
5863
return {
64+
...old,
5965
totalStorageUsed: Math.max(
60-
old?.totalStorageUsed ?? 0 - notNanOrDefault(video?.fileSizeBytes),
66+
(old?.totalStorageUsed ?? 0) -
67+
notNanOrDefault(video?.fileSizeBytes),
6168
0
6269
),
63-
maxStorage: old?.maxStorage ?? 0,
64-
maxFileUpload: old?.maxFileUpload ?? undefined,
6570
};
6671
});
6772

6873
queryClient.setQueryData(videosQueryOptions.queryKey, (old) => {
74+
if (!old) {
75+
return;
76+
}
77+
6978
return {
7079
...old,
71-
videos: videos.filter((v) => v.id !== deleteVideoDialogData.videoId),
80+
videos: old.videos.filter(
81+
(v) => v.id !== deleteVideoDialogData.videoId
82+
),
7283
};
7384
});
7485

0 commit comments

Comments
 (0)