-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add download feature for all or individual projects (#111)
- Loading branch information
1 parent
6827ff3
commit c05e978
Showing
8 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/components/project/DownloadProject/DownloadProject.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.download { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 1.2rem !important; | ||
} |
53 changes: 53 additions & 0 deletions
53
src/components/project/DownloadProject/DownloadProject.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import AppIcon from '@/components/ui/icon'; | ||
import { useLogActivity } from '@/hooks/logActivity.hooks'; | ||
import fileSystem from '@/lib/fs'; | ||
import ZIP from '@/lib/zip'; | ||
import { Button, Tooltip } from 'antd'; | ||
import { FC, useState } from 'react'; | ||
import s from './DownloadProject.module.scss'; | ||
|
||
interface Props { | ||
path: string; | ||
title: string; | ||
} | ||
|
||
const DownloadProject: FC<Props> = ({ path, title }) => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const { createLog } = useLogActivity(); | ||
const download = () => { | ||
try { | ||
let fileName = path.split('/').pop(); | ||
if (path === '/') { | ||
fileName = 'archive'; | ||
} | ||
const zip = new ZIP(fileSystem); | ||
zip.bundleFilesAndDownload([path], `${fileName}.zip`); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
createLog(error.message, 'error'); | ||
} else { | ||
createLog('Failed to download project', 'error'); | ||
} | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip title={title}> | ||
<Button | ||
type="text" | ||
title={title} | ||
onClick={() => { | ||
download(); | ||
}} | ||
disabled={isLoading} | ||
icon={<AppIcon name="Download" />} | ||
size="small" | ||
className={s.download} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default DownloadProject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './DownloadProject'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as DownloadProject } from './DownloadProject'; | ||
export { default as MigrateToUnifiedFS } from './MigrateToUnifiedFS'; | ||
export { default as NewProject } from './NewProject'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters