1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-06-07 17:56:37 +02:00
Lexiconga/src/components/display/WordsList.jsx

57 lines
1.4 KiB
React
Raw Normal View History

import Inferno from 'inferno';
import Component from 'inferno-component';
import PropTypes from 'prop-types';
import marked from 'marked';
2017-09-11 11:29:22 -06:00
// npm lazyload-inferno-component uses outdated inferno dependencies, so just using the script.
import LazyLoader from '../../../vendor/LGabAnnell/lazyload-inferno-component/lazyload-component';
import idManager from '../../managers/IDManager';
import { WordDisplay } from './WordDisplay';
2017-09-11 11:29:22 -06:00
const loadAd = (callback, { props, router }) => {
require.ensure([], (require) => {
const component = require("./Ad").Ad;
callback(component);
});
};
export class WordsList extends Component {
constructor (props) {
super(props);
PropTypes.checkPropTypes({
adsEveryXWords: PropTypes.number,
words: PropTypes.array,
updateDisplay: PropTypes.func.isRequired,
}, props, 'prop', 'WordList');
}
render () {
2017-09-11 11:29:22 -06:00
const adsEveryXWords = this.props.adsEveryXWords || 10;
return (
<div className='box'>
2017-06-25 14:23:42 -06:00
{this.props.words
2017-09-11 11:29:22 -06:00
&& this.props.words.map((word, index) => {
return (
<div>
{index % adsEveryXWords == 0
&& <LazyLoader lazyLoad={ loadAd } />
}
<WordDisplay key={ `word_${word.id}` }
word={ word }
updateDisplay={ this.props.updateDisplay } />
</div>
);
})
2017-06-25 14:23:42 -06:00
}
</div>
);
}
}