Skip to content

Commit c8662be

Browse files
committed
fix(editor): fix add stops mode
1 parent 5fe0ea8 commit c8662be

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

lib/editor/components/pattern/PatternStopsPanel.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export default class PatternStopsPanel extends Pure {
2020
updateEditSetting: PropTypes.func.isRequired
2121
}
2222

23-
_onClickAddStop = () => this.props.updateEditSetting('addStops', !this.props.editSettings.addStops)
23+
_toggleAddStopsMode = () => {
24+
const {editSettings, updateEditSetting} = this.props
25+
updateEditSetting('addStops', !editSettings.present.addStops)
26+
}
2427

25-
addStopFromSelect = (input) => {
28+
_addStopFromSelect = (input) => {
2629
if (!input) {
2730
return
2831
}
@@ -45,9 +48,11 @@ export default class PatternStopsPanel extends Pure {
4548
setActiveStop,
4649
status,
4750
stops,
48-
updateActiveEntity,
49-
updateEditSetting
51+
updateActiveEntity
5052
} = this.props
53+
const {addStops} = editSettings.present
54+
const patternHasStops = activePattern.patternStops &&
55+
activePattern.patternStops.length > 0
5156
const cardStyle = {
5257
border: '1px dashed gray',
5358
padding: '0.5rem 0.5rem',
@@ -63,31 +68,36 @@ export default class PatternStopsPanel extends Pure {
6368
</h4>
6469
<div style={{width: '100%'}}>
6570
<Button
66-
onClick={this._onClickAddStop}
71+
onClick={this._toggleAddStopsMode}
6772
className='pull-right'
68-
// bsStyle={editSettings.addStops ? 'default' : 'success'}
6973
bsSize='small'>
70-
{editSettings.addStops
74+
{addStops
7175
? <span><Icon type='times' /> Cancel</span>
7276
: <span><Icon type='plus' /> Add stop</span>
7377
}
7478
</Button>
75-
<small className='pull-right' style={{margin: '5px'}}>{editSettings.addStops && mapState.zoom <= 14
76-
? 'Zoom to view stops'
77-
: `Add stops via map`
78-
}</small>
79+
<small className='pull-right' style={{margin: '5px'}}>
80+
{addStops && mapState.zoom <= 14
81+
? 'Zoom to view stops'
82+
: `Add stops via map`
83+
}
84+
</small>
7985
</div>
8086
{/* List of pattern stops */}
8187
<div id='pattern-stop-list-header'>
8288
<div className='pull-left' style={{width: '50%'}}>
83-
<p className='small' style={{marginBottom: '0px'}}><strong>Stop sequence</strong></p>
89+
<p className='small' style={{marginBottom: '0px'}}>
90+
<strong>Stop sequence</strong>
91+
</p>
8492
</div>
8593
<div className='pull-right' style={{width: '50%'}}>
86-
<p style={{marginBottom: '0px'}} className='small text-right'><strong>Travel time</strong></p>
94+
<p style={{marginBottom: '0px'}} className='small text-right'>
95+
<strong>Travel time</strong>
96+
</p>
8797
</div>
8898
<div className='clearfix' />
8999
</div>
90-
{activePattern.patternStops && activePattern.patternStops.length > 0
100+
{patternHasStops
91101
? <PatternStopContainer
92102
stops={stops}
93103
cardStyle={cardStyle}
@@ -101,32 +111,30 @@ export default class PatternStopsPanel extends Pure {
101111
setActiveEntity={setActiveEntity}
102112
feedSource={feedSource}
103113
patternEdited={patternEdited}
104-
setActiveStop={setActiveStop}
105-
editSettings={editSettings}
106-
updateEditSetting={updateEditSetting} />
114+
setActiveStop={setActiveStop} />
107115
: <p className='lead text-center'>This pattern has no stops.</p>
108116
}
109117
{/* Add stop selector */}
110-
{editSettings.addStops
118+
{addStops
111119
? <div style={cardStyle}>
112120
<VirtualizedEntitySelect
113121
component={'stop'}
114122
entities={stops}
115-
onChange={this.addStopFromSelect} />
123+
onChange={this._addStopFromSelect} />
116124
<div style={{marginTop: '5px'}}>
117125
<Button
118126
bsSize='small'
119127
bsStyle='default'
120128
block
121-
onClick={this._onClickAddStop}>
129+
onClick={this._toggleAddStopsMode}>
122130
<Icon type='times' /> Cancel
123131
</Button>
124132
</div>
125133
</div>
126134
: <Button
127135
bsSize='small'
128136
block
129-
onClick={this._onClickAddStop}>
137+
onClick={this._toggleAddStopsMode}>
130138
<Icon type='plus' /> Add stop by name
131139
</Button>
132140
}

0 commit comments

Comments
 (0)