mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix: project removal not being executed
- Prevent context menu from closing when a confirmation dialog is open. - Add success toast notification upon project removal. - Refactor event handlers to account for dialog state, improving user experience.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useRef, useState, memo } from 'react';
|
import { useEffect, useRef, useState, memo } from 'react';
|
||||||
import type { LucideIcon } from 'lucide-react';
|
import type { LucideIcon } from 'lucide-react';
|
||||||
import { Edit2, Trash2, Palette, ChevronRight, Moon, Sun, Monitor } from 'lucide-react';
|
import { Edit2, Trash2, Palette, ChevronRight, Moon, Sun, Monitor } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { type ThemeMode, useAppStore } from '@/store/app-store';
|
import { type ThemeMode, useAppStore } from '@/store/app-store';
|
||||||
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
||||||
@@ -129,14 +130,20 @@ export function ProjectContextMenu({
|
|||||||
const { handlePreviewEnter, handlePreviewLeave } = useThemePreview({ setPreviewTheme });
|
const { handlePreviewEnter, handlePreviewLeave } = useThemePreview({ setPreviewTheme });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleClickOutside = (event: MouseEvent) => {
|
const handleClickOutside = (event: globalThis.MouseEvent) => {
|
||||||
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
// Don't close if a confirmation dialog is open (dialog is in a portal)
|
||||||
|
if (showRemoveDialog) return;
|
||||||
|
|
||||||
|
if (menuRef.current && !menuRef.current.contains(event.target as globalThis.Node)) {
|
||||||
setPreviewTheme(null);
|
setPreviewTheme(null);
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEscape = (event: KeyboardEvent) => {
|
const handleEscape = (event: globalThis.KeyboardEvent) => {
|
||||||
|
// Don't close if a confirmation dialog is open (let the dialog handle escape)
|
||||||
|
if (showRemoveDialog) return;
|
||||||
|
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
setPreviewTheme(null);
|
setPreviewTheme(null);
|
||||||
onClose();
|
onClose();
|
||||||
@@ -150,7 +157,7 @@ export function ProjectContextMenu({
|
|||||||
document.removeEventListener('mousedown', handleClickOutside);
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
document.removeEventListener('keydown', handleEscape);
|
document.removeEventListener('keydown', handleEscape);
|
||||||
};
|
};
|
||||||
}, [onClose, setPreviewTheme]);
|
}, [onClose, setPreviewTheme, showRemoveDialog]);
|
||||||
|
|
||||||
const handleEdit = () => {
|
const handleEdit = () => {
|
||||||
onEdit(project);
|
onEdit(project);
|
||||||
@@ -173,11 +180,16 @@ export function ProjectContextMenu({
|
|||||||
|
|
||||||
const handleConfirmRemove = () => {
|
const handleConfirmRemove = () => {
|
||||||
moveProjectToTrash(project.id);
|
moveProjectToTrash(project.id);
|
||||||
|
toast.success('Project removed', {
|
||||||
|
description: `${project.name} has been removed from your projects list`,
|
||||||
|
});
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{/* Hide context menu when confirm dialog is open */}
|
||||||
|
{!showRemoveDialog && (
|
||||||
<div
|
<div
|
||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -316,6 +328,7 @@ export function ProjectContextMenu({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<ConfirmDialog
|
<ConfirmDialog
|
||||||
open={showRemoveDialog}
|
open={showRemoveDialog}
|
||||||
|
|||||||
Reference in New Issue
Block a user