diff --git a/webui/src/App.tsx b/webui/src/App.tsx index bd83aba0..669e7238 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -66,6 +66,15 @@ const providers = [ { id: 'iflow', name: 'iFlow', color: 'from-teal-500 to-cyan-600' }, ] +const downloadBlob = (blob: Blob, filename: string) => { + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = filename; + a.click(); + URL.revokeObjectURL(url); +}; + export default function App() { const [status, setStatus] = useState(null); const [privateOAuth, setPrivateOAuth] = useState(false); @@ -110,6 +119,7 @@ export default function App() { const [modelMappings, setModelMappings] = useState([]); const [newMapping, setNewMapping] = useState({ from: '', to: '', provider: '' }); const [editingMapping, setEditingMapping] = useState(null); + const [editingMappingValues, setEditingMappingValues] = useState({ from: '', to: '', provider: '' }); const [mappingTestInput, setMappingTestInput] = useState(''); const [mappingTestResult, setMappingTestResult] = useState(''); @@ -486,12 +496,7 @@ export default function App() { throw new Error(msg); } const blob = await res.blob(); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = `proxypilot-session-${memorySession}.zip`; - a.click(); - URL.revokeObjectURL(url); + downloadBlob(blob, `proxypilot-session-${memorySession}.zip`); }; const exportAllMemory = async () => { @@ -504,12 +509,7 @@ export default function App() { throw new Error(msg); } const blob = await res.blob(); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = 'proxypilot-memory-all.zip'; - a.click(); - URL.revokeObjectURL(url); + downloadBlob(blob, 'proxypilot-memory-all.zip'); }; const deleteAllMemory = async () => { @@ -1235,8 +1235,8 @@ export default function App() { setEditingMappingValues(v => ({ ...v, from: e.target.value }))} /> @@ -1246,16 +1246,16 @@ export default function App() { setEditingMappingValues(v => ({ ...v, to: e.target.value }))} /> setEditingMappingValues(v => ({ ...v, provider: e.target.value }))} /> @@ -1265,14 +1265,8 @@ export default function App() { variant="ghost" className="h-7 w-7 p-0" onClick={() => { - const fromEl = document.getElementById(`edit-from-${index}`) as HTMLInputElement; - const toEl = document.getElementById(`edit-to-${index}`) as HTMLInputElement; - const providerEl = document.getElementById(`edit-provider-${index}`) as HTMLInputElement; - updateModelMapping(index, { - from: fromEl?.value || '', - to: toEl?.value || '', - provider: providerEl?.value || '', - }).catch((e) => showToast(String(e), 'error')); + updateModelMapping(index, editingMappingValues) + .catch((e) => showToast(String(e), 'error')); }} > @@ -1304,7 +1298,14 @@ export default function App() { size="sm" variant="ghost" className="h-7 w-7 p-0" - onClick={() => setEditingMapping(index)} + onClick={() => { + setEditingMapping(index); + setEditingMappingValues({ + from: mapping.from || '', + to: mapping.to || '', + provider: mapping.provider || '', + }); + }} >