Updated all components that implement window resize to use redux dimensions

• Updated:
- all components that implement window resize to use redux dimensions
This commit is contained in:
mgabdev
2021-01-08 00:15:53 -05:00
parent 8744868190
commit 152e59a66f
13 changed files with 76 additions and 271 deletions

View File

@@ -21,15 +21,11 @@ import {
TrendsHeadlinesPanel,
TrendsRSSPanel,
} from './ui/util/async_components'
import { getWindowDimension } from '../utils/is_mobile'
const initialState = getWindowDimension()
class News extends React.PureComponent {
state = {
lazyLoaded: false,
width: initialState.width,
}
componentDidMount() {
@@ -38,21 +34,12 @@ class News extends React.PureComponent {
this.window.addEventListener('scroll', this.handleScroll)
this.handleResize()
window.addEventListener('keyup', this.handleKeyUp, false)
window.addEventListener('resize', this.handleResize, false)
}
componentWillUnmount() {
this.detachScrollListener()
window.removeEventListener('keyup', this.handleKeyUp)
window.removeEventListener('resize', this.handleResize, false)
}
handleResize = () => {
const { width } = getWindowDimension()
this.setState({ width })
}
detachScrollListener = () => {
@@ -71,8 +58,8 @@ class News extends React.PureComponent {
}, 150, { trailing: true })
render() {
const { children, isSmall } = this.props
const { lazyLoaded, width } = this.state
const { children, isSmall, width } = this.props
const { lazyLoaded } = this.state
const isXS = width <= BREAKPOINT_EXTRA_SMALL
@@ -113,8 +100,12 @@ class News extends React.PureComponent {
}
const mapStateToProps = (state) => ({
width: state.getIn(['settings', 'window_dimensions', 'width']),
})
News.propTypes = {
isSmall: PropTypes.bool,
}
export default News
export default connect(mapStateToProps)(News)