Skip to content

Commit

Permalink
[NewEntry] Allow submission with no gloss (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Nov 4, 2020
1 parent a436818 commit b3b87b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
35 changes: 23 additions & 12 deletions src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
}));
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
/>
<VernDialog
Expand Down Expand Up @@ -357,7 +365,10 @@ export default class NewEntry extends React.Component<
this.updateGlossField(newValue)
}
handleEnterAndTab={(e: React.KeyboardEvent) =>
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}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/types/word.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit b3b87b1

Please sign in to comment.