Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useContext, useState, useEffect } from 'react';
import axios from 'axios';
import GetAppIcon from '@material-ui/icons/GetApp';
import Button from '@material-ui/core/Button';
import styled from 'styled-components';
import { apiUrl, apiDomain } from '../env';
import FollowCollectionButton from './FollowCollectionButton.js';
import { Store } from '../Store.js'
import { Grid } from '@material-ui/core';
const DowloadButton = (props) => {
const { state } = useContext(Store);
const [download_url, setDownloadUrl] = useState('');
useEffect(() => {
const body = {
"package": {
"object": [{ "type": "Collection", "id": props.id }]
}
};
axios
.post(apiUrl + '/package', body)
.catch(err => {
if (err.response && err.response.status === 302) {
setDownloadUrl(apiDomain + '/' + err.response.data.url);
}
});
}, [props.id]);
return (
<>
<DownloadAnchor href={download_url} >
<DownloadButton
variant="outlined"
color="primary"
startIcon={<GetAppIcon fontSize="large" />}
size="small"
>
<ButtonText>Baixar Coleção</ButtonText>
</DownloadButton>
</DownloadAnchor>
</>
)
}
const ButtonText = styled.span`
font-weight: bolder;
font-size: 1.2em;
`
const DownloadButton = styled(Button)`
padding-left: 10;
padding-right: 10;
width: 250px;
`
const DownloadAnchor = styled.a`
text-decoration: none !important;
`
export default DowloadButton;