Skip to content

Commit 357d2cc

Browse files
authored
sound-editor.jsx -- use modal api
1 parent 4ccb2dc commit 357d2cc

File tree

1 file changed

+26
-69
lines changed

1 file changed

+26
-69
lines changed

src/containers/sound-editor.jsx

Lines changed: 26 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,21 @@ class SoundEditor extends React.Component {
506506
);
507507
const pitchParts = pitchDiv.children;
508508
const volumeParts = volumeDiv.children;
509-
const menu = this.displayPopup("Modify Sound", 200, 280, "Apply", "Cancel", () => {
510-
// accepted
511-
audio.close();
512-
const pitch = pitchParts[1].value, volume = volumeParts[1].value;
513-
const truePitch = isNaN(Number(pitch)) ? 0 : Number(pitch);
514-
const trueVolume = isNaN(Number(volume)) ? 0 : Number(volume);
515-
this.handleEffect({
516-
pitch: truePitch * 10,
517-
volume: trueVolume
518-
});
519-
}, () => {
520-
// denied
521-
audio.close();
522-
// we dont need to do anything else
523-
});
509+
const menu = window.ScratchBlocks.customPrompt(
510+
"Modify Sound", { width: 200, height: 280 },
511+
{
512+
name: "Apply", callback: () => {
513+
audio.close();
514+
const pitch = pitchParts[1].value, volume = volumeParts[1].value;
515+
const truePitch = isNaN(Number(pitch)) ? 0 : Number(pitch);
516+
const trueVolume = isNaN(Number(volume)) ? 0 : Number(volume);
517+
this.handleEffect({
518+
pitch: truePitch * 10, volume: trueVolume
519+
});
520+
}
521+
},
522+
{ name: "Cancel", callback: () => audio.close() },
523+
);
524524

525525
menu.textarea.style = "margin: 0 10px 0 10px;position: relative;display: flex;justify-content: flex-end;flex-direction: row;height: calc(100% - (3.125em + 2.125em + 16px));align-items: center;";
526526
menu.textarea.append(pitchDiv, volumeDiv);
@@ -617,12 +617,17 @@ class SoundEditor extends React.Component {
617617
];
618618
let selectedSampleRate = this.props.sampleRate;
619619
let selectedForceRate = false;
620-
const menu = this.displayPopup("Format Sound", 350, 300, "Apply", "Cancel", () => {
621-
// accepted
622-
const edits = { sampleRate: selectedSampleRate };
623-
if (selectedForceRate) edits.sampleRateEnforced = selectedSampleRate;
624-
this.handleEffect(edits);
625-
});
620+
const menu = window.ScratchBlocks.customPrompt(
621+
"Format Sound", { width: 350, height: 300 },
622+
{
623+
name: "Apply", callback: () => {
624+
const edits = { sampleRate: selectedSampleRate };
625+
if (selectedForceRate) edits.sampleRateEnforced = selectedSampleRate;
626+
this.handleEffect(edits);
627+
}
628+
},
629+
{ name: "Cancel", callback: () => {} },
630+
);
626631

627632
menu.textarea.style = "padding: 10px 20px;";
628633
const rateTitle = genTitle("New Sample Rate:");
@@ -669,54 +674,6 @@ class SoundEditor extends React.Component {
669674
});
670675
menu.textarea.append(rateTitle, warningDiv, genTitle("Apply to:"), applicatorDiv, warningDiv2);
671676
}
672-
673-
// TODO: use actual scratch-gui menus instead of this
674-
displayPopup(title, width, height, okname, denyname, accepted, cancelled) {
675-
const div = document.createElement("div");
676-
document.body.append(div);
677-
div.classList.add(confirmStyles.base);
678-
const box = document.createElement("div");
679-
div.append(box);
680-
box.classList.add(confirmStyles.promptBox);
681-
box.style.width = `${width}px`;
682-
box.style.height = `${height}px`;
683-
const header = document.createElement("div");
684-
box.append(header);
685-
header.classList.add(confirmStyles.header);
686-
header.innerText = title;
687-
const textarea = document.createElement("div");
688-
box.append(textarea);
689-
const buttonRow = document.createElement("div");
690-
box.append(buttonRow);
691-
buttonRow.classList.add(confirmStyles.buttonRow);
692-
const deny = document.createElement("button");
693-
buttonRow.append(deny);
694-
deny.classList.add(confirmStyles.promptButton);
695-
deny.classList.add(confirmStyles.deny);
696-
deny.innerHTML = denyname ? denyname : "Cancel";
697-
const accept = document.createElement("button");
698-
buttonRow.append(accept);
699-
accept.classList.add(confirmStyles.promptButton);
700-
accept.classList.add(confirmStyles.accept);
701-
accept.innerHTML = okname ? okname : "OK";
702-
accept.onclick = () => {
703-
div.remove();
704-
if (accepted) accepted();
705-
}
706-
deny.onclick = () => {
707-
div.remove();
708-
if (cancelled) cancelled();
709-
}
710-
return {
711-
popup: div,
712-
container: box,
713-
header: header,
714-
buttonRow: buttonRow,
715-
textarea: textarea,
716-
cancel: deny,
717-
ok: accept
718-
}
719-
}
720677
render() {
721678
const { effectTypes } = AudioEffects;
722679
return (

0 commit comments

Comments
 (0)