52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import React from "react";
|
|
import { SpinnerCircular } from 'spinners-react';
|
|
|
|
import { getFile } from "../../../actions";
|
|
import LogFileDownload from "../../../components/LogFileDownload";
|
|
|
|
export default class DownloadFileById extends LogFileDownload
|
|
{
|
|
constructor(props)
|
|
{
|
|
super(props);
|
|
this.state = {
|
|
downloading: false,
|
|
};
|
|
}
|
|
|
|
_handle_onDownloadFile = () =>
|
|
{
|
|
const { id, filename } = this.props;
|
|
const { downloading } = this.state;
|
|
|
|
if(!downloading)
|
|
{
|
|
this.setState({ downloading: true }, () =>
|
|
{
|
|
getFile({ id, filename })
|
|
.then(() =>
|
|
{
|
|
if(this._log !== undefined) { this._log(); }
|
|
this.setState({ downloading: false });
|
|
})
|
|
.catch(() => { this.setState({ downloading: false }); });
|
|
});
|
|
}
|
|
}
|
|
|
|
render()
|
|
{
|
|
const { id, filename, url, bitrix, title } = this.props;
|
|
const { downloading } = this.state;
|
|
|
|
return (
|
|
<span style={{ position: "relative" }} onClick={ this._handle_onDownloadFile }>
|
|
{ downloading ? (
|
|
<SpinnerCircular style={{ position: "absolute", top: "0px", left: "10px", }} size={ 18 } thickness={ 100 } speed={ 100 } color="rgba(255, 255, 255, 1)" secondaryColor="rgba(28, 1, 169, 1)" />
|
|
) : (
|
|
this.props.children
|
|
) }
|
|
</span>
|
|
)
|
|
}
|
|
} |