-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome.js
125 lines (116 loc) · 3.52 KB
/
home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { Component } from "react";
import axios from "axios";
import InfiniteScroll from "react-infinite-scroll-component";
import App from "../components/layouts/App";
import Story from "../components/Story";
import { Icon, Divider, BackTop } from "antd";
import Banner from "../components/Banner";
export class Home extends Component {
state = {
page: 0,
stories: [],
count: 2,
hasMore: true,
total: 0
};
componentDidMount() {
const { count, page } = this.state;
axios.get(`/stories?page=${page}&count=${count}`).then(res => {
this.setState({
stories: this.state.stories.concat(res.data.data.results),
page: this.state.page + 1,
total: res.data.data.total
});
});
}
fetchStories = () => {
setTimeout(() => {
if (this.state.stories.length >= this.state.total) {
this.setState({
hasMore: false
});
return;
}
const { count, page } = this.state;
axios.get(`/stories?page=${page}&count=${count}`).then(res => {
this.setState({
stories: this.state.stories.concat(res.data.data.results),
page: this.state.page + 1,
total: res.data.data.total
});
});
}, 500);
};
render() {
return (
<App>
<Banner />
<div className="stories">
<InfiniteScroll
dataLength={this.state.stories.length}
next={this.fetchStories}
hasMore={this.state.hasMore}
loader={
<div>
<div className="loader-ellips">
<span className="loader-ellips__dot one" />
<span className="loader-ellips__dot two" />
<span className="loader-ellips__dot three" />
<span className="loader-ellips__dot four" />
</div>
<p style={{ textAlign: "center" }}>
<b>Cooking more stories for you</b>
</p>
</div>
}
endMessage={
<div style={{ padding: "5px" }}>
<p style={{ textAlign: "center" }}>
<div className="icons-list" style={{ padding: "20px" }}>
<Icon
type="smile"
theme="twoTone"
style={{ fontSize: "52px" }}
/>
<Icon
type="heart"
theme="twoTone"
twoToneColor="#eb2f96"
style={{ fontSize: "52px" }}
/>
<Icon
type="check-circle"
theme="twoTone"
twoToneColor="#52c41a"
style={{ fontSize: "52px" }}
/>
</div>
<b>Yay! You have seen it all</b>
</p>
</div>
}
>
<div>
<BackTop visibilityHeight="400" />
</div>
<Divider style={{ fontSize: "40px", marginTop: "5px" }} id="read">
Stories
</Divider>
<div
style={{
padding: "6%",
scrollBehavior: "smooth"
}}
>
{this.state.stories.map(story => (
<Story key={story.id} story={story} />
))}
</div>
<Divider />
</InfiniteScroll>
</div>
</App>
);
}
}
export default Home;