summaryrefslogtreecommitdiff
path: root/animism-align/frontend/views/media/components/media.menu.js
blob: 153a5c1ff36f92c3d0bfe374b62198058d12cadb (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
import React, { Component } from 'react'
import { Route, Link } from 'react-router-dom'
import { connect } from 'react-redux'

import { history } from '../../../store'
import actions from '../../../actions'
import { MenuButton, FileInput } from '../../../common'

const mapStateToProps = state => ({
  media: state.media,
})

export default class MediaMenu extends Component {
  render() {
    return (
      <div className='menuButtons'>
        <Route exact path='/media/:id/show/' component={MediaShowMenu} />
        <Route exact path='/media/:id/edit/' component={MediaEditMenu} />
        <Route exact path='/media/new/' component={MediaNewMenu} />
        <Route exact path='/media/' component={MediaIndexMenu} />
      </div>
    )
  }
}

const MediaIndexMenu = () => ([
  <MenuButton key='new' name="new" href="/media/new/" />,
])

const MediaShowMenu = connect(mapStateToProps)((props) => ([
  <MenuButton key='back' name="back" href="/media/" />,
  <MenuButton key='edit' name="edit" href={"/media/" + props.match.params.id + "/edit/"} />,
  <MenuButton key='delete' name="delete" onClick={() => {
    const { res: media } = props.media.show
    if (confirm("Really delete this media?")) {
      actions.media.destroy(media).then(() => {
        history.push('/media/')
      })
    }
  }} />,
]))

const MediaNewMenu = (props) => ([
  <MenuButton key='back' name="back" href="/media/" />,
])

const MediaEditMenu = connect(mapStateToProps)((props) => ([
  <MenuButton key='back' name="back" href="/media/" />,
  <MenuButton key='copy' name="copy" href={"/media/" + props.match.params.id + '/copy/'} label="Make a copy" />,
  <MenuButton key='delete' name="delete" onClick={() => {
    const { res: media } = props.media.show
    if (confirm("Really delete this media?")) {
      actions.media.destroy(media).then(() => {
        history.push('/media/')
      })
    }
  }} />,
]))