Skip to content

Commit 41c5cbd

Browse files
committed
refresh files after upload
1 parent 409c82d commit 41c5cbd

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/components/file-download.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react"
1+
import React, { useState, useEffect, useCallback } from "react"
22
import { saveAs } from "file-saver"
33
import { DownloadCloud, Trash } from "lucide-react"
44
import { Button } from "./ui/button"
@@ -15,7 +15,7 @@ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
1515
const FileDownload = () => {
1616
const [checked, setChecked] = useState<File[]>([])
1717
const [selectAll, setSelectAll] = useState(false)
18-
const { downloadableFiles, setDownloadableFiles, fetchFiles } =
18+
const { downloadableFiles, fetchFiles } =
1919
useDownloadableFiles()
2020

2121
const downloadFiles = async () => {
@@ -49,7 +49,7 @@ const FileDownload = () => {
4949
).then((_) => setTimeout(() => {
5050
setSelectAll(false)
5151
setChecked([])
52-
getFiles()
52+
fetchFiles()
5353
}, 500))
5454
}
5555
}
@@ -66,11 +66,6 @@ const FileDownload = () => {
6666
setChecked(newChecked)
6767
}
6868

69-
const getFiles = async () => {
70-
const files = await fetchFiles()
71-
setDownloadableFiles(files)
72-
}
73-
7469
useEffect(() => {
7570
setChecked([])
7671
if (selectAll) {
@@ -84,6 +79,10 @@ const FileDownload = () => {
8479
// eslint-disable-next-line
8580
}, [selectAll])
8681

82+
useCallback(() => {
83+
fetchFiles()
84+
}, [downloadableFiles])
85+
8786
return (
8887
<Card>
8988
<CardHeader>

src/components/file-upload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ const FileUpload = () => {
2121
fetch(`/api/files${query}`, {
2222
method: "POST",
2323
body: data,
24-
}).then(() => fetchFiles())
24+
})
2525
})
2626
toast({
2727
description: "Files uploaded successfully!",
2828
variant: "success",
2929
})
3030
setPath(null)
3131
setFiles([])
32+
fetchFiles()
3233
}
3334

3435
return (

src/hooks/useDownloadableFiles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const DownloadableFilesProvider = ({ children }: any) => {
1818
const files = await fetch("/api/files")
1919
.then((response) => response.json())
2020
.then((data) => data);
21-
return files
21+
setDownloadableFiles(files)
2222
}
2323

2424
useEffect(() => {
25-
fetchFiles().then((files) => setDownloadableFiles(files))
25+
fetchFiles()
2626
}, [])
2727

2828
return (

0 commit comments

Comments
 (0)