Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear the audio when a new entry is submitted #2566

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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