Skip to content

Commit 23fc55b

Browse files
authored
Merge pull request #36 from mbsantiago/fix/sound_event_notes
Fixed note taking in sound events when annotating
2 parents 6d7f043 + 11261f4 commit 23fc55b

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

front/src/app/components/sound_event_annotations/SelectedSoundEventAnnotation.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export default function SelectedSoundEventAnnotation({
1515
}) {
1616
const tagColorFn = useStore((state) => state.getTagColor);
1717

18-
const { data, addTag, removeTag } = useSoundEventAnnotation({
19-
uuid: soundEventAnnotation.uuid,
20-
soundEventAnnotation,
21-
});
18+
const { data, addTag, removeTag, addNote, updateNote, removeNote } =
19+
useSoundEventAnnotation({
20+
uuid: soundEventAnnotation.uuid,
21+
soundEventAnnotation,
22+
});
2223

2324
return (
2425
<SelectedSoundEventAnnotationBase
@@ -27,6 +28,11 @@ export default function SelectedSoundEventAnnotation({
2728
onDeleteSoundEventAnnotationTag={removeTag.mutate}
2829
TagSearchBar={ProjectTagSearch}
2930
tagColorFn={tagColorFn}
31+
onCreateSoundEventAnnotationNote={addNote.mutate}
32+
onUpdateSoundEventAnnotationNote={(note, data) =>
33+
updateNote.mutate({ note, data })
34+
}
35+
onDeleteSoundEventAnnotationNote={removeNote.mutate}
3036
/>
3137
);
3238
}

front/src/app/hooks/api/useSoundEventAnnotation.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { useQuery as useReactQuery } from "@tanstack/react-query";
1+
import {
2+
useMutation as useReactMutation,
3+
useQuery as useReactQuery,
4+
} from "@tanstack/react-query";
25
import type { AxiosError } from "axios";
36
import { useCallback, useMemo } from "react";
47

@@ -8,7 +11,9 @@ import useObject from "@/lib/hooks/utils/useObject";
811

912
import type {
1013
ClipAnnotation,
14+
Note,
1115
NoteCreate,
16+
NoteUpdate,
1217
Recording,
1318
SoundEventAnnotation,
1419
Tag,
@@ -162,13 +167,27 @@ export default function useSoundEventAnnotation({
162167
onSuccess: handleAddNote,
163168
});
164169

170+
const updateNote = useReactMutation({
171+
mutationFn: ({ note, data }: { note: Note; data: NoteUpdate }) =>
172+
api.notes.update(note, data),
173+
onSuccess: () => {
174+
query.refetch();
175+
},
176+
});
177+
178+
const removeNote = useMutation({
179+
mutationFn: api.soundEventAnnotations.removeNote,
180+
});
181+
165182
return {
166183
...query,
167184
update,
168185
delete: delete_,
169186
addTag,
170187
removeTag,
171188
addNote,
189+
updateNote,
190+
removeNote,
172191
recording: recordingQuery,
173192
} as const;
174193
}

front/src/lib/components/notes/NotesPanel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Feed from "@/lib/components/notes/Feed";
44
import Card from "@/lib/components/ui/Card";
55
import { H3 } from "@/lib/components/ui/Headings";
66

7-
import type { Note, NoteCreate, User } from "@/lib/types";
7+
import type { Note, NoteCreate, NoteUpdate, User } from "@/lib/types";
88

99
export default function NotesPanel({
1010
notes,
@@ -19,7 +19,7 @@ export default function NotesPanel({
1919
notes: Note[];
2020
currentUser?: User;
2121
onCreateNote?: (note: NoteCreate) => void;
22-
onUpdateNote?: (note: Note, data: Partial<Note>) => void;
22+
onUpdateNote?: (note: Note, data: NoteUpdate) => void;
2323
onDeleteNote?: (note: Note) => void;
2424
EmptyNotes?: JSX.Element;
2525
}) {

front/src/lib/components/sound_event_annotations/SelectedSoundEventAnnotation.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ import SoundEventAnnotationNotes from "@/lib/components/sound_event_annotations/
33
import SoundEventAnnotationTags from "@/lib/components/sound_event_annotations/SoundEventAnnotationTags";
44
import Card from "@/lib/components/ui/Card";
55

6-
import type { NoteCreate, SoundEventAnnotation, Tag } from "@/lib/types";
6+
import type {
7+
Note,
8+
NoteCreate,
9+
NoteUpdate,
10+
SoundEventAnnotation,
11+
Tag,
12+
} from "@/lib/types";
713

814
export default function SelectedSoundEventAnnotation({
915
soundEventAnnotation,
1016
onAddSoundEventAnnotationTag,
1117
onDeleteSoundEventAnnotationTag,
1218
onCreateSoundEventAnnotationNote,
19+
onUpdateSoundEventAnnotationNote,
20+
onDeleteSoundEventAnnotationNote,
1321
onCreateTag,
1422
...props
1523
}: {
1624
soundEventAnnotation: SoundEventAnnotation;
1725
onAddSoundEventAnnotationTag?: (tag: Tag) => void;
1826
onDeleteSoundEventAnnotationTag?: (tag: Tag) => void;
1927
onCreateSoundEventAnnotationNote?: (note: NoteCreate) => void;
28+
onUpdateSoundEventAnnotationNote?: (note: Note, data: NoteUpdate) => void;
29+
onDeleteSoundEventAnnotationNote?: (note: Note) => void;
2030
onCreateTag?: (tag: Tag) => void;
2131
} & Omit<
2232
Parameters<typeof SoundEventAnnotationTags>[0],
@@ -29,7 +39,7 @@ export default function SelectedSoundEventAnnotation({
2939
soundEventAnnotation={soundEventAnnotation}
3040
/>
3141
</Card>
32-
<Card>
42+
<Card className="grow">
3343
<SoundEventAnnotationTags
3444
soundEventAnnotation={soundEventAnnotation}
3545
onAddTag={onAddSoundEventAnnotationTag}
@@ -41,6 +51,8 @@ export default function SelectedSoundEventAnnotation({
4151
<SoundEventAnnotationNotes
4252
soundEventAnnotation={soundEventAnnotation}
4353
onCreateNote={onCreateSoundEventAnnotationNote}
54+
onDeleteNote={onDeleteSoundEventAnnotationNote}
55+
onUpdateNote={onUpdateSoundEventAnnotationNote}
4456
/>
4557
</div>
4658
);

0 commit comments

Comments
 (0)