-
+
+
- {this.state.word.name}
+ {this.state.name}
{this.showPronunciation()}
@@ -66,7 +93,13 @@ export class Word extends React.Component {
{this.showSimpleDefinition()}
{this.showLongDefinition()}
+
+ {this.showManagementArea()}
);
}
+}
+
+Word.defaultProps = {
+ isEditing: false
}
\ No newline at end of file
diff --git a/src/components/WordForm.jsx b/src/components/WordForm.jsx
deleted file mode 100644
index b76a737..0000000
--- a/src/components/WordForm.jsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import React from 'react';
-
-import {Input} from './Input';
-import {TextArea} from './TextArea';
-import {keyCodeFor} from '../js/helpers';
-
-export class WordForm extends React.Component {
- constructor(props) {
- super(props);
-
- this.state = {
- errorMessage: '',
- updateConflictMessage: ''
- };
-
- this.isNewWord = (this.props.action == 'new');
- }
-
- submitWordOnCtrlEnter() {
- var keyCode = (event.which ? event.which : event.keyCode);
-
- //Windows and Linux Chrome accept ctrl+enter as keyCode 10.
- if (keyCode === keyCodeFor('ctrlEnter') || (keyCode == keyCodeFor('enter') && event.ctrlKey)) {
- event.preventDefault();
-
- this.handleSubmit();
- }
- }
-
- handleSubmit() {
- if (this.validate()) {
-
- }
- }
-
- validate() {
-
- return true;
- }
-
- confirmArea() {
- if (this.isNewWord) {
- return
;
- }
- return (
-
-
-
-
- );
- }
-
- clearForm() {
- this.props.children.forEach((field) => {
- field.state.value = '';
- })
- }
-
- render() {
- return (
-
- );
- }
-}
\ No newline at end of file
diff --git a/src/index.jsx b/src/index.jsx
index d6944b5..13e3c6f 100644
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -8,39 +8,42 @@ import {Header} from './components/Header';
import {NewWordForm} from './components/NewWordForm';
import {Button} from './components/Button';
import {Dictionary} from './components/Dictionary';
+import {Word} from './components/Word';
+
+import {dynamicSort} from './js/helpers';
class Lexiconga extends React.Component {
constructor(props) {
super(props);
+ this.showConsoleMessages = this.props.showConsoleMessages || false;
+
this.state = {
scroll: {
x: 0,
y: 0
},
- currentDictionary: {
+ details: {
name: "New",
description: "A new dictionary.",
createdBy: 'Someone',
- words: [],
- settings: {
- allowDuplicates: false,
- caseSensitive: false,
- partsOfSpeech: "Noun,Adjective,Verb,Adverb,Preposition,Pronoun,Conjunction",
- sortByEquivalent: false,
- isComplete: false,
- isPublic: false
- },
nextWordId: 1,
externalID: 0
- }
+ },
+ words: [],
+ settings: {
+ allowDuplicates: false,
+ caseSensitive: false,
+ partsOfSpeech: "Noun,Adjective,Verb,Adverb,Preposition,Pronoun,Conjunction",
+ sortByEquivalent: false,
+ isComplete: false,
+ isPublic: false
+ },
};
this.defaultDictionaryJSON = JSON.stringify(this.state.dictionaryDetails); //Saves a stringifyed default dictionary.
this.previousDictionary = {};
-
- // this.addTestWord();
}
changeDictionaryName() {
@@ -54,18 +57,83 @@ class Lexiconga extends React.Component {
})
}
+ addWord(wordObject) {
+ let newWord = {
+ name: wordObject.name || 'errorWord',
+ pronunciation: wordObject.pronunciation || '',
+ partOfSpeech: wordObject.partOfSpeech || '',
+ simpleDefinition: wordObject.simpleDefinition || '',
+ longDefinition: wordObject.longDefinition || '',
+ wordId: this.state.details.nextWordId
+ }
+
+ let sortMethod;
+ if (this.state.settings.sortByEquivalent) {
+ sortMethod = ['simpleDefinition', 'partOfSpeech'];
+ } else {
+ sortMethod = ['name', 'partOfSpeech'];
+ }
+
+ let updatedWords = this.state.words.concat([newWord]);
+ updatedWords.sort(dynamicSort(sortMethod));
+
+ let updatedDetails = this.state.details;
+ updatedDetails.nextwordid += 1;
+
+ this.setState({
+ words: updatedWords,
+ details: updatedDetails
+ }, () => {
+ if (this.showConsoleMessages) {
+ console.log('New word ' + newWord.name + ' added successfully');
+ }
+ });
+ }
+
+ updateWord(index, wordObject) {
+ let updatedWords = this.state.words;
+ updatedWords[index].name = wordObject.name;
+ updatedWords[index].pronunciation = wordObject.pronunciation;
+ updatedWords[index].partOfSpeech = wordObject.partOfSpeech;
+ updatedWords[index].simpledefinition = wordObject.simpledefinition;
+ updatedWords[index].longDefinition = wordObject.longDefinition;
+ this.setState({words: updatedWords});
+ }
+
+ showWords() {
+ let words = this.state.words.map((word, index) => {
+ return
this.updateWord(index, wordObject)} />;
+ });
+
+ return {words}
;
+ }
+
render() {
return (
-
+
this.addWord(wordObject)} parent={this} />
);
}
}
-ReactDOM.render(, document.getElementById('site'));
\ No newline at end of file
+ReactDOM.render(, document.getElementById('site'));
\ No newline at end of file
diff --git a/src/js/dependencies/removeDiacritics.js b/src/js/dependencies/removeDiacritics.js
index 981724e..74e7ba6 100644
--- a/src/js/dependencies/removeDiacritics.js
+++ b/src/js/dependencies/removeDiacritics.js
@@ -14,7 +14,7 @@
limitations under the License.
*/
// "what?" version ... http://jsperf.com/diacritics/12
-function removeDiacritics(str) {
+export function removeDiacritics(str) {
var defaultDiacriticsRemovalap = [
{'base':'A', 'letters':'\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F'},
{'base':'AA','letters':'\uA732'},
@@ -115,6 +115,4 @@ function removeDiacritics(str) {
return str.replace(/[^\u0000-\u007E]/g, function(a){
return diacriticsMap[a] || a;
});
-}
-
-modules.export = removeDiacritics;
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/js/helpers.js b/src/js/helpers.js
index 8660917..79d48de 100644
--- a/src/js/helpers.js
+++ b/src/js/helpers.js
@@ -1,3 +1,5 @@
+import {removeDiacritics} from './dependencies/removeDiacritics';
+
// function ready(fn) {
// if (document.readyState != 'loading'){
// fn();