Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled multi download in history and share page #193

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions ui/src/app/(pages)/(protected)/history/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function HistoryPage() {
const [newTitleUploadID, setNewTitleUploadID] = useState('')
const [editing, setEditing] = useState(false)
const [data, setData] = React.useState<History[]>([])
const [downloading, setDownloading] = useState(false)
const [openEditDialog, setOpenEditDialog] = useState(false)
const [openDeleteConfirmation, setOpenDeleteConfirmation] = useState(false)
const [deleteUploadID, setDeleteUploadID] = useState('')
Expand Down Expand Up @@ -157,8 +156,6 @@ function HistoryPage() {
}, [statusLoaded])

const handleDownload = async (uploadId: string) => {
if (!downloading) {
setDownloading(true)
const downloadInprogressToastID = toast.loading('Download in progress...', { duration: 9999999 })
const apiBaseURL = process.env.NEXT_PUBLIC_API_BASE_URL
const apiKey = process.env.NEXT_PUBLIC_API_KEY
Expand All @@ -174,7 +171,7 @@ function HistoryPage() {
},
)
if (!downloadResponse.ok) {
setDownloading(false)

toast.dismiss(downloadInprogressToastID)
toast.error('Upload ID is not valid')
return
Expand Down Expand Up @@ -207,15 +204,14 @@ function HistoryPage() {

const zipBlob = await zip.generateAsync({ type: 'blob' })
const zipFileName = 'ByteShare_Preview_' + uploadId + '.zip'

saveAs(zipBlob, zipFileName)
toast.dismiss(downloadInprogressToastID)
} catch (err) {
toast.dismiss(downloadInprogressToastID)
toast.error('Error downloading zip file.')
} finally {
setDownloading(false)
}
}

}

const handleCopyShareLink = async(uploadId: string) => {
Expand Down Expand Up @@ -411,7 +407,6 @@ function HistoryPage() {
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(row.original.id)}
disabled={downloading}
>
Download
</DropdownMenuItem>
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/(pages)/auth/login/components/auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
Email
</Label>
<Input
className="text-lightgray-foreground"
id="email"
placeholder="Email address"
type="email"
Expand All @@ -87,7 +86,6 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
Password
</Label>
<Input
className="text-lightgray-foreground"
id="password"
placeholder="Password"
type="password"
Expand Down
3 changes: 0 additions & 3 deletions ui/src/app/(pages)/auth/signup/components/auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
Name
</Label>
<Input
className="text-lightgray-foreground"
id="name"
placeholder="Your Name"
type="text"
Expand All @@ -98,7 +97,6 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
Email
</Label>
<Input
className="text-lightgray-foreground"
id="email"
placeholder="Email Address"
type="email"
Expand All @@ -116,7 +114,6 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
Email
</Label>
<Input
className="text-lightgray-foreground"
id="password"
placeholder="Password"
type="password"
Expand Down
11 changes: 4 additions & 7 deletions ui/src/app/(pages)/share/[uploadId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function SharePage({ params }: Params) {
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
const [progress, setProgress] = useState(0)
const [downloadingAll, setDownloadingAll] = useState(false)
const [downloadingOne, setDownloadingOne] = useState(false)
const [data, setData] = React.useState<File[]>([])
const [source, setSource] = useState(null)
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
Expand Down Expand Up @@ -129,18 +128,17 @@ function SharePage({ params }: Params) {
downloadLink: string,
fileName: string,
) => {
const downloadInprogressToastID = toast.loading('Download in progress...', {
duration: 9999999,
})
try {
setDownloadingOne(true)
toast.loading('Download in progress...', { duration: 9999999 })
const response = await fetch(downloadLink)
const blob = await response.blob()
saveAs(blob, fileName)
toast.dismiss()
} catch (err) {
toast.dismiss()
toast.error('Error in downloading file')
} finally {
setDownloadingOne(false)
toast.dismiss(downloadInprogressToastID)
}
}

Expand Down Expand Up @@ -178,7 +176,6 @@ function SharePage({ params }: Params) {
<Button
variant="ghost"
className="h-8 w-8 p-0"
disabled={downloadingOne}
onClick={() => {
handleSingleDownload(row.original.downloadLink, row.original.name)
}}
Expand Down
Loading