forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-more.js
More file actions
58 lines (50 loc) · 1.67 KB
/
Copy pathload-more.js
File metadata and controls
58 lines (50 loc) · 1.67 KB
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
import React from 'react'
import i18n from 'i18n!react_collaborations'
class LoadMore extends React.Component {
static propTypes = {
hasMore: React.PropTypes.bool.isRequired,
loadMore: React.PropTypes.func.isRequired,
isLoading: React.PropTypes.bool,
children: React.PropTypes.any
}
componentDidUpdate (oldProps) {
let oldCount = React.Children.count(oldProps.children)
let newCount = React.Children.count(this.props.children)
// not first results and not on delete
if (oldCount > 0 && newCount > oldCount) {
let element = this.refs.parent.querySelector(`*:nth-child(${oldCount + 1}) .lor-result a`)
if (element) {
element.focus()
}
}
}
render () {
const hasChildren = React.Children.count(this.props.children) > 0
const opacity = this.props.isLoading ? 1 : 0
return (
<div className='LoadMore' ref='parent'>
{this.props.children}
{this.props.hasMore && !this.props.isLoading &&
<div className='LoadMore-button'>
<button className='Button--link' onClick={this.props.loadMore}>
{i18n.t('Load more results')}
</button>
</div>
}
{hasChildren && this.props.hasMore &&
<div
aria-hidden={!this.props.isLoading}
className='LoadMore-loader'>
</div>
}
</div>
)
}
};
LoadMore.propTypes = {
hasMore: React.PropTypes.bool.isRequired,
loadMore: React.PropTypes.func.isRequired,
isLoading: React.PropTypes.bool,
children: React.PropTypes.any
};
export default LoadMore