diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx index 9674cc845d..1ffb6a2804 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx @@ -6,7 +6,7 @@ import DupFinder, { DefaultParams, } from "../../../../goals/MergeDupGoal/DuplicateFinder/DuplicateFinder"; import theme from "../../../../types/theme"; -import { SemanticDomain, Word } from "../../../../types/word"; +import { SemanticDomain, Sense, Word } from "../../../../types/word"; import Pronunciations from "../../../Pronunciations/PronunciationsComponent"; import Recorder from "../../../Pronunciations/Recorder"; import GlossWithSuggestions from "../GlossWithSuggestions/GlossWithSuggestions"; @@ -99,12 +99,7 @@ export default class NewEntry extends React.Component< this.setState((prevState, props) => ({ newEntry: { ...prevState.newEntry, - senses: [ - { - glosses: [{ language: props.analysisLang, def: newValue }], - semanticDomains: [props.semanticDomain], - }, - ], + senses: [new Sense(newValue, props.analysisLang, props.semanticDomain)], }, activeGloss: newValue, })); @@ -161,7 +156,15 @@ export default class NewEntry extends React.Component< } addNewWordAndReset() { - this.props.addNewWord(this.state.newEntry, this.state.audioFileURLs); + const newEntry: Word = this.state.newEntry.senses.length + ? this.state.newEntry + : { + ...this.state.newEntry, + senses: [ + new Sense("", this.props.analysisLang, this.props.semanticDomain), + ], + }; + this.props.addNewWord(newEntry, this.state.audioFileURLs); this.resetState(); } @@ -193,10 +196,12 @@ export default class NewEntry extends React.Component< } } - handleEnterAndTab(e: React.KeyboardEvent) { + handleEnter(e: React.KeyboardEvent, checkGloss: boolean) { if (!this.state.vernOpen && e.key === "Enter") { + // The user can never submit a new entry without a vernacular if (this.state.newEntry.vernacular) { - if (this.state.activeGloss) { + // The user can conditionally submit a new entry without a gloss + if (this.state.activeGloss || !checkGloss) { this.addOrUpdateWord(); this.focusVernInput(); } else { @@ -312,7 +317,10 @@ export default class NewEntry extends React.Component< }} suggestedVerns={this.state.suggestedVerns} handleEnterAndTab={(e: React.KeyboardEvent) => - this.handleEnterAndTab(e) + // To prevent unintentional no-gloss submissions: + // If enter pressed from the vern field, + // check whether gloss is empty + this.handleEnter(e, true) } /> - this.handleEnterAndTab(e) + // To allow intentional no-gloss submissions: + // If enter pressed from the gloss field, + // don't check whether gloss is empty + this.handleEnter(e, false) } analysisLang={this.props.analysisLang} /> diff --git a/src/types/word.tsx b/src/types/word.tsx index 2ca51db946..4751571c4d 100644 --- a/src/types/word.tsx +++ b/src/types/word.tsx @@ -22,8 +22,11 @@ export class Sense { semanticDomains: SemanticDomain[] = []; accessibility?: State; - constructor(gloss: string, language?: string) { - this.glosses = [{ def: gloss, language: language ? language : "" }]; + constructor(gloss: string, language?: string, semDom?: SemanticDomain) { + this.glosses = [{ def: gloss, language: language ?? "" }]; + if (semDom) { + this.semanticDomains.push(semDom); + } } }