From 80fdea0d4c70b8bd33740e1b32ca8c0c70be4289 Mon Sep 17 00:00:00 2001
From: Robbie Antenesse
Date: Thu, 20 Apr 2017 13:02:12 -0600
Subject: [PATCH] Start adding words to db via search form
---
src/components/management/SearchBox.jsx | 4 +-
src/components/management/WordForm.jsx | 134 ++++++++++++++++++++++--
src/managers/DictionaryData.js | 10 ++
src/managers/IDManager.js | 17 +++
src/managers/Word.js | 45 ++++++++
src/managers/WordDatabase.js | 6 +-
6 files changed, 207 insertions(+), 9 deletions(-)
create mode 100644 src/managers/IDManager.js
create mode 100644 src/managers/Word.js
diff --git a/src/components/management/SearchBox.jsx b/src/components/management/SearchBox.jsx
index 115a541..0611a24 100644
--- a/src/components/management/SearchBox.jsx
+++ b/src/components/management/SearchBox.jsx
@@ -47,7 +47,7 @@ export class SearchBox extends Component {
diff --git a/src/components/management/WordForm.jsx b/src/components/management/WordForm.jsx
index 11a6f0b..65e3cb3 100644
--- a/src/components/management/WordForm.jsx
+++ b/src/components/management/WordForm.jsx
@@ -1,9 +1,81 @@
import Inferno from 'inferno';
import Component from 'inferno-component';
+import {Word} from '../../managers/Word';
+
export class WordForm extends Component {
constructor (props) {
super(props);
+
+ this.state = {
+ wordName: this.props.name || ''
+ , wordPronunciation: this.props.pronunciation || ''
+ , wordPartOfSpeech: this.props.partOfSpeech || ''
+ , wordDefinition: this.props.definition || ''
+ , wordDetails: this.props.details || ''
+
+ , nameIsValid: true
+ , pronunciationIsValid: true
+ , partOfSpeechIsValid: true
+ , definitionIsValid: true
+ , detailsIsValid: true
+ }
+ }
+
+ isValidWord () {
+ let nameIsValid = true
+ , definitionIsValid = true
+ , detailsIsValid = true;
+
+ if (this.state.wordName === '') {
+ nameIsValid = false;
+ }
+
+ if (this.state.wordPartOfSpeech === '') {
+ // popup(?) confirming no part of speech.
+ }
+
+ if (this.state.wordDefinition === ''
+ && this.state.wordDetails === '') {
+ definitionIsValid = false;
+ detailsIsValid = false;
+ }
+
+ this.setState({
+ nameIsValid
+ , definitionIsValid
+ , detailsIsValid
+ });
+
+ return nameIsValid == true && definitionIsValid == true && detailsIsValid == true;
+ }
+
+ createWord () {
+ const word = new Word({
+ name: this.state.wordName
+ , pronunciation: this.state.wordPronunciation
+ , partOfSpeech: this.state.wordPartOfSpeech
+ , definition: this.state.wordDefinition
+ , details: this.state.wordDetails
+ });
+
+
+ if (this.isValidWord()) {
+ word.create()
+ .then(() => {
+ this.clearForm();
+ });
+ }
+ }
+
+ clearForm () {
+ this.setState({
+ wordName: ''
+ , wordPronunciation: ''
+ , wordPartOfSpeech: ''
+ , wordDefinition: ''
+ , wordDetails: ''
+ });
}
render () {
@@ -12,14 +84,27 @@ export class WordForm extends Component {
@@ -27,8 +112,11 @@ export class WordForm extends Component {
-