forked from gryffon/ringteki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditDeck.jsx
More file actions
109 lines (93 loc) · 3.17 KB
/
Copy pathEditDeck.jsx
File metadata and controls
109 lines (93 loc) · 3.17 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import DeckSummary from './DeckSummary.jsx';
import DeckEditor from './DeckEditor.jsx';
import AlertPanel from './SiteComponents/AlertPanel.jsx';
import * as actions from './actions';
class InnerEditDeck extends React.Component {
constructor() {
super();
this.onEditDeck = this.onEditDeck.bind(this);
}
componentWillMount() {
if(this.props.deckId) {
return this.props.loadDeck(this.props.deckId);
} else if(this.props.deck) {
this.props.setUrl('/decks/edit/' + this.props.deck._id);
return this.props.loadDeck(this.props.deck._id);
}
}
componentWillUpdate() {
if(this.props.deckSaved) {
this.props.navigate('/decks');
return;
}
}
onEditDeck(deck) {
this.props.saveDeck(deck);
}
render() {
let content;
if(this.props.loading) {
content = <div>Loading decks from the server...</div>;
} else if(this.props.apiError) {
content = <AlertPanel type='error' message={ this.props.apiError } />;
} else if(!this.props.deck) {
content = <AlertPanel message='The specified deck was not found' type='error' />;
} else {
content = (
<div>
<div className='col-sm-6'>
<div className='panel-title text-center'>
Deck Editor
</div>
<div className='panel'>
<DeckEditor mode='Save' onDeckSave={ this.onEditDeck } />
</div>
</div>
<div className='col-sm-6'>
<div className='panel-title text-center col-xs-12'>
{ this.props.deck.name }
</div>
<div className='panel col-xs-12'>
<DeckSummary cards={ this.props.cards } deck={ this.props.deck } />
</div>
</div>
</div>);
}
return content;
}
}
InnerEditDeck.displayName = 'InnerEditDeck';
InnerEditDeck.propTypes = {
agendas: PropTypes.object,
apiError: PropTypes.string,
banners: PropTypes.array,
cards: PropTypes.object,
deck: PropTypes.object,
deckId: PropTypes.string,
deckSaved: PropTypes.bool,
factions: PropTypes.object,
loadDeck: PropTypes.func,
loading: PropTypes.bool,
navigate: PropTypes.func,
packs: PropTypes.array,
saveDeck: PropTypes.func,
setUrl: PropTypes.func
};
function mapStateToProps(state) {
return {
agendas: state.cards.agendas,
apiError: state.api.message,
banners: state.cards.banners,
cards: state.cards.cards,
deck: state.cards.selectedDeck,
deckSaved: state.cards.deckSaved,
factions: state.cards.factions,
loading: state.api.loading,
socket: state.socket.socket
};
}
const EditDeck = connect(mapStateToProps, actions)(InnerEditDeck);
export default EditDeck;