capture: optimistic list update + SSE refresh on transcription complete

This commit is contained in:
2026-04-29 18:00:53 +00:00
parent 60728978e1
commit 43278686f7
2 changed files with 19 additions and 1 deletions
+18 -1
View File
@@ -111,9 +111,25 @@ export default function CapturePage() {
checkPending();
window.addEventListener('focus', retryQueue);
window.addEventListener('online', retryQueue);
// Listen for capture_saved SSE — refresh list when transcription completes
let es: EventSource | null = null;
function connectSSE() {
es = new EventSource(`${API_URL}/api/captures/events`);
es.onmessage = (e) => {
try {
const data = JSON.parse(e.data);
if (data.type === 'capture_saved') loadRecentCaptures();
} catch {}
};
es.onerror = () => { es?.close(); setTimeout(connectSSE, 10000); };
}
connectSSE();
return () => {
window.removeEventListener('focus', retryQueue);
window.removeEventListener('online', retryQueue);
es?.close();
};
}, []);
@@ -217,7 +233,8 @@ export default function CapturePage() {
setImagePreview(null);
setImageBlob(null);
imageBlobRef.current = null;
await loadRecentCaptures();
// Optimistic update — show immediately as processing
setRecentCaptures(prev => [{ name: `${new Date().toISOString().slice(0,16).replace('T','-').replace(':','-')}-voice ⏳` }, ...prev].slice(0, 4));
setTimeout(() => setMode('idle'), 3000);
return;
}
+1
View File
@@ -6,6 +6,7 @@ export function proxy(request: NextRequest) {
// Always allow these through
if (
pathname.startsWith('/api/captures') ||
pathname.startsWith('/api/') ||
pathname.startsWith('/login') ||
pathname.startsWith('/_next') ||