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

[NewEntry] Allow submission with no gloss #796

Merged
merged 3 commits into from
Nov 4, 2020
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
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