Lexiconga/src/index.jsx

110 lines
2.4 KiB
React
Raw Normal View History

2017-06-26 00:23:03 +02:00
// import 'font-awesome/scss/font-awesome.scss';
import './sass/main.scss';
import Inferno from 'inferno';
import Component from 'inferno-component';
import { addHelpfulPrototypes } from './Helpers';
addHelpfulPrototypes();
import dictionary from './managers/DictionaryData';
2017-08-20 19:57:17 +02:00
import { Updater } from './managers/Updater';
if (process.env.NODE_ENV !== 'production') {
require('inferno-devtools');
}
import { Header } from './components/structure/Header';
import { MainDisplay } from './components/MainDisplay';
import { Footer } from './components/structure/Footer';
class App extends Component {
constructor (props) {
super(props);
this.state = {
2017-06-25 23:49:23 +02:00
name: dictionary.name,
specification: dictionary.specification,
description: dictionary.description,
partsOfSpeech: dictionary.partsOfSpeech,
details: dictionary.details,
settings: dictionary.settings,
alphabeticalOrder: dictionary.alphabeticalOrder,
2017-06-25 23:49:23 +02:00
displayedWords: [],
searchConfig: null,
}
this.updater = new Updater(this, dictionary);
this.updateDisplayedWords();
}
get dictionaryInfo () {
const {
2017-06-25 23:49:23 +02:00
name,
specification,
description,
partsOfSpeech,
details,
settings,
alphabeticalOrder,
} = this.state;
return {
name,
specification,
description,
partsOfSpeech,
details,
settings,
alphabeticalOrder,
};
}
2017-06-25 23:49:23 +02:00
updatePartsOfSpeech () {
this.setState({
partsOfSpeech: dictionary.partsOfSpeech,
});
}
2017-06-25 22:23:42 +02:00
updateDisplayedWords () {
// const {searchIn, searchTerm, filteredPartsOfSpeech} = this.state.searchConfig;
// TODO: Sort out searching to remove this temporary solution.
dictionary.wordsPromise.then((words) => {
2017-06-25 22:23:42 +02:00
this.setState({
2017-06-25 23:49:23 +02:00
displayedWords: words,
2017-06-25 22:23:42 +02:00
})
});
}
search (searchConfig) {
this.setState({
2017-06-25 23:49:23 +02:00
searchConfig: searchConfig,
});
}
render () {
return (
<div>
<Header
2017-06-25 23:49:23 +02:00
partsOfSpeech={ this.state.partsOfSpeech }
search={ (searchConfig) => this.search(searchConfig) }
/>
<MainDisplay
2017-06-25 23:49:23 +02:00
dictionaryInfo={ this.dictionaryInfo }
wordsToDisplay={ this.state.displayedWords }
updateDisplay={ this.updateDisplayedWords.bind(this) }
updater={ this.updater }
/>
<Footer />
</div>
);
}
}
Inferno.render(<App />, document.getElementById('site'));