Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add confirmation dialog to sandbox reset button #402

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/sandbox/src/components/SidebarActions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@
right: -0.325rem;
border-radius: 100%;
}

.localDeleteConfirmation {
display: flex;
flex-direction: column;
gap: 1rem;
}
43 changes: 41 additions & 2 deletions packages/sandbox/src/components/SidebarActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { NearIconSvg, Tooltip, useTheme } from '@bos-web-engine/ui';
import {
Button,
Dialog,
NearIconSvg,
Tooltip,
useTheme,
} from '@bos-web-engine/ui';
import {
Plus,
Code,
Expand All @@ -12,6 +18,7 @@ import {
Moon,
MagnifyingGlass,
} from '@phosphor-icons/react';
import { useState } from 'react';

import { GitHubIconSvg } from './GitHubIconSvg';
import s from './SidebarActions.module.css';
Expand All @@ -38,6 +45,8 @@ export function SidebarActions({ showFileOpener }: Props) {
const { modifiedFilePaths } = useModifiedFiles();
const { theme, setTheme } = useTheme();

const [localDeleteIsOpen, setLocalDeleteIsOpen] = useState(false);

const formatCode = () => {
const actionName = 'editor.action.formatDocument';

Expand Down Expand Up @@ -211,11 +220,41 @@ export function SidebarActions({ showFileOpener }: Props) {
side="right"
container={containerElement}
>
<button className={s.action} type="button" onClick={resetAllFiles}>
<button
className={s.action}
type="button"
onClick={() => setLocalDeleteIsOpen(true)}
>
<FileX />
</button>
</Tooltip>

<Dialog.Root
open={localDeleteIsOpen}
onOpenChange={setLocalDeleteIsOpen}
>
<Dialog.Portal container={containerElement}>
<Dialog.Content anchor="center" size="m">
<div className={s.localDeleteConfirmation}>
<h2>Delete local components and reinitialize examples</h2>
<p>
Any components in the editor which have not been published
will be lost. Would you like to proceed?
</p>
<Button
style={{ alignSelf: 'flex-end' }}
onClick={() => {
setLocalDeleteIsOpen(false);
resetAllFiles();
}}
>
Yes
</Button>
</div>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>

{theme === 'dark' ? (
<Tooltip
content="Change to light theme"
Expand Down
Loading