1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-06-20 08:06:39 +02:00

Add Grammar notes editing and display

This commit is contained in:
Robbie Antenesse 2017-12-22 08:56:21 -07:00
parent 526f22c329
commit a05fd9c48d
6 changed files with 87 additions and 8 deletions

View file

@ -0,0 +1,29 @@
import Inferno from 'inferno';
import PropTypes from 'prop-types';
import marked from 'marked';
import sanitizeHtml from 'sanitize-html';
export const GrammarDisplay = (props) => {
PropTypes.checkPropTypes({
grammarContent: PropTypes.object.isRequired,
}, props, 'prop', 'GrammarDisplay');
const { grammarContent } = props
return (
<div>
<div className='columns'>
<div className='column'>
<strong>Notes:</strong>
<div className='content'>
<div dangerouslySetInnerHTML={{
__html: marked(sanitizeHtml(grammarContent.notes, { allowedTags: [], allowedAttributes: [], })),
}} />
</div>
</div>
</div>
</div>
);
}

View file

@ -128,7 +128,10 @@ export class DetailsSection extends Component {
break; break;
} }
case 'Grammar': { case 'Grammar': {
detailsDisplay = 'Grammar content!'; detailsDisplay = (
<GrammarDisplay
grammarContent={ details.grammar } />
);
break; break;
} }
} }

View file

@ -16,6 +16,7 @@ export const EditLinguisticsForm = (props) => {
coda: PropTypes.string.isRequired, coda: PropTypes.string.isRequired,
exceptions: PropTypes.string.isRequired, exceptions: PropTypes.string.isRequired,
orthographyNotes: PropTypes.string.isRequired, orthographyNotes: PropTypes.string.isRequired,
grammarNotes: PropTypes.string.isRequired,
}, props, 'prop', 'EditLinguisticsForm'); }, props, 'prop', 'EditLinguisticsForm');
const { const {
@ -29,6 +30,7 @@ export const EditLinguisticsForm = (props) => {
coda, coda,
exceptions, exceptions,
orthographyNotes, orthographyNotes,
grammarNotes,
} = props; } = props;
return ( return (
<div className='form'> <div className='form'>
@ -229,6 +231,32 @@ export const EditLinguisticsForm = (props) => {
</div> </div>
</div> </div>
<h4 className='title as-4'>
Grammar
</h4>
<div className='columns'>
<div className='column'>
<LargeTextArea
label='Grammar Notes'
helpText={[
'Any explanation of grammar, ',
<a href={ MARKDOWN_LINK } target='_blank'>Markdown</a>,
' enabled',
]}
placeholder={ `- Word order is VSO\n- There is no definite article\n...` }
value={ grammarNotes }
onInput={ (event) => {
editDictionaryModal.setState({
grammarNotes: event.target.value,
hasChanged: event.target.value != editDictionaryModal.props.details.grammar.notes,
});
}} />
</div>
</div>
</div> </div>
); );
} }

View file

@ -48,6 +48,7 @@ export class EditDictionaryModal extends Component {
coda: props.details.phonology.phonotactics.coda.join('\n'), coda: props.details.phonology.phonotactics.coda.join('\n'),
exceptions: props.details.phonology.phonotactics.exceptions, exceptions: props.details.phonology.phonotactics.exceptions,
orthographyNotes: props.details.orthography.notes, orthographyNotes: props.details.orthography.notes,
grammarNotes: props.details.grammar.notes,
allowDuplicates: props.settings.allowDuplicates, allowDuplicates: props.settings.allowDuplicates,
caseSensitive: props.settings.caseSensitive, caseSensitive: props.settings.caseSensitive,
@ -104,6 +105,7 @@ export class EditDictionaryModal extends Component {
coda={ this.state.coda } coda={ this.state.coda }
exceptions={ this.state.exceptions } exceptions={ this.state.exceptions }
orthographyNotes={ this.state.orthographyNotes } orthographyNotes={ this.state.orthographyNotes }
grammarNotes={ this.state.grammarNotes }
/> />
); );
break; break;
@ -210,6 +212,10 @@ export class EditDictionaryModal extends Component {
updatedDetails['orthographyNotes'] = this.state.orthographyNotes; updatedDetails['orthographyNotes'] = this.state.orthographyNotes;
} }
if (this.state.grammarNotes !== this.props.details.grammar.notes) {
updatedDetails['grammarNotes'] = this.state.grammarNotes;
}
if (this.state.allowDuplicates !== this.props.settings.allowDuplicates) { if (this.state.allowDuplicates !== this.props.settings.allowDuplicates) {
updatedDetails['allowDuplicates'] = this.state.allowDuplicates; updatedDetails['allowDuplicates'] = this.state.allowDuplicates;
} }

View file

@ -25,14 +25,14 @@ const defaultDictionary = {
notes: '', notes: '',
}, },
grammar: { grammar: {
content: '', notes: '',
}, },
custom: [ // custom: [
{ // // {
name: 'Example Tab', // // name: 'Example Tab',
content: `This is an _example_ tab to show how **tabs** work with [Markdown](${ MARKDOWN_LINK })!`, // // content: `This is an _example_ tab to show how **tabs** work with [Markdown](${ MARKDOWN_LINK })!`,
} // // }
], // ],
}, },
settings: { settings: {
allowDuplicates: false, allowDuplicates: false,
@ -233,6 +233,18 @@ class DictionaryData {
return store.set('Lexiconga', updatedValues); return store.set('Lexiconga', updatedValues);
} }
get grammarNotes () {
return store.get('Lexiconga').details.grammar.notes
|| defaultDictionary.details.grammar.notes;
}
set grammarNotes (value) {
assert(typeof value === 'string', 'Grammar Notes must be passed as a string.');
const updatedValues = store.get('Lexiconga');
updatedValues.details.grammar.notes = value.trim();
return store.set('Lexiconga', updatedValues);
}
get alphabeticalOrder () { get alphabeticalOrder () {
return store.get('Lexiconga').alphabeticalOrder return store.get('Lexiconga').alphabeticalOrder
|| defaultDictionary.alphabeticalOrder; || defaultDictionary.alphabeticalOrder;

View file

@ -33,6 +33,7 @@ export class Updater {
'coda', 'coda',
'exceptions', 'exceptions',
'orthographyNotes', 'orthographyNotes',
'grammarNotes',
]; ];
const settingKeys = [ const settingKeys = [
'allowDuplicates', 'allowDuplicates',