Skip to content

Commit

Permalink
Merge pull request #36 from mbsantiago/fix/sound_event_notes
Browse files Browse the repository at this point in the history
Fixed note taking in sound events when annotating
  • Loading branch information
mbsantiago authored Sep 30, 2024
2 parents 6d7f043 + 11261f4 commit 23fc55b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export default function SelectedSoundEventAnnotation({
}) {
const tagColorFn = useStore((state) => state.getTagColor);

const { data, addTag, removeTag } = useSoundEventAnnotation({
uuid: soundEventAnnotation.uuid,
soundEventAnnotation,
});
const { data, addTag, removeTag, addNote, updateNote, removeNote } =
useSoundEventAnnotation({
uuid: soundEventAnnotation.uuid,
soundEventAnnotation,
});

return (
<SelectedSoundEventAnnotationBase
Expand All @@ -27,6 +28,11 @@ export default function SelectedSoundEventAnnotation({
onDeleteSoundEventAnnotationTag={removeTag.mutate}
TagSearchBar={ProjectTagSearch}
tagColorFn={tagColorFn}
onCreateSoundEventAnnotationNote={addNote.mutate}
onUpdateSoundEventAnnotationNote={(note, data) =>
updateNote.mutate({ note, data })
}
onDeleteSoundEventAnnotationNote={removeNote.mutate}
/>
);
}
21 changes: 20 additions & 1 deletion front/src/app/hooks/api/useSoundEventAnnotation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useQuery as useReactQuery } from "@tanstack/react-query";
import {
useMutation as useReactMutation,
useQuery as useReactQuery,
} from "@tanstack/react-query";
import type { AxiosError } from "axios";
import { useCallback, useMemo } from "react";

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

import type {
ClipAnnotation,
Note,
NoteCreate,
NoteUpdate,
Recording,
SoundEventAnnotation,
Tag,
Expand Down Expand Up @@ -162,13 +167,27 @@ export default function useSoundEventAnnotation({
onSuccess: handleAddNote,
});

const updateNote = useReactMutation({
mutationFn: ({ note, data }: { note: Note; data: NoteUpdate }) =>
api.notes.update(note, data),
onSuccess: () => {
query.refetch();
},
});

const removeNote = useMutation({
mutationFn: api.soundEventAnnotations.removeNote,
});

return {
...query,
update,
delete: delete_,
addTag,
removeTag,
addNote,
updateNote,
removeNote,
recording: recordingQuery,
} as const;
}
4 changes: 2 additions & 2 deletions front/src/lib/components/notes/NotesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Feed from "@/lib/components/notes/Feed";
import Card from "@/lib/components/ui/Card";
import { H3 } from "@/lib/components/ui/Headings";

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

export default function NotesPanel({
notes,
Expand All @@ -19,7 +19,7 @@ export default function NotesPanel({
notes: Note[];
currentUser?: User;
onCreateNote?: (note: NoteCreate) => void;
onUpdateNote?: (note: Note, data: Partial<Note>) => void;
onUpdateNote?: (note: Note, data: NoteUpdate) => void;
onDeleteNote?: (note: Note) => void;
EmptyNotes?: JSX.Element;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ import SoundEventAnnotationNotes from "@/lib/components/sound_event_annotations/
import SoundEventAnnotationTags from "@/lib/components/sound_event_annotations/SoundEventAnnotationTags";
import Card from "@/lib/components/ui/Card";

import type { NoteCreate, SoundEventAnnotation, Tag } from "@/lib/types";
import type {
Note,
NoteCreate,
NoteUpdate,
SoundEventAnnotation,
Tag,
} from "@/lib/types";

export default function SelectedSoundEventAnnotation({
soundEventAnnotation,
onAddSoundEventAnnotationTag,
onDeleteSoundEventAnnotationTag,
onCreateSoundEventAnnotationNote,
onUpdateSoundEventAnnotationNote,
onDeleteSoundEventAnnotationNote,
onCreateTag,
...props
}: {
soundEventAnnotation: SoundEventAnnotation;
onAddSoundEventAnnotationTag?: (tag: Tag) => void;
onDeleteSoundEventAnnotationTag?: (tag: Tag) => void;
onCreateSoundEventAnnotationNote?: (note: NoteCreate) => void;
onUpdateSoundEventAnnotationNote?: (note: Note, data: NoteUpdate) => void;
onDeleteSoundEventAnnotationNote?: (note: Note) => void;
onCreateTag?: (tag: Tag) => void;
} & Omit<
Parameters<typeof SoundEventAnnotationTags>[0],
Expand All @@ -29,7 +39,7 @@ export default function SelectedSoundEventAnnotation({
soundEventAnnotation={soundEventAnnotation}
/>
</Card>
<Card>
<Card className="grow">
<SoundEventAnnotationTags
soundEventAnnotation={soundEventAnnotation}
onAddTag={onAddSoundEventAnnotationTag}
Expand All @@ -41,6 +51,8 @@ export default function SelectedSoundEventAnnotation({
<SoundEventAnnotationNotes
soundEventAnnotation={soundEventAnnotation}
onCreateNote={onCreateSoundEventAnnotationNote}
onDeleteNote={onDeleteSoundEventAnnotationNote}
onUpdateNote={onUpdateSoundEventAnnotationNote}
/>
</div>
);
Expand Down

0 comments on commit 23fc55b

Please sign in to comment.