From db05223c686185fd556af068b1c9e67ec238e265 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Dec 2025 15:18:34 -0600 Subject: [PATCH] Move project templates to AI settings --- src/components/ProjectTemplatesSection.tsx | 218 +++++++++++++++++++++ src/lib/system.test.ts | 11 +- src/lib/system.ts | 8 +- src/locales/en.json | 12 +- src/pages/AISettings.tsx | 4 + src/pages/SystemSettings.tsx | 144 +------------- 6 files changed, 239 insertions(+), 158 deletions(-) create mode 100644 src/components/ProjectTemplatesSection.tsx diff --git a/src/components/ProjectTemplatesSection.tsx b/src/components/ProjectTemplatesSection.tsx new file mode 100644 index 00000000..695a3ea0 --- /dev/null +++ b/src/components/ProjectTemplatesSection.tsx @@ -0,0 +1,218 @@ +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { FileCode2, Trash2, Plus } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; +import { Label } from '@/components/ui/label'; +import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; +import { Separator } from '@/components/ui/separator'; +import { Alert, AlertDescription } from '@/components/ui/alert'; +import { useAppContext } from '@/hooks/useAppContext'; +import { useToast } from '@/hooks/useToast'; + +interface ProjectTemplate { + name: string; + description: string; + url: string; +} + +export function ProjectTemplatesSection() { + const { t } = useTranslation(); + const { config, updateConfig } = useAppContext(); + const { toast } = useToast(); + const [newTemplateName, setNewTemplateName] = useState(''); + const [newTemplateDescription, setNewTemplateDescription] = useState(''); + const [newTemplateUrl, setNewTemplateUrl] = useState(''); + + const templates = config.templates || []; + + const handleAddTemplate = () => { + if (!newTemplateName.trim() || !newTemplateDescription.trim() || !newTemplateUrl.trim()) { + return; + } + + const newTemplate: ProjectTemplate = { + name: newTemplateName.trim(), + description: newTemplateDescription.trim(), + url: newTemplateUrl.trim(), + }; + + updateConfig((current) => ({ + ...current, + templates: [...(current.templates || []), newTemplate], + })); + + toast({ + title: t('templateAdded'), + description: t('templateAddedDescription', { name: newTemplateName.trim() }), + }); + + setNewTemplateName(''); + setNewTemplateDescription(''); + setNewTemplateUrl(''); + }; + + const handleRemoveTemplate = (index: number) => { + const templateName = templates[index]?.name || 'template'; + const newTemplates = templates.filter((_, i) => i !== index); + + updateConfig((current) => ({ + ...current, + templates: newTemplates, + })); + + toast({ + title: t('templateDeleted'), + description: t('templateDeletedDescription', { name: templateName }), + }); + }; + + const handleUpdateTemplate = (index: number, updatedTemplate: ProjectTemplate) => { + const newTemplates = [...templates]; + newTemplates[index] = updatedTemplate; + + updateConfig((current) => ({ + ...current, + templates: newTemplates, + })); + }; + + return ( +
+ {/* Divider */} + + + {/* Project Templates Header */} +
+
+ +

{t('projectTemplates')}

+
+

+ {t('projectTemplatesDescription')} +

+
+ + {/* Configured Templates List */} + {templates.length > 0 ? ( +
+ {templates.map((template, index) => ( + + + +
+ + {template.name} +
+
+ +
+
+ + handleUpdateTemplate(index, { ...template, name: e.target.value })} + /> +
+
+ +