diff --git a/src/components/ProjectTemplatesSection.tsx b/src/components/ProjectTemplatesSection.tsx
index 5d73f8eb..d9e5750d 100644
--- a/src/components/ProjectTemplatesSection.tsx
+++ b/src/components/ProjectTemplatesSection.tsx
@@ -1,6 +1,25 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { FileCode2, Trash2, Plus } from 'lucide-react';
+import { FileCode2, Trash2, Plus, GripVertical, RotateCcw } from 'lucide-react';
+import {
+ DndContext,
+ closestCenter,
+ KeyboardSensor,
+ PointerSensor,
+ useSensor,
+ useSensors,
+ type DragEndEvent,
+} from '@dnd-kit/core';
+import {
+ arrayMove,
+ SortableContext,
+ sortableKeyboardCoordinates,
+ verticalListSortingStrategy,
+} from '@dnd-kit/sortable';
+import {
+ useSortable,
+} from '@dnd-kit/sortable';
+import { CSS } from '@dnd-kit/utilities';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
@@ -16,15 +35,128 @@ interface ProjectTemplate {
url: string;
}
+interface SortableTemplateItemProps {
+ template: ProjectTemplate;
+ index: number;
+ onRemove: (index: number) => void;
+ onUpdate: (index: number, template: ProjectTemplate) => void;
+ showDragHandle: boolean;
+ isOnlyTemplate: boolean;
+}
+
+function SortableTemplateItem({
+ template,
+ index,
+ onRemove,
+ onUpdate,
+ showDragHandle,
+ isOnlyTemplate,
+}: SortableTemplateItemProps) {
+ const { t } = useTranslation();
+ const {
+ attributes,
+ listeners,
+ setNodeRef,
+ transform,
+ transition,
+ isDragging,
+ } = useSortable({ id: `template-${index}` });
+
+ const style = {
+ transform: CSS.Transform.toString(transform),
+ transition,
+ opacity: isDragging ? 0.5 : 1,
+ };
+
+ return (
+
+
+
+ {showDragHandle && (
+
+
+
+ )}
+
+
{template.name}
+
+
+
+
+
+
+ onUpdate(index, { ...template, name: e.target.value })}
+ />
+
+
+
+
+
+
+ onUpdate(index, { ...template, url: e.target.value })}
+ />
+
+
+
+
+
+ );
+}
+
export function ProjectTemplatesSection() {
const { t } = useTranslation();
- const { config, updateConfig } = useAppContext();
+ const { config, defaultConfig, updateConfig } = useAppContext();
const { toast } = useToast();
const [newTemplateName, setNewTemplateName] = useState('');
const [newTemplateDescription, setNewTemplateDescription] = useState('');
const [newTemplateUrl, setNewTemplateUrl] = useState('');
const templates = config.templates || [];
+ const defaultTemplates = defaultConfig.templates || [];
+
+ const sensors = useSensors(
+ useSensor(PointerSensor),
+ useSensor(KeyboardSensor, {
+ coordinateGetter: sortableKeyboardCoordinates,
+ })
+ );
+
+ // Check if current templates match the default configuration
+ const templatesMatchDefault = JSON.stringify(templates) === JSON.stringify(defaultTemplates);
const handleAddTemplate = () => {
if (!newTemplateName.trim() || !newTemplateDescription.trim() || !newTemplateUrl.trim()) {
@@ -77,6 +209,31 @@ export function ProjectTemplatesSection() {
}));
};
+ const handleDragEnd = (event: DragEndEvent) => {
+ const { active, over } = event;
+
+ if (active.id !== over?.id) {
+ const oldIndex = parseInt(active.id.toString().replace('template-', ''));
+ const newIndex = parseInt(over?.id.toString().replace('template-', '') || '0');
+
+ if (!isNaN(oldIndex) && !isNaN(newIndex) && oldIndex !== newIndex) {
+ const newTemplates = arrayMove(templates, oldIndex, newIndex);
+ updateConfig((current) => ({
+ ...current,
+ templates: newTemplates,
+ }));
+ }
+ }
+ };
+
+ const handleResetToDefaults = () => {
+ // Remove the templates from local config so defaults take precedence
+ updateConfig((current) => {
+ const { templates: _, ...rest } = current;
+ return rest;
+ });
+ };
+
return (
{/* Divider */}
@@ -87,6 +244,18 @@ export function ProjectTemplatesSection() {
{t('projectTemplates')}
+ {!templatesMatchDefault && (
+
+ )}
+ {!templatesMatchDefault && (
+
+ )}
{t('projectTemplatesDescription')}
@@ -96,61 +265,30 @@ export function ProjectTemplatesSection() {
{/* Configured Templates List */}
{templates.length > 0 && (
- {templates.map((template, index) => (
-
-
-
-
-
- {template.name}
-
-
-
-
-
-
- handleUpdateTemplate(index, { ...template, name: e.target.value })}
- />
-
-
-
-
-
-
- handleUpdateTemplate(index, { ...template, url: e.target.value })}
- />
-
-
-
-
-
-
- ))}
+
+ `template-${index}`)}
+ strategy={verticalListSortingStrategy}
+ >
+
+ {templates.map((template, index) => (
+ 1}
+ isOnlyTemplate={templates.length === 1}
+ />
+ ))}
+
+
+
)}