blob: 20a6a0cabf7c1f8dd2073dd6c732433565913259 (
plain)
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
59
60
61
62
63
64
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import actions from 'app/actions'
import { formatDate, formatTime, formatAge, uploadUri } from 'app/utils'
import { history } from 'app/store'
import { Loader, MenuButton } from 'app/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)} />
</div>
<div>
<img src={data.url} />
<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,
})
export default connect(mapStateToProps)(UploadShow)
|