Skip to content

Commit

Permalink
Revert "plans/assets: Render project tiles on demand"
Browse files Browse the repository at this point in the history
This reverts commit 1887a6a.
  • Loading branch information
philli-m committed May 3, 2021
1 parent 645dee4 commit dd10b30
Showing 1 changed file with 9 additions and 57 deletions.
66 changes: 9 additions & 57 deletions meinberlin/apps/plans/assets/PlansList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
const React = require('react')
const Moment = require('moment')

const autoScrollThreshold = 500
const itemListInterval = 10

class LazyBackground extends React.Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -73,56 +70,6 @@ class LazyBackground extends React.Component {
}

class PlansList extends React.Component {
constructor (props) {
super(props)

this.addItemsToList = this.addItemsToList.bind(this)
this.bindList = this.bindList.bind(this)
this.handleScroll = this.handleScroll.bind(this)
this.renderTopics = this.renderTopics.bind(this)

this.state = {
itemList: []
}
}

componentDidMount () {
window.addEventListener('scroll', this.handleScroll, { passive: true })
this.addItemsToList()
}

componentWillUnmount () {
window.removeEventListener('scroll', this.handleScroll)
}

getDocumentHeight () {
const D = document
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
)
}

handleScroll () {
const html = document.documentElement
if (html.scrollTop + html.clientHeight > this.getDocumentHeight() - autoScrollThreshold) {
this.addItemsToList()
}
}

addItemsToList () {
const newItemList = this.state.itemList.slice()
for (let i = this.state.itemList.length;
i < this.props.items.length &&
(i - this.state.itemList.length) < itemListInterval; i++) {
newItemList.push(this.renderListItem(this.props.items[i], i))
}
this.setState({
itemList: newItemList
})
}

bindList (element) {
this.listElement = element
}
Expand Down Expand Up @@ -193,7 +140,7 @@ class PlansList extends React.Component {
{item.tile_image &&
<LazyBackground
item={item}
renderTopics={this.renderTopics}
renderTopics={this.renderTopics.bind(this)}
isHorizontal={this.props.isHorizontal}
/>}
<div className="participation-tile__content">
Expand Down Expand Up @@ -287,10 +234,15 @@ class PlansList extends React.Component {
}

renderList () {
if (this.state.itemList.length > 0) {
const list = []
this.props.items.forEach((item, i) => {
list.push(this.renderListItem(item, i))
})

if (list.length > 0) {
return (
<ul className="u-list-reset participation-tile__list">
{this.state.itemList}
{list}
</ul>
)
} else {
Expand All @@ -302,7 +254,7 @@ class PlansList extends React.Component {

render () {
return (
<div ref={this.bindList}>
<div ref={this.bindList.bind(this)}>
{this.renderList()}
</div>
)
Expand Down

0 comments on commit dd10b30

Please sign in to comment.