Skip to content

Commit

Permalink
feat: add H5P download
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofmochi committed Jun 22, 2022
1 parent 89fdd3d commit 68f9135
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/components/main/DownloadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import { MUTATION_KEYS } from '@graasp/query-client';
import { DownloadButton as Button } from '@graasp/ui';
import PropTypes from 'prop-types';
import { useMutation } from '../../config/queryClient';
import { ITEM_TYPES } from '../../enums';

export const DownloadButton = ({ id, name }) => {
export const DownloadButton = ({ item }) => {
const { id, name, type } = item;
const { t } = useTranslation();

const mutationKey =
type === ITEM_TYPES.H5P
? MUTATION_KEYS.EXPORT_H5P
: MUTATION_KEYS.EXPORT_ZIP;

const {
mutate: downloadItem,
data,
isSuccess,
isLoading: isDownloading,
} = useMutation(MUTATION_KEYS.EXPORT_ZIP);
} = useMutation(mutationKey);

useEffect(() => {
if (isSuccess) {
Expand All @@ -40,8 +47,11 @@ export const DownloadButton = ({ id, name }) => {
};

DownloadButton.propTypes = {
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
item: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
}).isRequired,
};

export default DownloadButton;
2 changes: 1 addition & 1 deletion src/components/main/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Item = ({ item, memberships }) => {
{enableEdition && (
<>
<EditButton item={item} />
<DownloadButton id={id} name={name} />
<DownloadButton item={item} />
</>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/table/ActionsCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ActionsCellRenderer = ({ memberships, items, member }) => {
return (
<>
<EditButton item={item} />
<DownloadButton id={item?.id} name={item?.name} />
<DownloadButton item={item} />
</>
);
};
Expand Down
15 changes: 12 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1955,9 +1955,9 @@ __metadata:

"@graasp/query-client@github:graasp/graasp-query-client.git#163-h5p":
version: 0.1.0
resolution: "@graasp/query-client@https://github.com/graasp/graasp-query-client.git#commit=154537c836d995d9fda71551e91986e3bd3cdbcf"
resolution: "@graasp/query-client@https://github.com/graasp/graasp-query-client.git#commit=9af1e3968474c2e510c3c9435ea9f468125524af"
dependencies:
"@graasp/translations": "github:graasp/graasp-translations.git"
"@graasp/translations": "github:graasp/graasp-translations.git#15-h5p-translations"
axios: 0.27.2
crypto-js: 4.1.1
http-status-codes: 2.2.0
Expand All @@ -1968,7 +1968,7 @@ __metadata:
uuid: 8.3.2
peerDependencies:
react: ^17.0.0
checksum: d36122bbeb45254099fe218e93c3d4cac400f2e6c13ec1ed87a57c05c7e67d138298ad6f39041459194f76498a77c6660666b5c1b8d13d2a0fd7a4efee8194b4
checksum: 602f16d83cb44a32f8a389bdff5175b90a89ac244c3ba5b946974241ba84398a56bcd2c3971e06cf8132a198a3487696eed6259b21341ac54f0c54d8e877ef50
languageName: node
linkType: hard

Expand All @@ -1981,6 +1981,15 @@ __metadata:
languageName: node
linkType: hard

"@graasp/translations@github:graasp/graasp-translations.git#15-h5p-translations":
version: 0.1.0
resolution: "@graasp/translations@https://github.com/graasp/graasp-translations.git#commit=02c00050109c73d545d7117388d6aa309d0a9c34"
dependencies:
i18next: 21.6.11
checksum: 0bc1f3cd45f78fb8a5941a4d78f1b2bb1a4a24752d60c5e3df0ef5b8f2c52341d0059c0cb0928cab6de412d565bbc4aa72c8243c91a7c6b318f6e408172a2e26
languageName: node
linkType: hard

"@graasp/ui@github:graasp/graasp-ui":
version: 0.2.0
resolution: "@graasp/ui@https://github.com/graasp/graasp-ui.git#commit=40dec00985e34d057edc5630c5ac2889c09f0724"
Expand Down

0 comments on commit 68f9135

Please sign in to comment.