import { useState, useMemo, useCallback } from "react"; import { useAppStore, AIProfile, } from "@/store/app-store"; import { useKeyboardShortcuts, useKeyboardShortcutsConfig, KeyboardShortcut, } from "@/hooks/use-keyboard-shortcuts"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Sparkles } from "lucide-react"; import { toast } from "sonner"; import { DeleteConfirmDialog } from "@/components/ui/delete-confirm-dialog"; import { DndContext, DragEndEvent, PointerSensor, useSensor, useSensors, closestCenter, } from "@dnd-kit/core"; import { SortableContext, verticalListSortingStrategy, } from "@dnd-kit/sortable"; import { SortableProfileCard, ProfileForm, ProfilesHeader, } from "./profiles-view/components"; export function ProfilesView() { const { aiProfiles, addAIProfile, updateAIProfile, removeAIProfile, reorderAIProfiles, resetAIProfiles, } = useAppStore(); const shortcuts = useKeyboardShortcutsConfig(); const [showAddDialog, setShowAddDialog] = useState(false); const [editingProfile, setEditingProfile] = useState(null); const [profileToDelete, setProfileToDelete] = useState(null); // Sensors for drag-and-drop const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 5, }, }) ); // Separate built-in and custom profiles const builtInProfiles = useMemo( () => aiProfiles.filter((p) => p.isBuiltIn), [aiProfiles] ); const customProfiles = useMemo( () => aiProfiles.filter((p) => !p.isBuiltIn), [aiProfiles] ); const handleDragEnd = useCallback( (event: DragEndEvent) => { const { active, over } = event; if (over && active.id !== over.id) { const oldIndex = aiProfiles.findIndex((p) => p.id === active.id); const newIndex = aiProfiles.findIndex((p) => p.id === over.id); if (oldIndex !== -1 && newIndex !== -1) { reorderAIProfiles(oldIndex, newIndex); } } }, [aiProfiles, reorderAIProfiles] ); const handleAddProfile = (profile: Omit) => { addAIProfile(profile); setShowAddDialog(false); toast.success("Profile created", { description: `Created "${profile.name}" profile`, }); }; const handleUpdateProfile = (profile: Omit) => { if (editingProfile) { updateAIProfile(editingProfile.id, profile); setEditingProfile(null); toast.success("Profile updated", { description: `Updated "${profile.name}" profile`, }); } }; const confirmDeleteProfile = () => { if (!profileToDelete) return; removeAIProfile(profileToDelete.id); toast.success("Profile deleted", { description: `Deleted "${profileToDelete.name}" profile`, }); setProfileToDelete(null); }; const handleResetProfiles = () => { resetAIProfiles(); toast.success("Profiles refreshed", { description: "Default profiles have been updated to the latest version", }); }; // Build keyboard shortcuts for profiles view const profilesShortcuts: KeyboardShortcut[] = useMemo(() => { const shortcutsList: KeyboardShortcut[] = []; // Add profile shortcut - when in profiles view shortcutsList.push({ key: shortcuts.addProfile, action: () => setShowAddDialog(true), description: "Create new profile", }); return shortcutsList; }, [shortcuts]); // Register keyboard shortcuts for profiles view useKeyboardShortcuts(profilesShortcuts); return (
{/* Header Section */} setShowAddDialog(true)} addProfileHotkey={shortcuts.addProfile} /> {/* Content */}
{/* Custom Profiles Section */}

Custom Profiles

{customProfiles.length}
{customProfiles.length === 0 ? (
setShowAddDialog(true)} >

No custom profiles yet. Create one to get started!

) : ( p.id)} strategy={verticalListSortingStrategy} >
{customProfiles.map((profile) => ( setEditingProfile(profile)} onDelete={() => setProfileToDelete(profile)} /> ))}
)}
{/* Built-in Profiles Section */}

Built-in Profiles

{builtInProfiles.length}

Pre-configured profiles for common use cases. These cannot be edited or deleted.

p.id)} strategy={verticalListSortingStrategy} >
{builtInProfiles.map((profile) => ( {}} onDelete={() => {}} /> ))}
{/* Add Profile Dialog */} Create New Profile Define a reusable model configuration preset. setShowAddDialog(false)} isEditing={false} hotkeyActive={showAddDialog} /> {/* Edit Profile Dialog */} setEditingProfile(null)} > Edit Profile Modify your profile settings. {editingProfile && ( setEditingProfile(null)} isEditing={true} hotkeyActive={!!editingProfile} /> )} {/* Delete Confirmation Dialog */} !open && setProfileToDelete(null)} onConfirm={confirmDeleteProfile} title="Delete Profile" description={ profileToDelete ? `Are you sure you want to delete "${profileToDelete.name}"? This action cannot be undone.` : "" } confirmText="Delete Profile" testId="delete-profile-confirm-dialog" confirmTestId="confirm-delete-profile-button" />
); }