mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-06-21 08:36:42 +02:00
Move default stuff to a Constants.js file; Use stored user data for IPA pronunciation
This commit is contained in:
parent
c496bd77c0
commit
3ed0ba0e72
8 changed files with 99 additions and 99 deletions
52
src/Constants.js
Normal file
52
src/Constants.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { timestampInSeconds } from './Helpers';
|
||||
|
||||
export const DEFAULT_USER_DATA = {
|
||||
email: '',
|
||||
username: '',
|
||||
publicName: '',
|
||||
allowEmails: true,
|
||||
useIPAPronunciation: true,
|
||||
itemsPerPage: 30,
|
||||
};
|
||||
|
||||
export const DEFAULT_DICTIONARY = {
|
||||
name: 'New',
|
||||
specification: 'Dictionary',
|
||||
description: 'A new dictionary.',
|
||||
partsOfSpeech: ['Noun', 'Adjective', 'Verb'],
|
||||
alphabeticalOrder: [],
|
||||
details: {
|
||||
phonology: {
|
||||
consonants: [],
|
||||
vowels: [],
|
||||
blends: [],
|
||||
phonotactics: {
|
||||
onset: [],
|
||||
nucleus: [],
|
||||
coda: [],
|
||||
exceptions: '',
|
||||
},
|
||||
},
|
||||
orthography: {
|
||||
notes: '',
|
||||
},
|
||||
grammar: {
|
||||
notes: '',
|
||||
},
|
||||
// custom: [
|
||||
// // {
|
||||
// // name: 'Example Tab',
|
||||
// // content: `This is an _example_ tab to show how **tabs** work with [Markdown](${ MARKDOWN_LINK })!`,
|
||||
// // }
|
||||
// ],
|
||||
},
|
||||
settings: {
|
||||
allowDuplicates: false,
|
||||
caseSensitive: false,
|
||||
sortByDefinition: false,
|
||||
isComplete: false,
|
||||
isPublic: false,
|
||||
},
|
||||
lastUpdated: null,
|
||||
createdOn: timestampInSeconds(),
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
import Inferno from 'inferno';
|
||||
import { Component } from 'inferno';
|
||||
import PropTypes from 'prop-types';
|
||||
import store from 'store';
|
||||
|
||||
import { LeftColumn } from './structure/LeftColumn';
|
||||
import { RightColumn } from './structure/RightColumn';
|
||||
|
@ -9,6 +10,7 @@ import { Pagination } from './structure/Pagination';
|
|||
import { WordForm } from './management/WordForm';
|
||||
import { DictionaryDetails } from './display/DictionaryDetails';
|
||||
import { WordsList } from './display/WordsList';
|
||||
import { DEFAULT_USER_DATA } from '../Constants';
|
||||
|
||||
export class MainDisplay extends Component {
|
||||
constructor (props) {
|
||||
|
@ -21,8 +23,6 @@ export class MainDisplay extends Component {
|
|||
wordsAreFiltered: PropTypes.bool,
|
||||
wordsInCurrentList: PropTypes.number,
|
||||
currentPage: PropTypes.number,
|
||||
itemsPerPage: PropTypes.number,
|
||||
useIpaPronunciationField: PropTypes.bool,
|
||||
stats: PropTypes.object.isRequired,
|
||||
setPage: PropTypes.func.isRequired,
|
||||
updateDisplay: PropTypes.func.isRequired,
|
||||
|
@ -56,6 +56,8 @@ export class MainDisplay extends Component {
|
|||
}
|
||||
|
||||
render () {
|
||||
const userData = store.get('LexicongaUserData');
|
||||
const itemsPerPage = userData ? userData.itemsPerPage : DEFAULT_USER_DATA.itemsPerPage;
|
||||
const {
|
||||
dictionaryInfo,
|
||||
isLoadingWords,
|
||||
|
@ -63,7 +65,6 @@ export class MainDisplay extends Component {
|
|||
wordsAreFiltered,
|
||||
wordsInCurrentList,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
useIpaPronunciationField,
|
||||
stats,
|
||||
setPage,
|
||||
|
@ -86,7 +87,6 @@ export class MainDisplay extends Component {
|
|||
closeWordForm={ this.closeWordForm.bind(this) }
|
||||
>
|
||||
<WordForm
|
||||
useIpaField={ useIpaPronunciationField }
|
||||
updateDisplay={ updateDisplay }
|
||||
/>
|
||||
</LeftColumn>
|
||||
|
@ -124,7 +124,6 @@ export class MainDisplay extends Component {
|
|||
isLoadingWords={ isLoadingWords }
|
||||
words={ wordsToDisplay }
|
||||
adsEveryXWords={ 10 }
|
||||
useIpaFieldOnEdit={ useIpaPronunciationField }
|
||||
updateDisplay={ updateDisplay } />
|
||||
|
||||
<Pagination
|
||||
|
|
|
@ -17,7 +17,6 @@ export class WordDisplay extends Component {
|
|||
|
||||
PropTypes.checkPropTypes({
|
||||
word: PropTypes.object.isRequired,
|
||||
useIpaFieldOnEdit: PropTypes.bool,
|
||||
updateDisplay: PropTypes.func.isRequired,
|
||||
}, props, 'prop', 'WordDisplay');
|
||||
|
||||
|
@ -66,13 +65,12 @@ export class WordDisplay extends Component {
|
|||
|
||||
render () {
|
||||
const { menuIsOpen, isEditing } = this.state;
|
||||
const { word, useIpaFieldOnEdit, updateDisplay } = this.props;
|
||||
const { word, updateDisplay } = this.props;
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<WordForm
|
||||
word={word}
|
||||
useIpaField={ useIpaFieldOnEdit }
|
||||
updateDisplay={updateDisplay}
|
||||
callback={() => {
|
||||
this.setState({
|
||||
|
|
|
@ -16,7 +16,6 @@ export class WordsList extends Component {
|
|||
isLoadingWords: PropTypes.bool,
|
||||
adsEveryXWords: PropTypes.number,
|
||||
words: PropTypes.array,
|
||||
useIpaFieldOnEdit: PropTypes.bool,
|
||||
updateDisplay: PropTypes.func.isRequired,
|
||||
}, props, 'prop', 'WordList');
|
||||
}
|
||||
|
@ -42,7 +41,6 @@ export class WordsList extends Component {
|
|||
}
|
||||
|
||||
<WordDisplay word={ word }
|
||||
useIpaFieldOnEdit={ this.props.useIpaFieldOnEdit }
|
||||
updateDisplay={ this.props.updateDisplay } />
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -8,16 +8,9 @@ import { Modal } from '../../structure/Modal';
|
|||
import { LoginForm } from './LoginForm';
|
||||
import { MyAccount } from './MyAccount';
|
||||
|
||||
import { DEFAULT_USER_DATA } from '../../../Constants';
|
||||
import { request } from '../../../Helpers';
|
||||
|
||||
const defaultUserData = {
|
||||
email: '',
|
||||
username: '',
|
||||
publicName: '',
|
||||
allowEmails: true,
|
||||
useIPAPronunciation: true,
|
||||
};
|
||||
|
||||
export class AccountManager extends Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
|
@ -31,11 +24,12 @@ export class AccountManager extends Component {
|
|||
this.state = {
|
||||
isLoggedIn: false,
|
||||
userData: {
|
||||
email: userData ? userData.email : defaultUserData.email,
|
||||
username: userData ? userData.username : defaultUserData.username,
|
||||
publicName: userData ? userData.publicName : defaultUserData.publicName,
|
||||
allowEmails: userData ? userData.allowEmails : defaultUserData.allowEmails,
|
||||
useIPAPronunciation: userData ? userData.useIPAPronunciation : defaultUserData.useIPAPronunciation,
|
||||
email: userData ? userData.email : DEFAULT_USER_DATA.email,
|
||||
username: userData ? userData.username : DEFAULT_USER_DATA.username,
|
||||
publicName: userData ? userData.publicName : DEFAULT_USER_DATA.publicName,
|
||||
allowEmails: userData ? userData.allowEmails : DEFAULT_USER_DATA.allowEmails,
|
||||
useIPAPronunciation: userData ? userData.useIPAPronunciation : DEFAULT_USER_DATA.useIPAPronunciation,
|
||||
itemsPerPage: userData ? userData.itemsPerPage : DEFAULT_USER_DATA.itemsPerPage,
|
||||
},
|
||||
userDictionaries: [],
|
||||
};
|
||||
|
@ -52,7 +46,7 @@ export class AccountManager extends Component {
|
|||
store.remove('LexicongaUserData');
|
||||
this.setState({
|
||||
isLoggedIn: false,
|
||||
userData: Object.assign({}, defaultUserData),
|
||||
userData: Object.assign({}, DEFAULT_USER_DATA),
|
||||
userDictionaries: [],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import Inferno from 'inferno';
|
||||
import { Component } from 'inferno';
|
||||
import PropTypes from 'prop-types';
|
||||
import store from 'store';
|
||||
|
||||
import dictionaryData from '../../managers/DictionaryData';
|
||||
import { DEFAULT_USER_DATA } from '../../Constants';
|
||||
import { IPAField } from './IPAField';
|
||||
import { LargeTextArea } from './LargeTextArea';
|
||||
import { Word } from '../../managers/Word';
|
||||
|
@ -13,7 +15,6 @@ export class WordForm extends Component {
|
|||
|
||||
PropTypes.checkPropTypes({
|
||||
word: PropTypes.object,
|
||||
useIpaField: PropTypes.bool.isRequired,
|
||||
callback: PropTypes.func,
|
||||
updateDisplay: PropTypes.func,
|
||||
}, props, 'prop', 'WordForm');
|
||||
|
@ -102,6 +103,8 @@ export class WordForm extends Component {
|
|||
}
|
||||
|
||||
render () {
|
||||
const userData = store.get('LexicongaUserData');
|
||||
const useIpaField = userData ? userData.useIPAPronunciation : DEFAULT_USER_DATA.useIPAPronunciation;
|
||||
return (
|
||||
<div className='box'>
|
||||
<div className='field'>
|
||||
|
@ -121,7 +124,7 @@ export class WordForm extends Component {
|
|||
</div>
|
||||
|
||||
<IPAField value={ this.state.wordPronunciation }
|
||||
preventIPA={ !this.props.useIpaField }
|
||||
preventIPA={ !useIpaField }
|
||||
onChange={ (newValue) => this.setState({ wordPronunciation: newValue }) } />
|
||||
|
||||
<div className='field'>
|
||||
|
|
|
@ -6,6 +6,7 @@ import { Component, render } from 'inferno';
|
|||
import store from 'store';
|
||||
|
||||
import removeDiacritics from '../vendor/StackOverflow/removeDiacritics';
|
||||
import { DEFAULT_USER_DATA } from './Constants';
|
||||
import { addHelpfulPrototypes, getWordsStats } from './Helpers';
|
||||
addHelpfulPrototypes();
|
||||
|
||||
|
@ -37,8 +38,6 @@ class App extends Component {
|
|||
|
||||
displayedWords: [],
|
||||
currentPage: 0,
|
||||
itemsPerPage: 30,
|
||||
useIpaPronunciationField: true,
|
||||
searchConfig: {
|
||||
searchingIn: 'name',
|
||||
searchMethod: SEARCH_METHOD.contains,
|
||||
|
@ -95,9 +94,10 @@ class App extends Component {
|
|||
}
|
||||
|
||||
updateDisplayedWords (callback = () => {}) {
|
||||
const {currentPage, itemsPerPage} = this.state;
|
||||
dictionary.wordsPromise.then(words => {
|
||||
const { searchConfig, partsOfSpeech, currentPage, itemsPerPage } = this.state;
|
||||
const userData = store.get('LexicongaUserData');
|
||||
const itemsPerPage = userData ? userData.itemsPerPage : DEFAULT_USER_DATA.itemsPerPage;
|
||||
const { searchConfig, partsOfSpeech, currentPage } = this.state;
|
||||
const partsOfSpeechForFilter = [...partsOfSpeech, 'Uncategorized'];
|
||||
const pageStart = currentPage * itemsPerPage;
|
||||
const pageEnd = pageStart + itemsPerPage;
|
||||
|
@ -218,8 +218,6 @@ class App extends Component {
|
|||
wordsAreFiltered={ this.isUsingFilter }
|
||||
wordsInCurrentList={ this.state.wordsInCurrentList }
|
||||
currentPage={ this.state.currentPage }
|
||||
itemsPerPage={ this.state.itemsPerPage }
|
||||
useIpaPronunciationField={ this.state.useIpaPronunciationField }
|
||||
stats={ this.state.stats }
|
||||
setPage={ this.setPage.bind(this) }
|
||||
updateDisplay={ this.updateDisplayedWords.bind(this) }
|
||||
|
|
|
@ -2,60 +2,18 @@ import assert from 'assert';
|
|||
import store from 'store';
|
||||
import wordDb from './WordDatabase';
|
||||
import idManager from './IDManager';
|
||||
import { timestampInSeconds } from '../Helpers';
|
||||
|
||||
const defaultDictionary = {
|
||||
name: 'New',
|
||||
specification: 'Dictionary',
|
||||
description: 'A new dictionary.',
|
||||
partsOfSpeech: ['Noun', 'Adjective', 'Verb'],
|
||||
alphabeticalOrder: [],
|
||||
details: {
|
||||
phonology: {
|
||||
consonants: [],
|
||||
vowels: [],
|
||||
blends: [],
|
||||
phonotactics: {
|
||||
onset: [],
|
||||
nucleus: [],
|
||||
coda: [],
|
||||
exceptions: '',
|
||||
},
|
||||
},
|
||||
orthography: {
|
||||
notes: '',
|
||||
},
|
||||
grammar: {
|
||||
notes: '',
|
||||
},
|
||||
// custom: [
|
||||
// // {
|
||||
// // name: 'Example Tab',
|
||||
// // content: `This is an _example_ tab to show how **tabs** work with [Markdown](${ MARKDOWN_LINK })!`,
|
||||
// // }
|
||||
// ],
|
||||
},
|
||||
settings: {
|
||||
allowDuplicates: false,
|
||||
caseSensitive: false,
|
||||
sortByDefinition: false,
|
||||
isComplete: false,
|
||||
isPublic: false,
|
||||
},
|
||||
lastUpdated: null,
|
||||
createdOn: timestampInSeconds(),
|
||||
};
|
||||
import { DEFAULT_DICTIONARY } from '../Constants';
|
||||
|
||||
class DictionaryData {
|
||||
constructor () {
|
||||
this.default = defaultDictionary;
|
||||
this.default = DEFAULT_DICTIONARY;
|
||||
|
||||
if (['emptydetails', 'donotsave'].includes(process.env.NODE_ENV)) {
|
||||
store.remove('Lexiconga');
|
||||
}
|
||||
|
||||
if (!store.get('Lexiconga')) {
|
||||
this.storedData = defaultDictionary;
|
||||
this.storedData = DEFAULT_DICTIONARY;
|
||||
} else {
|
||||
wordDb.words
|
||||
.orderBy('id').reverse()
|
||||
|
@ -83,7 +41,7 @@ class DictionaryData {
|
|||
|
||||
get name () {
|
||||
return this.storedData.name
|
||||
|| defaultDictionary.name;
|
||||
|| DEFAULT_DICTIONARY.name;
|
||||
}
|
||||
|
||||
set name (value) {
|
||||
|
@ -95,7 +53,7 @@ class DictionaryData {
|
|||
|
||||
get specification () {
|
||||
return this.storedData.specification
|
||||
|| defaultDictionary.specification;
|
||||
|| DEFAULT_DICTIONARY.specification;
|
||||
}
|
||||
|
||||
set specification (value) {
|
||||
|
@ -107,7 +65,7 @@ class DictionaryData {
|
|||
|
||||
get description () {
|
||||
return this.storedData.description
|
||||
|| defaultDictionary.description;
|
||||
|| DEFAULT_DICTIONARY.description;
|
||||
}
|
||||
|
||||
set description (value) {
|
||||
|
@ -119,7 +77,7 @@ class DictionaryData {
|
|||
|
||||
get partsOfSpeech () {
|
||||
return this.storedData.partsOfSpeech
|
||||
|| defaultDictionary.partsOfSpeech;
|
||||
|| DEFAULT_DICTIONARY.partsOfSpeech;
|
||||
}
|
||||
|
||||
set partsOfSpeech (array) {
|
||||
|
@ -133,12 +91,12 @@ class DictionaryData {
|
|||
|
||||
get details () {
|
||||
return this.storedData.details
|
||||
|| defaultDictionary.details;
|
||||
|| DEFAULT_DICTIONARY.details;
|
||||
}
|
||||
|
||||
get consonants () {
|
||||
return this.storedData.details.phonology.consonants
|
||||
|| defaultDictionary.details.phonology.consonants;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.consonants;
|
||||
}
|
||||
|
||||
set consonants (array) {
|
||||
|
@ -152,7 +110,7 @@ class DictionaryData {
|
|||
|
||||
get vowels () {
|
||||
return this.storedData.details.phonology.vowels
|
||||
|| defaultDictionary.details.phonology.vowels;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.vowels;
|
||||
}
|
||||
|
||||
set vowels (array) {
|
||||
|
@ -166,7 +124,7 @@ class DictionaryData {
|
|||
|
||||
get blends () {
|
||||
return this.storedData.details.phonology.blends
|
||||
|| defaultDictionary.details.phonology.blends;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.blends;
|
||||
}
|
||||
|
||||
set blends (array) {
|
||||
|
@ -180,7 +138,7 @@ class DictionaryData {
|
|||
|
||||
get onset () {
|
||||
return this.storedData.details.phonology.phonotactics.onset
|
||||
|| defaultDictionary.details.phonology.phonotactics.onset;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.phonotactics.onset;
|
||||
}
|
||||
|
||||
set onset (array) {
|
||||
|
@ -194,7 +152,7 @@ class DictionaryData {
|
|||
|
||||
get nucleus () {
|
||||
return this.storedData.details.phonology.phonotactics.nucleus
|
||||
|| defaultDictionary.details.phonology.phonotactics.nucleus;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.phonotactics.nucleus;
|
||||
}
|
||||
|
||||
set nucleus (array) {
|
||||
|
@ -208,7 +166,7 @@ class DictionaryData {
|
|||
|
||||
get coda () {
|
||||
return this.storedData.details.phonology.phonotactics.coda
|
||||
|| defaultDictionary.details.phonology.phonotactics.coda;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.phonotactics.coda;
|
||||
}
|
||||
|
||||
set coda (array) {
|
||||
|
@ -222,7 +180,7 @@ class DictionaryData {
|
|||
|
||||
get exceptions () {
|
||||
return this.storedData.details.phonology.phonotactics.exceptions
|
||||
|| defaultDictionary.details.phonology.phonotactics.exceptions;
|
||||
|| DEFAULT_DICTIONARY.details.phonology.phonotactics.exceptions;
|
||||
}
|
||||
|
||||
set exceptions (value) {
|
||||
|
@ -234,7 +192,7 @@ class DictionaryData {
|
|||
|
||||
get orthographyNotes () {
|
||||
return this.storedData.details.orthography.notes
|
||||
|| defaultDictionary.details.orthography.notes;
|
||||
|| DEFAULT_DICTIONARY.details.orthography.notes;
|
||||
}
|
||||
|
||||
set orthographyNotes (value) {
|
||||
|
@ -246,7 +204,7 @@ class DictionaryData {
|
|||
|
||||
get grammarNotes () {
|
||||
return this.storedData.details.grammar.notes
|
||||
|| defaultDictionary.details.grammar.notes;
|
||||
|| DEFAULT_DICTIONARY.details.grammar.notes;
|
||||
}
|
||||
|
||||
set grammarNotes (value) {
|
||||
|
@ -258,7 +216,7 @@ class DictionaryData {
|
|||
|
||||
get alphabeticalOrder () {
|
||||
return this.storedData.alphabeticalOrder
|
||||
|| defaultDictionary.alphabeticalOrder;
|
||||
|| DEFAULT_DICTIONARY.alphabeticalOrder;
|
||||
}
|
||||
|
||||
set alphabeticalOrder (array) {
|
||||
|
@ -272,12 +230,12 @@ class DictionaryData {
|
|||
|
||||
get settings () {
|
||||
return this.storedData.settings
|
||||
|| defaultDictionary.settings;
|
||||
|| DEFAULT_DICTIONARY.settings;
|
||||
}
|
||||
|
||||
get allowDuplicates () {
|
||||
return this.storedData.settings.allowDuplicates
|
||||
|| defaultDictionary.settings.allowDuplicates;
|
||||
|| DEFAULT_DICTIONARY.settings.allowDuplicates;
|
||||
}
|
||||
|
||||
set allowDuplicates (value) {
|
||||
|
@ -289,7 +247,7 @@ class DictionaryData {
|
|||
|
||||
get caseSensitive () {
|
||||
return this.storedData.settings.caseSensitive
|
||||
|| defaultDictionary.settings.caseSensitive;
|
||||
|| DEFAULT_DICTIONARY.settings.caseSensitive;
|
||||
}
|
||||
|
||||
set caseSensitive (value) {
|
||||
|
@ -301,7 +259,7 @@ class DictionaryData {
|
|||
|
||||
get sortByDefinition () {
|
||||
return this.storedData.settings.sortByDefinition
|
||||
|| defaultDictionary.settings.sortByDefinition;
|
||||
|| DEFAULT_DICTIONARY.settings.sortByDefinition;
|
||||
}
|
||||
|
||||
set sortByDefinition (value) {
|
||||
|
@ -313,7 +271,7 @@ class DictionaryData {
|
|||
|
||||
get isComplete () {
|
||||
return this.storedData.settings.isComplete
|
||||
|| defaultDictionary.settings.isComplete;
|
||||
|| DEFAULT_DICTIONARY.settings.isComplete;
|
||||
}
|
||||
|
||||
set isComplete (value) {
|
||||
|
@ -325,7 +283,7 @@ class DictionaryData {
|
|||
|
||||
get isPublic () {
|
||||
return this.storedData.settings.isPublic
|
||||
|| defaultDictionary.settings.isPublic;
|
||||
|| DEFAULT_DICTIONARY.settings.isPublic;
|
||||
}
|
||||
|
||||
set isPublic (value) {
|
||||
|
@ -337,7 +295,7 @@ class DictionaryData {
|
|||
|
||||
get lastUpdated () {
|
||||
return this.storedData.lastUpdated
|
||||
|| defaultDictionary.lastUpdated;
|
||||
|| DEFAULT_DICTIONARY.lastUpdated;
|
||||
}
|
||||
|
||||
set lastUpdated (value) {
|
||||
|
|
Loading…
Add table
Reference in a new issue