2017-05-18 23:43:29 -06:00
|
|
|
import Inferno from 'inferno';
|
|
|
|
import Component from 'inferno-component';
|
2017-11-15 13:59:58 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-18 23:43:29 -06:00
|
|
|
import marked from 'marked';
|
2017-11-15 11:02:09 -07:00
|
|
|
import swal from 'sweetalert2';
|
2017-05-18 23:43:29 -06:00
|
|
|
|
2017-10-31 09:16:22 -06:00
|
|
|
import './WordDisplay.scss';
|
|
|
|
|
2017-05-18 23:43:29 -06:00
|
|
|
import idManager from '../../managers/IDManager';
|
2017-07-25 22:11:33 -06:00
|
|
|
import { Word } from '../../managers/Word';
|
2017-05-18 23:43:29 -06:00
|
|
|
|
2017-07-25 22:11:33 -06:00
|
|
|
import { WordForm } from '../management/WordForm';
|
2017-05-18 23:43:29 -06:00
|
|
|
|
|
|
|
export class WordDisplay extends Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-11-15 13:59:58 -07:00
|
|
|
PropTypes.checkPropTypes({
|
|
|
|
word: PropTypes.object.isRequired,
|
|
|
|
updateDisplay: PropTypes.func.isRequired,
|
|
|
|
}, props, 'prop', 'WordDisplay');
|
|
|
|
|
2017-05-18 23:43:29 -06:00
|
|
|
this.state = {
|
2017-11-14 17:04:02 -07:00
|
|
|
menuIsOpen: false,
|
2017-07-25 22:11:33 -06:00
|
|
|
isEditing: false,
|
2017-05-18 23:43:29 -06:00
|
|
|
}
|
2017-10-31 09:16:22 -06:00
|
|
|
|
|
|
|
this.wordDetailsHTML = marked(props.word.details);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUpdate (nextProps, nextState) {
|
|
|
|
if (this.props.word.details !== nextProps.word.details) {
|
|
|
|
this.wordDetailsHTML = marked(nextProps.word.details);
|
|
|
|
}
|
2017-05-18 23:43:29 -06:00
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:02 -07:00
|
|
|
edit () {
|
|
|
|
this.setState({
|
|
|
|
menuIsOpen: false,
|
|
|
|
isEditing: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:02:09 -07:00
|
|
|
delete () {
|
|
|
|
const { word } = this.props;
|
|
|
|
swal({
|
|
|
|
title: `Delete "${ word.name }"?`,
|
|
|
|
text: `It will be gone forever and cannot be restored!`,
|
|
|
|
type: 'warning',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: 'Yes, delete it!',
|
|
|
|
cancelButtonText: 'No, cancel!',
|
|
|
|
confirmButtonClass: 'button is-danger',
|
|
|
|
cancelButtonClass: 'button',
|
|
|
|
buttonsStyling: false
|
|
|
|
}).then(() => {
|
|
|
|
word.delete(word.id)
|
|
|
|
.then(() => {
|
|
|
|
this.props.updateDisplay();
|
|
|
|
}).then(() => {
|
|
|
|
this.setState({ menuIsOpen: false }, () => {
|
|
|
|
swal(
|
|
|
|
'Deleted!',
|
|
|
|
`"${ word.name }" has been deleted.`,
|
|
|
|
'success'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, dismiss => {
|
|
|
|
console.log('Word not deleted');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-18 23:43:29 -06:00
|
|
|
render () {
|
2017-11-14 17:04:02 -07:00
|
|
|
const { menuIsOpen, isEditing } = this.state;
|
2017-11-15 13:50:46 -07:00
|
|
|
const { word, updateDisplay } = this.props;
|
2017-11-14 17:04:02 -07:00
|
|
|
|
|
|
|
if (isEditing) {
|
|
|
|
return (
|
|
|
|
<WordForm
|
2017-11-15 13:50:46 -07:00
|
|
|
word={word}
|
|
|
|
updateDisplay={updateDisplay}
|
|
|
|
callback={() => {
|
|
|
|
this.setState({
|
|
|
|
menuIsOpen: false,
|
|
|
|
isEditing: false,
|
|
|
|
})
|
|
|
|
}}
|
2017-11-14 17:04:02 -07:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2017-05-18 23:43:29 -06:00
|
|
|
return (
|
|
|
|
<div className='card'>
|
|
|
|
|
|
|
|
<header className='card-header'>
|
2017-10-31 09:16:22 -06:00
|
|
|
<div className='word-card-header-title'>
|
|
|
|
<span className='word-name'>
|
2017-11-15 11:02:09 -07:00
|
|
|
{ word.name }
|
2017-10-31 09:16:22 -06:00
|
|
|
</span>
|
2017-08-21 15:12:46 -06:00
|
|
|
{
|
2017-11-15 11:02:09 -07:00
|
|
|
(word.pronunciation || word.partOfSpeech)
|
2017-08-21 15:12:46 -06:00
|
|
|
&& (
|
2017-10-31 09:16:22 -06:00
|
|
|
<span className='word-classification'>
|
2017-08-21 15:12:46 -06:00
|
|
|
{
|
2017-11-15 11:02:09 -07:00
|
|
|
(word.pronunciation)
|
2017-10-31 09:16:22 -06:00
|
|
|
&& (
|
|
|
|
<span className='word-pronunciation'>
|
2017-11-15 11:02:09 -07:00
|
|
|
{ word.pronunciation }
|
2017-10-31 09:16:22 -06:00
|
|
|
</span>
|
|
|
|
)
|
2017-08-21 15:12:46 -06:00
|
|
|
}
|
2017-10-31 09:16:22 -06:00
|
|
|
|
2017-08-21 15:12:46 -06:00
|
|
|
{
|
2017-11-15 11:02:09 -07:00
|
|
|
(word.partOfSpeech)
|
2017-10-31 09:16:22 -06:00
|
|
|
&& (
|
|
|
|
<span className='word-part-of-speech'>
|
2017-11-15 11:02:09 -07:00
|
|
|
{ word.partOfSpeech }
|
2017-10-31 09:16:22 -06:00
|
|
|
</span>
|
|
|
|
)
|
2017-08-21 15:12:46 -06:00
|
|
|
}
|
2017-10-31 09:16:22 -06:00
|
|
|
</span>
|
2017-08-21 15:12:46 -06:00
|
|
|
)
|
|
|
|
}
|
2017-10-31 09:16:22 -06:00
|
|
|
</div>
|
2017-11-14 17:04:02 -07:00
|
|
|
<div aria-label='options'
|
|
|
|
className={`card-header-icon dropdown is-right ${ menuIsOpen ? 'is-active' : '' }`}
|
|
|
|
>
|
|
|
|
<span className='icon dropdown-trigger'
|
|
|
|
onClick={ () => this.setState({ menuIsOpen: !menuIsOpen }) }
|
|
|
|
>
|
|
|
|
<i className={`fa fa-angle-${ menuIsOpen ? 'up' : 'down' }`} aria-hidden='true'></i>
|
2017-10-31 09:16:22 -06:00
|
|
|
</span>
|
2017-11-14 17:04:02 -07:00
|
|
|
<div className='dropdown-menu' id='dropdown-menu' role='menu'>
|
|
|
|
<div className='dropdown-content'>
|
|
|
|
<a className='dropdown-item' onClick={ this.edit.bind(this) }>
|
|
|
|
Edit
|
|
|
|
</a>
|
2017-11-15 11:02:09 -07:00
|
|
|
<a onClick={ this.delete.bind(this) } className='dropdown-item is-danger'>
|
2017-11-14 17:04:02 -07:00
|
|
|
Delete
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-10-31 09:16:22 -06:00
|
|
|
</header>
|
2017-05-18 23:43:29 -06:00
|
|
|
|
2017-10-31 09:16:22 -06:00
|
|
|
<section className='card-content'>
|
|
|
|
<div className='content'>
|
2017-08-21 15:12:46 -06:00
|
|
|
{
|
2017-11-15 11:02:09 -07:00
|
|
|
(word.definition)
|
2017-05-18 23:43:29 -06:00
|
|
|
&& (
|
2017-10-31 09:16:22 -06:00
|
|
|
<p className='word-definition'>
|
2017-11-15 11:02:09 -07:00
|
|
|
{ word.definition }
|
2017-05-18 23:43:29 -06:00
|
|
|
</p>
|
2017-08-21 15:12:46 -06:00
|
|
|
)
|
|
|
|
}
|
2017-05-18 23:43:29 -06:00
|
|
|
|
2017-08-21 15:12:46 -06:00
|
|
|
{
|
2017-11-15 11:02:09 -07:00
|
|
|
(word.details)
|
2017-05-18 23:43:29 -06:00
|
|
|
&& (
|
2017-10-31 09:16:22 -06:00
|
|
|
<p className='word-details'
|
|
|
|
dangerouslySetInnerHTML={{__html: this.wordDetailsHTML}} />
|
2017-08-21 15:12:46 -06:00
|
|
|
)
|
|
|
|
}
|
2017-05-18 23:43:29 -06:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|