Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: drag-and-drop reordering for AI presets

Louis Beaumontfc1a1d3ada6b
diff --git a/apps/screenpipe-app-tauri/bun.lock b/apps/screenpipe-app-tauri/bun.lock
index 163893a05..556ca542d 100644
--- a/apps/screenpipe-app-tauri/bun.lock
+++ b/apps/screenpipe-app-tauri/bun.lock
@@ -5,6 +5,9 @@
"": {
"name": "screenpipe-app",
"dependencies": {
+ "@dnd-kit/core": "^6.3.1",
+ "@dnd-kit/sortable": "^10.0.0",
+ "@dnd-kit/utilities": "^3.2.2",
"@patternfly/react-core": "^6.4.1",
"@patternfly/react-log-viewer": "^6.3.0",
"@radix-ui/react-accordion": "^1.2.12",
@@ -191,6 +194,14 @@
"@csstools/css-tokenizer": ["@csstools/[email protected]", "", {}, "sha512-Vd/9EVDiu6PPJt9yAh6roZP6El1xHrdvIVGjyBsHR0RYwNHgL7FJPyIIW4fANJNG6FtyZfvlRPpFI4ZM/lubvw=="],
+ "@dnd-kit/accessibility": ["@dnd-kit/[email protected]", "", { "dependencies": { "tslib": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0" } }, "sha512-2P+YgaXF+gRsIihwwY1gCsQSYnu9Zyj2py8kY5fFvUM1qm2WA2u639R6YNVfU4GWr+ZM5mqEsfHZZLoRONbemw=="],
+
+ "@dnd-kit/core": ["@dnd-kit/[email protected]", "", { "dependencies": { "@dnd-kit/accessibility": "^3.1.1", "@dnd-kit/utilities": "^3.2.2", "tslib": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ=="],
+
+ "@dnd-kit/sortable": ["@dnd-kit/[email protected]", "", { "dependencies": { "@dnd-kit/utilities": "^3.2.2", "tslib": "^2.0.0" }, "peerDependencies": { "@dnd-kit/core": "^6.3.0", "react": ">=16.8.0" } }, "sha512-+xqhmIIzvAYMGfBYYnbKuNicfSsk4RksY2XdmJhT+HAC01nix6fHCztU68jooFiMUB01Ky3F0FyOvhG/BZrWkg=="],
+
+ "@dnd-kit/utilities": ["@dnd-kit/[email protected]", "", { "dependencies": { "tslib": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0" } }, "sha512-+MKAJEOfaBe5SmV6t34p80MMKhjvUz0vRrvVJbPT0WElzaOJ/1xs+D+KDv+tD/NE5ujfrChEcshd4fLn0wpiqg=="],
+
"@emnapi/runtime": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
"@esbuild/aix-ppc64": ["@esbuild/[email protected]", "", { "os": "aix", "cpu": "ppc64" }, "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q=="],
diff --git a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
index 35aae98a6..9a4051a94 100644
--- a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
@@ -1697,6 +1697,111 @@ const providerImageSrc: Record<string, string> = {
pi: "/images/screenpipe.png",
};
+// Sortable preset card for drag-and-drop reordering
+function SortablePresetCard({
+ preset,
+ isDefault,
+ hasValidation,
+ onEdit,
+ onDuplicate,
+ onSetDefault,
+ onDelete,
+ isLoading,
+}: {
+ preset: AIPreset;
+ isDefault: boolean;
+ hasValidation: boolean;
+ onEdit: () => void;
+ onDuplicate: () => void;
+ onSetDefault: () => void;
+ onDelete: () => void;
+ isLoading: boolean;
+}) {
+ const {
+ attributes,
+ listeners,
+ setNodeRef,
+ transform,
+ transition,
+ isDragging,
+ } = useSortable({ id: preset.id });
+
+ const style = {
+ transform: CSS.Transform.toString(transform),
+ transition,
+ opacity: isDragging ? 0.5 : 1,
+ zIndex: isDragging ? 50 : undefined,
+ };
+
+ return (
+ <Card
+ ref={setNodeRef}
+ style={style}
+ className={cn(
+ "p-3 relative group transition-all hover:shadow-md border-border bg-card cursor-pointer",
+ isDefault && "ring-2 ring-primary/20",
+ isDragging && "shadow-lg"
+ )}
+ onClick={onEdit}
+ >
+ <div className="space-y-2">
+ <div className="flex justify-between items-center">
+ <div className="flex items-center gap-2 flex-1 min-w-0">
+ <button
+ className="cursor-grab active:cursor-grabbing touch-none text-muted-foreground hover:text-foreground shrink-0"
+ {...attributes}
+ {...listeners}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <GripVertical className="w-4 h-4" />
+ </button>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ src={providerImageSrc[preset.provider]}
+ alt={`${preset.provider} logo`}
+ className="w-6 h-6 opacity-80 rounded shrink-0"
+ />
+ <h3 className="text-sm font-semibold text-foreground truncate" title={preset.id}>
+ {formatPresetName(preset.id)}
+ </h3>
+ {isDefault && (
+ <Badge variant="default" className="text-[10px] px-1.5 py-0">
+ default
+ </Badge>
+ )}
+ {!hasValidation && (
+ <AlertCircle className="h-3.5 w-3.5 text-destructive shrink-0" />
+ )}
+ </div>
+ {hasValidation ? (
+ <CheckCircle2 className="h-4 w-4 text-foreground/50 shrink-0" />
+ ) : (
+ <AlertCircle className="h-4 w-4 text-destructive shrink-0" />
+ )}
+ </div>
+ <div className="flex items-center gap-1.5 text-xs text-muted-foreground">
+ <span className="font-mono bg-muted px-1.5 py-0.5 rounded truncate max-w-[180px]" title={preset.model || 'Not set'}>
+ {preset.model || 'Not set'}
+ </span>
+ </div>
+ <div className="flex items-center gap-0.5 pt-1.5 border-t border-border">
+ <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); onDuplicate(); }} disabled={isLoading}>
+ <Copy className="w-3 h-3 mr-1" />duplicate
+ </Button>
+ <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); onSetDefault(); }} disabled={isLoading || isDefault}>
+ <Star className="w-3 h-3 mr-1" />{isDefault ? "default" : "set default"}
+ </Button>
+ {!isDefault && (
+ <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2 text-destructive hover:text-destructive ml-auto" onClick={(e) => { e.stopPropagation(); onDelete(); }} disabled={isLoading}>
+ <Trash2 className="w-3 h-3" />
+ </Button>
+ )}
+ </div>
+ </div>
+ </Card>
+ );
+}
+
export const AIPresets = () => {
const { settings, updateSettings } = useSettings();
const [createPresetsDialog, setCreatePresentDialog] = useState(false);
@@ -1710,6 +1815,28 @@ export const AIPresets = () => {
const isEnterprise = useIsEnterpriseBuild();
const [piAvailable, setPiAvailable] = useState(false);
+ // Drag-and-drop sensors with activation distance to avoid conflicts with clicks
+ const sensors = useSensors(
+ useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
+ );
+
+ const handleDragEnd = useCallback(
+ (event: DragEndEvent) => {
+ const { active, over } = event;
+ if (!over || active.id === over.id) return;
+
+ const presets = settings.aiPresets;
+ const oldIndex = presets.findIndex((p) => p.id === active.id);
+ const newIndex = presets.findIndex((p) => p.id === over.id);
+ if (oldIndex === -1 || newIndex === -1) return;
+
+ const reordered = arrayMove(presets, oldIndex, newIndex);
+ updateSettings({ aiPresets: reordered });
+ },
+ [settings.aiPresets, updateSettings]
+ );
+
// Check Pi availability (installed at app startup by Rust background thread)
useEffect(() => {
const checkPi = async () => {
@@ -1921,74 +2048,32 @@ export const AIPresets = () => {
</Button>
</div>
- <div className="w-full grid grid-cols-1 md:grid-cols-2 gap-3">
- {settings.aiPresets.filter((preset) => !isEnterprise || preset.provider !== "pi").map((preset) => {
- const isDefault = preset.defaultPreset;
- const hasValidation = preset.provider && preset.model && preset.url;
-
- return (
- <Card
- key={preset.id}
- className={cn(
- "p-3 relative group transition-all hover:shadow-md border-border bg-card cursor-pointer",
- isDefault && "ring-2 ring-primary/20"
- )}
- onClick={() => {
- setSelectedPreset(preset);
- setIsDuplicating(false);
- setCreatePresentDialog(true);
- }}
- >
- <div className="space-y-2">
- <div className="flex justify-between items-center">
- <div className="flex items-center gap-2 flex-1 min-w-0">
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img
- src={providerImageSrc[preset.provider]}
- alt={`${preset.provider} logo`}
- className="w-6 h-6 opacity-80 rounded shrink-0"
- />
- <h3 className="text-sm font-semibold text-foreground truncate" title={preset.id}>
- {formatPresetName(preset.id)}
- </h3>
- {isDefault && (
- <Badge variant="default" className="text-[10px] px-1.5 py-0">
- default
- </Badge>
- )}
- {!hasValidation && (
- <AlertCircle className="h-3.5 w-3.5 text-destructive shrink-0" />
- )}
- </div>
- {hasValidation ? (
- <CheckCircle2 className="h-4 w-4 text-foreground/50 shrink-0" />
- ) : (
- <AlertCircle className="h-4 w-4 text-destructive shrink-0" />
- )}
- </div>
- <div className="flex items-center gap-1.5 text-xs text-muted-foreground">
- <span className="font-mono bg-muted px-1.5 py-0.5 rounded truncate max-w-[180px]" title={preset.model || 'Not set'}>
- {preset.model || 'Not set'}
- </span>
- </div>
- <div className="flex items-center gap-0.5 pt-1.5 border-t border-border">
- <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); duplicatePreset(preset.id); }} disabled={isLoading}>
- <Copy className="w-3 h-3 mr-1" />duplicate
- </Button>
- <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); setPresetToSetDefault(preset.id); }} disabled={isLoading || isDefault}>
- <Star className="w-3 h-3 mr-1" />{isDefault ? "default" : "set default"}
- </Button>
- {!isDefault && (
- <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2 text-destructive hover:text-destructive ml-auto" onClick={(e) => { e.stopPropagation(); setPresetToDelete(preset.id); }} disabled={isLoading}>
- <Trash2 className="w-3 h-3" />
- </Button>
- )}
- </div>
- </div>
- </Card>
- );
- })}
- </div>
+ <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
+ <SortableContext
+ items={settings.aiPresets.filter((preset) => !isEnterprise || preset.provider !== "pi").map((p) => p.id)}
+ strategy={rectSortingStrategy}
+ >
+ <div className="w-full grid grid-cols-1 md:grid-cols-2 gap-3">
+ {settings.aiPresets.filter((preset) => !isEnterprise || preset.provider !== "pi").map((preset) => (
+ <SortablePresetCard
+ key={preset.id}
+ preset={preset}
+ isDefault={preset.defaultPreset}
+ hasValidation={!!(preset.provider && preset.model && preset.url)}
+ onEdit={() => {
+ setSelectedPreset(preset);
+ setIsDuplicating(false);
+ setCreatePresentDialog(true);
+ }}
+ onDuplicate={() => duplicatePreset(preset.id)}
+ onSetDefault={() => setPresetToSetDefault(preset.id)}
+ onDelete={() => setPresetToDelete(preset.id)}
+ isLoading={isLoading}
+ />
+ ))}
+ </div>
+ </SortableContext>
+ </DndContext>
<AlertDialog
open={!!presetToDelete}
diff --git a/apps/screenpipe-app-tauri/package.json b/apps/screenpipe-app-tauri/package.json
index b45ef109c..a7ef39dd0 100644
--- a/apps/screenpipe-app-tauri/package.json
+++ b/apps/screenpipe-app-tauri/package.json
@@ -14,6 +14,9 @@
"clean": "rm -rf out && cargo clean && rm -rf src-tauri/{screenpipe-*,tesseract-*,ffmpeg*,openblas*,bun*,ollama*,ui_monitor*} node_modules"
},
"dependencies": {
+ "@dnd-kit/core": "^6.3.1",
+ "@dnd-kit/sortable": "^10.0.0",
+ "@dnd-kit/utilities": "^3.2.2",
"@patternfly/react-core": "^6.4.1",
"@patternfly/react-log-viewer": "^6.3.0",
"@radix-ui/react-accordion": "^1.2.12",