42 |
43 | {renderItems(numberOfItems)}
44 |
45 |
46 |
47 | index: {index}
48 | cursor: {cursor} {nextCursor && `/ ${nextCursor}`}
49 |
50 |
51 | {isLoading &&
52 |
53 | APPENDING MORE POSTS
54 |
55 | }
56 |
57 | );
58 | }
59 |
60 | loadMoreItems(): void {
61 | if (this.state.isLoading) {
62 | return;
63 | }
64 |
65 | this.setState({ isLoading: true });
66 |
67 | setTimeout(() => {
68 | const {numberOfItems} = this.state;
69 |
70 | this.setState({ isLoading: false, numberOfItems: numberOfItems + 100 });
71 | }, 500);
72 | }
73 |
74 | setCursor({scrollTop, scrollHeight}: HTMLElement): void {
75 | this.setState({cursor: scrollTop, nextCursor: scrollHeight});
76 | }
77 |
78 | setIndex(index: number): void {
79 | this.setState({index});
80 | }
81 | }
82 |
83 | /**
84 | * Renders a bunch of spans with the index as content.
85 | */
86 |
87 | function renderItems(numberOfItems: number): Array