Skip to content

Commit

Permalink
refactor: unify clear canvas and reset buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
matyson committed Mar 28, 2024
1 parent 38e13b7 commit f7c2152
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 59 deletions.
52 changes: 0 additions & 52 deletions apps/pianno/components/toolbar/clear-canvas.tsx

This file was deleted.

24 changes: 19 additions & 5 deletions apps/pianno/components/toolbar/reset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import { useStoreActions } from '@/hooks/use-store';
import { useStoreActions, useStoreImg } from '@/hooks/use-store';
import { useWindowSize } from '@/hooks/use-window-size';
import { useTemporalStore } from '@/providers/store';
import { RotateCcwIcon } from 'lucide-react';
import { FC } from 'react';

import { Button } from '../ui/button';
import { Button, buttonVariants } from '../ui/button';

interface ResetProps {}

const Reset: FC<ResetProps> = ({}) => {
const { recenterViewport, reset } = useStoreActions();
const { recenterViewport, reset, softReset } = useStoreActions();
const img = useStoreImg();
const { clear } = useTemporalStore((state) => state);
const [width, height] = useWindowSize();
const onContinue = () => {
const handleClean = () => {
softReset();
clear();
recenterViewport(img.width, img.height);
};
const handleReset = () => {
reset();
clear();
recenterViewport(width, height);
Expand All @@ -45,7 +51,15 @@ const Reset: FC<ResetProps> = ({}) => {
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={onContinue}>Continue</AlertDialogAction>
<AlertDialogAction disabled={img.src === '#'} onClick={handleClean}>
Clear Canvas
</AlertDialogAction>
<AlertDialogAction
className={buttonVariants({ variant: 'destructive' })}
onClick={handleReset}
>
Clear Everything
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Expand Down
2 changes: 0 additions & 2 deletions apps/pianno/components/toolbar/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { useHotkeys } from 'react-hotkeys-hook';

import { Button, buttonVariants } from '../ui/button';
import ClearCanvas from './clear-canvas';
import OpenImageDialog from './open';
import Reset from './reset';
import SaveDialog from './save';
Expand Down Expand Up @@ -161,7 +160,6 @@ const Toolbar = () => {
{action.children}
</Button>
))}
<ClearCanvas />
<Reset />
</div>
{img.src === '#' && <ToolbarMessenger />}
Expand Down

0 comments on commit f7c2152

Please sign in to comment.