Skip to content

Commit 05d8759

Browse files
committed
fix(scene): persist the volume type of the "play notification" action
Switching between the Simple and Computed volume tabs only changed the local state: an action switched to Computed without editing the formula kept its fixed volume, and one switched back to Simple without moving the slider kept evaluating the formula. The tabs now use the same pattern as the "Set a variable" action: clicking the active tab is a no-op, switching clears the value of the other type, and switching to Computed seeds the formula with the volume shown by the slider. They are also real buttons, so they stay reachable with the keyboard, as the shared valueTypeLink style already documents. Autofix-Pass: 1
1 parent bf16961 commit 05d8759

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

front/src/routes/scene/edit-scene/actions/PlayNotification.jsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,37 @@ class PlayNotification extends Component {
2929
console.error(e);
3030
}
3131
};
32-
toggleVolumeType = () => this.setState({ computedVolume: !this.state.computedVolume });
32+
// Switching the volume type clears the value of the other type, so the action never keeps both
33+
// a "volume" and an "evaluate_volume": the server evaluates the formula as soon as it is there,
34+
// and the fixed volume would be silently ignored.
35+
selectVolumeType = computedVolume => {
36+
if (computedVolume === this.state.computedVolume) {
37+
return;
38+
}
39+
this.setState({ computedVolume });
40+
if (computedVolume) {
41+
// The formula starts from the volume currently selected, so switching to computed does not
42+
// lose the value shown by the slider.
43+
const { volume } = this.props.action;
44+
const evaluateVolume = volume !== undefined ? `${volume}` : undefined;
45+
this.props.updateActionProperty(this.props.path, 'evaluate_volume', evaluateVolume);
46+
this.props.updateActionProperty(this.props.path, 'volume', undefined);
47+
} else {
48+
this.props.updateActionProperty(this.props.path, 'evaluate_volume', undefined);
49+
}
50+
};
51+
52+
selectSimpleType = () => this.selectVolumeType(false);
53+
54+
selectComputedType = () => this.selectVolumeType(true);
55+
3356
updateVolume = e => {
3457
this.props.updateActionProperty(this.props.path, 'volume', parseInt(e.target.value, 10));
3558
this.props.updateActionProperty(this.props.path, 'evaluate_volume', undefined);
3659
};
3760
updateEvaluateVolume = text => {
3861
this.props.updateActionProperty(this.props.path, 'volume', undefined);
39-
this.props.updateActionProperty(this.props.path, 'evaluate_volume', text);
62+
this.props.updateActionProperty(this.props.path, 'evaluate_volume', text.length > 0 ? text : undefined);
4063
};
4164
updateText = text => {
4265
this.props.updateActionProperty(this.props.path, 'text', text);
@@ -83,11 +106,7 @@ class PlayNotification extends Component {
83106
</div>
84107
<div class="input-group">
85108
<TextWithVariablesInjected
86-
text={
87-
this.props.action.volume !== undefined
88-
? Number(this.props.action.volume).toString()
89-
: this.props.action.evaluate_volume
90-
}
109+
text={this.props.action.evaluate_volume || ''}
91110
path={this.props.path}
92111
triggersVariables={this.props.triggersVariables}
93112
actionsGroupsBefore={this.props.actionsGroupsBefore}
@@ -155,18 +174,20 @@ class PlayNotification extends Component {
155174
</span>
156175
</label>
157176
<div className={cx('nav-tabs', style.valueTypeTab)}>
158-
<span
177+
<button
178+
type="button"
159179
class={cx('nav-link', style.valueTypeLink, { active: !this.state.computedVolume })}
160-
onClick={this.toggleVolumeType}
180+
onClick={this.selectSimpleType}
161181
>
162182
<Text id="editScene.actionsCard.playNotification.valueTypeSimple" />
163-
</span>
164-
<span
183+
</button>
184+
<button
185+
type="button"
165186
class={cx('nav-link', style.valueTypeLink, { active: this.state.computedVolume })}
166-
onClick={this.toggleVolumeType}
187+
onClick={this.selectComputedType}
167188
>
168189
<Text id="editScene.actionsCard.playNotification.valueTypeComputed" />
169-
</span>
190+
</button>
170191
</div>
171192
{this.getVolumeInput()}
172193
</div>

0 commit comments

Comments
 (0)