This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
/
chat.jsx
87 lines (80 loc) · 2.54 KB
/
chat.jsx
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
var ListItem = createReactClass({
getDefaultProps: function() {
return {
height: 50,
lineHeight: "50px"
}
},
render: function() {
return <div className="infinite-list-item" style={
{
height: this.props.height,
lineHeight: this.props.lineHeight,
overflow: 'scroll'
}
}>
<div style={{height: 50}}>
List Item {this.props.index}
</div>
</div>;
}
});
var InfiniteList = createReactClass({
getInitialState: function() {
return {
elements: [],
isInfiniteLoading: false
}
},
componentDidMount: function() {
var that = this;
setInterval(function() {
var elemLength = that.state.elements.length,
newElements = that.buildElements(elemLength, elemLength + 1);
that.setState({
elements: that.state.elements.concat(newElements)
});
}, 500);
},
buildElements: function(start, end) {
var elements = [];
for (var i = start; i < end; i++) {
elements.push(<ListItem key={i} index={i}/>)
}
return elements;
},
handleInfiniteLoad: function() {
var that = this;
this.setState({
isInfiniteLoading: true
});
setTimeout(function() {
var elemLength = that.state.elements.length,
newElements = that.buildElements(elemLength, elemLength + 20);
that.setState({
isInfiniteLoading: false,
elements: newElements.concat(that.state.elements)
});
}, 2000);
},
elementInfiniteLoad: function() {
return <div className="infinite-list-item">
Loading...
</div>;
},
render: function() {
return <Infinite elementHeight={51}
containerHeight={window.innerHeight}
infiniteLoadBeginEdgeOffset={300}
onInfiniteLoad={this.handleInfiniteLoad}
loadingSpinnerDelegate={this.elementInfiniteLoad()}
isInfiniteLoading={this.state.isInfiniteLoading}
timeScrollStateLastsForAfterUserScrolls={1000}
displayBottomUpwards
>
{this.state.elements}
</Infinite>;
}
});
ReactDOM.render(<InfiniteList/>,
document.getElementById('infinite-window-example'));