Skip to content

Commit bcdfe30

Browse files
committed
Fix timeline poll not removing deleted recordings (#331)
The pollForNewRecordings function had two bugs: 1. It returned early when polledSegments was empty, so deleting all recordings in a time range would never clear the timeline. 2. It only detected additions (addedSegs) and never removals, so any deleted recording would remain visible until a full page reload. Fix: compute removedSegs by diffing current IDs against polled IDs. When either additions or removals are detected, replace the displayed segments with the authoritative polled list (sorted). Show a toast notification for removals in the same style as the existing additions notification.
1 parent 4362552 commit bcdfe30

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

web/js/components/preact/timeline/TimelinePage.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,22 +944,34 @@ export function TimelinePage() {
944944
if (!response.ok) return;
945945
const data = await response.json();
946946
const polledSegments = data.segments || [];
947-
if (polledSegments.length === 0) return;
948947

949948
const currentSegs = timelineState.timelineSegments || [];
950949
const currentIds = new Set(currentSegs.map(s => String(s.id)));
950+
const polledIds = new Set(polledSegments.map(s => String(s.id)));
951951
const addedSegs = polledSegments.filter(s => !currentIds.has(String(s.id)));
952+
const removedSegs = currentSegs.filter(s => !polledIds.has(String(s.id)));
953+
954+
if (addedSegs.length === 0 && removedSegs.length === 0) return;
955+
956+
// Use polled segments as the authoritative list
957+
const updated = [...polledSegments].sort((a, b) => a.start_timestamp - b.start_timestamp);
958+
setSegments(updated);
959+
timelineState.setState({ timelineSegments: updated });
952960

953961
if (addedSegs.length > 0) {
954-
const merged = [...currentSegs, ...addedSegs].sort((a, b) => a.start_timestamp - b.start_timestamp);
955-
setSegments(merged);
956-
timelineState.setState({ timelineSegments: merged });
957962
showStatusMessage(
958963
`${addedSegs.length} new recording${addedSegs.length !== 1 ? 's' : ''} added to timeline`,
959964
'info',
960965
3000
961966
);
962967
}
968+
if (removedSegs.length > 0) {
969+
showStatusMessage(
970+
`${removedSegs.length} recording${removedSegs.length !== 1 ? 's' : ''} removed from timeline`,
971+
'info',
972+
3000
973+
);
974+
}
963975
} catch (err) {
964976
console.debug('Timeline poll error (suppressed):', err);
965977
}

0 commit comments

Comments
 (0)