Skip to content

Commit

Permalink
Clear the audio when a new entry is submitted (#2566)
Browse files Browse the repository at this point in the history
* Clear the audio when a new entry is submitted

* Make props order consistant
  • Loading branch information
imnasnainaec authored Sep 11, 2023
1 parent 1dc49fb commit a532bbc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/DataEntry/DataEntryTable/NewEntry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface NewEntryProps {
vernacularLang: WritingSystem;
// Parent component handles new entry state:
addNewEntry: () => Promise<void>;
resetNewEntry: () => void;
updateWordWithNewGloss: (wordId: string) => Promise<void>;
newAudioUrls: string[];
addNewAudioUrl: (file: File) => void;
Expand Down Expand Up @@ -72,6 +73,7 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
vernacularLang,
// Parent component handles new entry state:
addNewEntry,
resetNewEntry,
updateWordWithNewGloss,
newAudioUrls,
addNewAudioUrl,
Expand Down Expand Up @@ -116,13 +118,10 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
);

const resetState = useCallback((): void => {
setNewGloss("");
setNewNote("");
setNewVern("");
resetNewEntry();
setVernOpen(false);
// May also need to reset newAudioUrls in the parent component.
focus(FocusTarget.Vernacular);
}, [focus, setNewGloss, setNewNote, setNewVern, setVernOpen]);
}, [focus, resetNewEntry, setVernOpen]);

/** Reset when tree opens, except for the first time it is open. */
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("NewEntry", () => {
vernacularLang={newWritingSystem()}
// Parent component handles new entry state:
addNewEntry={jest.fn()}
resetNewEntry={jest.fn()}
updateWordWithNewGloss={jest.fn()}
newAudioUrls={[]}
addNewAudioUrl={jest.fn()}
Expand Down
12 changes: 12 additions & 0 deletions src/components/DataEntry/DataEntryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@ export default function DataEntryTable(
});
};

/*** Clear all new entry state elements. */
const resetNewEntry = (): void => {
setState((prevState) => ({
...prevState,
newAudioUrls: [],
newGloss: "",
newNote: "",
newVern: "",
}));
};

/*** Add an audio file to newAudioUrls. */
const addNewAudioUrl = (file: File): void => {
setState((prevState) => {
Expand Down Expand Up @@ -893,6 +904,7 @@ export default function DataEntryTable(
vernacularLang={vernacularLang}
// Parent handles new entry state of child:
addNewEntry={addNewEntry}
resetNewEntry={resetNewEntry}
updateWordWithNewGloss={updateWordWithNewEntry}
newAudioUrls={state.newAudioUrls}
addNewAudioUrl={addNewAudioUrl}
Expand Down

0 comments on commit a532bbc

Please sign in to comment.