Skip to content

Commit

Permalink
feat(playground): add Reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Apr 24, 2024
1 parent 3b8e023 commit 4d8d0ee
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/src/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,26 @@ export default function Playground() {
updateWithEditorContent();
};

const reset = async () => {
setEditorContent({ html: initialCode?.html || HTML_DEFAULT, css: initialCode?.css || CSS_DEFAULT, js: initialCode?.js || JS_DEFAULT });

updateWithEditorContent();
};

const clearConfirm = async () => {
if (window.confirm("Do you really want to clear everything?")) {
gleanClick(`${PLAYGROUND}: reset-click`);
await clear();
}
};

const resetConfirm = async () => {
if (window.confirm("Do you really want to revert your changes?")) {
gleanClick(`${PLAYGROUND}: revert-click`);
await reset();
}
};

const updateWithEditorContent = () => {
const { html, css, js } = getEditorContent();
setIsEmpty(!html && !css && !js);
Expand Down Expand Up @@ -314,6 +327,16 @@ export default function Playground() {
>
clear
</Button>
{initialCode && (
<Button
type="secondary"
id="reset"
extraClasses="red"
onClickHandler={resetConfirm}
>
reset
</Button>
)}
</menu>
</aside>
<Editor
Expand Down

0 comments on commit 4d8d0ee

Please sign in to comment.