capture: optimistic list update + SSE refresh on transcription complete
This commit is contained in:
+18
-1
@@ -111,9 +111,25 @@ export default function CapturePage() {
|
|||||||
checkPending();
|
checkPending();
|
||||||
window.addEventListener('focus', retryQueue);
|
window.addEventListener('focus', retryQueue);
|
||||||
window.addEventListener('online', 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 () => {
|
return () => {
|
||||||
window.removeEventListener('focus', retryQueue);
|
window.removeEventListener('focus', retryQueue);
|
||||||
window.removeEventListener('online', retryQueue);
|
window.removeEventListener('online', retryQueue);
|
||||||
|
es?.close();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -217,7 +233,8 @@ export default function CapturePage() {
|
|||||||
setImagePreview(null);
|
setImagePreview(null);
|
||||||
setImageBlob(null);
|
setImageBlob(null);
|
||||||
imageBlobRef.current = 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);
|
setTimeout(() => setMode('idle'), 3000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export function proxy(request: NextRequest) {
|
|||||||
|
|
||||||
// Always allow these through
|
// Always allow these through
|
||||||
if (
|
if (
|
||||||
|
pathname.startsWith('/api/captures') ||
|
||||||
pathname.startsWith('/api/') ||
|
pathname.startsWith('/api/') ||
|
||||||
pathname.startsWith('/login') ||
|
pathname.startsWith('/login') ||
|
||||||
pathname.startsWith('/_next') ||
|
pathname.startsWith('/_next') ||
|
||||||
|
|||||||
Reference in New Issue
Block a user