-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
118 lines (111 loc) · 3.33 KB
/
index.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
import React, { Component } from "react";
import axios from "axios";
import { Spin } from "antd";
import InfiniteScroll from "react-infinite-scroll-component";
import App from "../components/layouts/App";
import Story from "../components/Story";
import { Icon, Divider, BackTop, Row, Col } from "antd";
export class Index extends Component {
state = {
page: 0,
stories: [],
count: 2,
loading: false,
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
});
});
}
antIcon = <Icon type="radar-chart" style={{ fontSize: 54 }} spin />;
fetchStories = () => {
const { count, page } = this.state;
if (this.state.stories.length >= this.state.total) {
this.setState({
hasMore: false
});
return;
}
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
});
});
this.setState({ loading: false });
};
render() {
return (
<App style={{ display: "flex", flexDirection: "row" }}>
<div className="stories">
<InfiniteScroll
dataLength={this.state.stories.length}
next={this.fetchStories}
hasMore={this.state.hasMore}
loader={
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
width: "85vw",
height: "300px",
padding: "0 auto"
}}
>
<Spin
style={{ textAlign: "center" }}
indicator={this.antIcon}
/>
<h2>Cooking Stories for you...</h2>
</div>
}
endMessage={
<div style={{ padding: "20px" }}>
<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>
}
>
{this.state.stories.map(story => (
<Story
key={story.id}
story={story}
loading={this.state.loading}
/>
))}
</InfiniteScroll>
</div>
</App>
);
}
}
export default Index;