diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-05-30 17:27:04 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-05-30 17:27:04 +0200 |
| commit | 0890fdd951d021308550a0db2e7b6f2593512957 (patch) | |
| tree | a0050b153242ccde662fc0a957a79fc7a7edc4b4 /frontend/views/upload/components/upload.show.js | |
initial site copied in
Diffstat (limited to 'frontend/views/upload/components/upload.show.js')
| -rw-r--r-- | frontend/views/upload/components/upload.show.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/frontend/views/upload/components/upload.show.js b/frontend/views/upload/components/upload.show.js new file mode 100644 index 0000000..6b36269 --- /dev/null +++ b/frontend/views/upload/components/upload.show.js @@ -0,0 +1,70 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import actions from '../../../actions' +import { formatDate, formatTime, formatAge, uploadUri } from '../../../util' +import { history } from '../../../store' +import { Loader, MenuButton } from '../../../common' + +class UploadShow extends Component { + componentDidMount() { + actions.upload.show(this.props.match.params.id) + } + + componentDidUpdate(prevProps) { + if (prevProps.match.params.id !== this.props.match.params.id) { + actions.upload.show(this.props.match.params.id) + } + } + + handleDestroy() { + const { res: data } = this.props.upload.show + if (confirm("Really delete this upload?")) { + actions.upload.destroy(data).then(() => { + history.push('/upload/') + }) + } + } + + render() { + const { show, destroy } = this.props.upload + if (show.loading || destroy.loading) { + return <Loader /> + } + if (!show.loading && !show.res || show.not_found) { + return <div className='gray'>Upload {this.props.match.params.id} not found</div> + } + const { res: data } = show + return ( + <section className="row uploadShow"> + <div className="menuButtons"> + <MenuButton name="delete" onClick={this.handleDestroy.bind(this)} /> + <MenuButton name="search" href={'/search/upload/' + data.id + '/'} /> + </div> + <div> + <img src={uploadUri(data)} /> + <div className='byline'> + {'Uploaded by '} + {data.username} + {' on '} + {formatDate(data.created_at)} + {' at '} + {formatTime(data.created_at)} + {'. '} + </div> + </div> + </section> + ) + } +} + +const mapStateToProps = state => ({ + upload: state.upload, +}) + +const mapDispatchToProps = dispatch => ({ + // searchActions: bindActionCreators({ ...searchActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(UploadShow) |
