mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
fix(collab): note attachments added or removed on the phone show in the Files tab at once
On the phone, attaching a file to a note, detaching one or deleting a note with attachments left the trip's Files tab on the old list until a reload. The desktop panel fires the local collab-files-changed event that useTripWebSocket listens for, because the server leaves the writer's own socket out of its broadcast; the phone notes tab never fired it. The event now lives in the shared useCollabNotesData hook: uploadNoteFiles announces it once after a batch, and announceNoteFilesChanged is what both shells call after deleting a note or a note file. The desktop no longer fires it by hand after an upload. Red before the fix: tests/unit/mobile/trip/MCollabNotes.test.tsx FE-MOB-CNOTE-034 failed with "expected 0 to be 1" on the event count after detaching a file. FE-COLLAB-NOTESDATA-009 covers the hook. No existing assertions changed.
This commit is contained in:
@@ -16,6 +16,15 @@ export interface CollabNotesDataOptions {
|
||||
waitForTripId?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the trip's Files tab that note attachments changed. The server leaves the writer's
|
||||
* own socket out of its broadcast, so the tab that made the change has to say it itself;
|
||||
* useTripWebSocket listens and reloads the files.
|
||||
*/
|
||||
export function announceNoteFilesChanged(): void {
|
||||
window.dispatchEvent(new Event('collab-files-changed'));
|
||||
}
|
||||
|
||||
/**
|
||||
* The trip notes behind the desktop Collab panel and the phone's notes tab, each reading
|
||||
* the rows through its own note type: the list as the server has it, kept current by the
|
||||
@@ -76,7 +85,8 @@ export function useCollabNotesData<N extends { id: number } = CollabNoteData>({
|
||||
|
||||
/**
|
||||
* Uploads a saved note's attachments one by one; a file the server refuses is toasted
|
||||
* and the rest still go. `onFileError` sees each refusal before the toast.
|
||||
* and the rest still go. `onFileError` sees each refusal before the toast. Once the
|
||||
* batch is through, the Files tab is told to reload.
|
||||
*/
|
||||
const uploadNoteFiles = useCallback(
|
||||
async (noteId: number, files: File[], onFileError?: (err: unknown) => void) => {
|
||||
@@ -90,6 +100,7 @@ export function useCollabNotesData<N extends { id: number } = CollabNoteData>({
|
||||
toast.error(t('common.error'));
|
||||
}
|
||||
}
|
||||
if (files.length > 0) announceNoteFilesChanged();
|
||||
},
|
||||
[tripId, toast, t]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user