-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
180 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import '@uppy/core/dist/style.css'; | ||
import '@uppy/dashboard/dist/style.css'; | ||
import { routines } from '@graasp/query-client'; | ||
import { Dashboard } from '@uppy/react'; | ||
import { useRouteMatch } from 'react-router'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { FILE_UPLOAD_MAX_FILES } from '../../config/constants'; | ||
import { configureZipImportUppy } from '../../utils/uppy'; | ||
import { ZIP_DASHBOARD_UPLOADER_ID } from '../../config/selectors'; | ||
import { buildItemPath } from '../../config/paths'; | ||
import notifier from '../../middlewares/notifier'; | ||
|
||
const ImportZip = () => { | ||
const [uppy, setUppy] = useState(null); | ||
const match = useRouteMatch(buildItemPath()); | ||
const itemId = match?.params?.itemId; | ||
const { t } = useTranslation(); | ||
|
||
const onComplete = (result) => { | ||
// update app on complete | ||
// todo: improve with websockets or by receiving corresponding items | ||
if (!result?.failed.length) { | ||
notifier({ type: routines.importZipRoutine.SUCCESS }); | ||
} | ||
}; | ||
const onError = () => { | ||
notifier({ type: routines.importZipRoutine.FAILURE }); | ||
}; | ||
|
||
const onFilesAdded = () => { | ||
notifier({ type: routines.importZipRoutine.REQUEST }); | ||
}; | ||
|
||
const applyUppy = () => | ||
setUppy( | ||
configureZipImportUppy({ | ||
itemId, | ||
onComplete, | ||
onError, | ||
onFilesAdded, | ||
}), | ||
); | ||
|
||
useEffect(() => { | ||
applyUppy(); | ||
|
||
return () => { | ||
uppy?.close(); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
useEffect(() => { | ||
applyUppy(); | ||
// update uppy configuration each time itemId changes | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [itemId]); | ||
|
||
if (!uppy) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<Typography variant="h6">{t('Import a Graasp Archive')}</Typography> | ||
<Typography variant="caption"> | ||
{t( | ||
'You can download your resources from graasp.eu by right clicking and choosing "Download as ZIP".', | ||
)} | ||
</Typography> | ||
<div id={ZIP_DASHBOARD_UPLOADER_ID}> | ||
<Dashboard | ||
uppy={uppy} | ||
height={200} | ||
width="100%" | ||
proudlyDisplayPoweredByUppy={false} | ||
note={t( | ||
`You can upload up to FILE_UPLOAD_MAX_FILES files at a time`, | ||
{ | ||
maxFiles: FILE_UPLOAD_MAX_FILES, | ||
}, | ||
)} | ||
locale={{ | ||
strings: { | ||
// Text to show on the droppable area. | ||
// `%{browse}` is replaced with a link that opens the system file selection dialog. | ||
dropPaste: `${t('Drop here or')} %{browse}`, | ||
// Used as the label for the link that opens the system file selection dialog. | ||
browse: t('Browse'), | ||
}, | ||
}} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ImportZip; |
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
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