Spaces:
Sleeping
Sleeping
NeonClary commited on
Commit ·
1abd9d5
1
Parent(s): 4fd9d4c
Simplify model selection: single-click to reuse, replace oldest on overflow
Browse files
frontend/src/components/LLMSelector.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
-
import React, { useCallback,
|
| 2 |
import { Cloud, ChevronDown, ChevronRight } from 'lucide-react';
|
| 3 |
|
| 4 |
export default function LLMSelector({ providers, neonModels, selections, onSelectionsChange }) {
|
| 5 |
-
const lastClickRef = useRef({ id: null, time: 0 });
|
| 6 |
const [openGroups, setOpenGroups] = useState({});
|
| 7 |
|
| 8 |
const toggleGroup = (key) => {
|
|
@@ -10,34 +9,17 @@ export default function LLMSelector({ providers, neonModels, selections, onSelec
|
|
| 10 |
};
|
| 11 |
|
| 12 |
const handleClick = useCallback((modelId) => {
|
| 13 |
-
const now = Date.now();
|
| 14 |
-
const last = lastClickRef.current;
|
| 15 |
-
const isDoubleClick = last.id === modelId && (now - last.time) < 400;
|
| 16 |
-
lastClickRef.current = { id: modelId, time: now };
|
| 17 |
-
|
| 18 |
onSelectionsChange(prev => {
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
const idx = prev.indexOf(modelId);
|
| 30 |
-
if (idx !== -1) {
|
| 31 |
-
if (prev.length === 2 && prev[0] === prev[1]) {
|
| 32 |
-
return [];
|
| 33 |
-
}
|
| 34 |
-
return prev.filter((_, i) => i !== idx);
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
if (prev.length < 2) {
|
| 38 |
-
return [...prev, modelId];
|
| 39 |
-
}
|
| 40 |
-
return [prev[0], modelId];
|
| 41 |
});
|
| 42 |
}, [onSelectionsChange]);
|
| 43 |
|
|
|
|
| 1 |
+
import React, { useCallback, useState } from 'react';
|
| 2 |
import { Cloud, ChevronDown, ChevronRight } from 'lucide-react';
|
| 3 |
|
| 4 |
export default function LLMSelector({ providers, neonModels, selections, onSelectionsChange }) {
|
|
|
|
| 5 |
const [openGroups, setOpenGroups] = useState({});
|
| 6 |
|
| 7 |
const toggleGroup = (key) => {
|
|
|
|
| 9 |
};
|
| 10 |
|
| 11 |
const handleClick = useCallback((modelId) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
onSelectionsChange(prev => {
|
| 13 |
+
const isSelected = prev.includes(modelId);
|
| 14 |
+
const isBoth = prev.length === 2 && prev[0] === modelId && prev[1] === modelId;
|
| 15 |
+
|
| 16 |
+
if (isBoth) return [];
|
| 17 |
+
|
| 18 |
+
if (isSelected) return [modelId, modelId];
|
| 19 |
+
|
| 20 |
+
if (prev.length < 2) return [...prev, modelId];
|
| 21 |
+
|
| 22 |
+
return [prev[1], modelId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
});
|
| 24 |
}, [onSelectionsChange]);
|
| 25 |
|