Add function to download all files as a zip

This commit is contained in:
Elias Schneider
2022-04-30 23:30:23 +02:00
parent 7ddce593f9
commit b070f17d67
7 changed files with 265 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
import { Group } from "@mantine/core";
import { useModals } from "@mantine/modals";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import Meta from "../../components/Meta";
import DownloadAllButton from "../../components/share/DownloadAllButton";
import FileList from "../../components/share/FileList";
import showEnterPasswordModal from "../../components/share/showEnterPasswordModal";
import showShareNotFoundModal from "../../components/share/showShareNotFoundModal";
@@ -13,7 +15,7 @@ const Share = () => {
const router = useRouter();
const modals = useModals();
const shareId = router.query.shareId as string;
const [shareList, setShareList] = useState<AppwriteFileWithPreview[]>([]);
const [fileList, setFileList] = useState<AppwriteFileWithPreview[]>([]);
const submitPassword = async (password: string) => {
await shareService.authenticateWithPassword(shareId, password).then(() => {
@@ -25,7 +27,9 @@ const Share = () => {
const getFiles = (password?: string) =>
shareService
.get(shareId, password)
.then((files) => setShareList(files))
.then((files) => {
setFileList(files);
})
.catch((e) => {
const error = e.response.data.message;
if (e.response.status == 404) {
@@ -44,10 +48,17 @@ const Share = () => {
return (
<>
<Meta title={`Share ${shareId}`} />
<Group position="right">
<DownloadAllButton
shareId={shareId}
files={fileList}
setFiles={setFileList}
/>
</Group>
<FileList
files={shareList}
files={fileList}
shareId={shareId}
isLoading={shareList.length == 0}
isLoading={fileList.length == 0}
/>
</>
);