diff --git a/src/newsreader/js/components/Messages.js b/src/newsreader/js/components/Messages.js index 3fed5de..e3d776e 100644 --- a/src/newsreader/js/components/Messages.js +++ b/src/newsreader/js/components/Messages.js @@ -3,9 +3,7 @@ import React from 'react'; class Messages extends React.Component { state = { messages: this.props.messages }; - close = ::this.close; - - close(index) { + close = (index) => { const newMessages = this.state.messages.filter((message, currentIndex) => { return currentIndex != index; }); diff --git a/src/newsreader/js/pages/homepage/components/PostModal.js b/src/newsreader/js/pages/homepage/components/PostModal.js index 4cdc78b..5dacdf8 100644 --- a/src/newsreader/js/pages/homepage/components/PostModal.js +++ b/src/newsreader/js/pages/homepage/components/PostModal.js @@ -7,132 +7,131 @@ import { SAVED_TYPE } from '../constants.js'; import { formatDatetime } from '../../../utils.js'; class PostModal extends React.Component { - modalListener = ::this.modalListener; -readTimer = null; + readTimer = null; -componentDidMount() { - const post = { ...this.props.post }; - const markPostRead = this.props.markPostRead; - const token = Cookies.get('csrftoken'); + componentDidMount() { + const post = { ...this.props.post }; + const markPostRead = this.props.markPostRead; + const token = Cookies.get('csrftoken'); - if (this.props.autoMarking && this.props.selectedType != SAVED_TYPE && !post.read) { - this.readTimer = setTimeout(markPostRead, 3000, post, token); + if (this.props.autoMarking && this.props.selectedType != SAVED_TYPE && !post.read) { + this.readTimer = setTimeout(markPostRead, 3000, post, token); + } + + window.addEventListener('click', this.modalListener); } - window.addEventListener('click', this.modalListener); -} + componentWillUnmount() { + if (this.readTimer) { + clearTimeout(this.readTimer); + } -componentWillUnmount() { - if (this.readTimer) { - clearTimeout(this.readTimer); + this.readTimer = null; + + window.removeEventListener('click', this.modalListener); } - this.readTimer = null; + modalListener = (e) => { + const targetClassName = e.target.className; - window.removeEventListener('click', this.modalListener); -} - -modalListener(e) { - const targetClassName = e.target.className; - - if (this.props.post && targetClassName == 'modal post-modal') { - this.props.unSelectPost(); - } -} - -render() { - const post = this.props.post; - const token = Cookies.get('csrftoken'); - const publicationDate = formatDatetime(post.publicationDate); - const titleClassName = post.read ? 'post__title post__title--read' : 'post__title'; - const readButtonDisabled = - post.read || this.props.isUpdating || this.props.selectedType === SAVED_TYPE; - const savedIconClass = post.saved - ? 'post__save post__save--saved saved-icon saved-icon--saved' - : 'post__save saved-icon'; - - let ruleUrl = ''; - - switch (this.props.rule.type) { - default: - ruleUrl = `${this.props.feedUrl}/${this.props.rule.id}/`; - break; + if (this.props.post && targetClassName == 'modal post-modal') { + this.props.unSelectPost(); + } } - return ( -