forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.jsx
More file actions
125 lines (115 loc) · 3.79 KB
/
Copy pathindex.jsx
File metadata and controls
125 lines (115 loc) · 3.79 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
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 PropTypes from "prop-types";
import { ErrorStateIcon } from "../SvgIcons";
import "./style.less";
export default class ContentLoadWrapper extends Component {
constructor() {
super();
this.state = {
percent: 0
};
this.timeout = 50;
this.delta = 1.00;
this.setTimeout = null;
}
componentDidMount() {
setTimeout(this.increase.bind(this), 100);
this._isMounted = true;
}
componentWillUnmount() {
this._isMounted = false;
}
componentDidUpdate(prevProps) {
let { props } = this;
if (props.loadComplete !== prevProps.loadComplete) {
if (props.loadComplete) {
clearTimeout(this.setTimeout);
if (this._isMounted) {
this.setState({ percent: 100 }, () => {
});
}
setTimeout(() => {
if (typeof props.onCompleteCallback === "function") {
props.onCompleteCallback();
}
}, 300);
}
}
if (props.loadError !== prevProps.loadError) {
if (props.loadError) {
clearTimeout(this.setTimeout);
if (this._isMounted) {
this.setState({ percent: 100 }, () => {
});
}
setTimeout(() => {
if (typeof props.onErrorCallback === "function") {
props.onErrorCallback();
}
}, 300);
}
}
}
increase() {
let {percent} = this.state;
percent++;
this.timeout *= this.delta;
this.delta *= 1.00;
if (percent <= 100) {
if (this._isMounted) {
this.setState({ percent });
}
}
if (percent < 95) {
this.setTimeout = setTimeout(this.increase.bind(this), this.timeout);
}
}
onTryAgain() {
this.setState({
percent: 0
}, () => {
setTimeout(this.increase.bind(this), 100);
});
if (typeof this.props.onTryAgain === "function") {
this.props.onTryAgain();
}
}
render() {
let {percent} = this.state;
const className = "dnn-content-load-wrapper" + (this.props.loadComplete ? " complete" : "") + (this.props.loadError ? " upload-error" : "");
if (typeof this.props.loadComplete === "undefined" || this.props.loadComplete) {
return this.props.children;
}
return <div className={className}>
{this.props.svgSkeleton}
{this.props.loadError &&
<div className="try-load-again">
<div>
<div className="upload-icon">ErrorStateIcon</div>
<p>{this.props.failedToLoadText}</p>
<span onClick={this.onTryAgain.bind(this)}>[{this.props.tryAgainText}]</span>
</div>
</div>}
<div className="upload-bar-container">
<div className="upload-bar-box">
<div className="upload-bar" style={{ width: percent + "%" }} />
</div>
</div>
</div>;
}
}
ContentLoadWrapper.propTypes = {
loadComplete: PropTypes.bool.isRequired,
failedToLoadText: PropTypes.string,
children: PropTypes.node,
svgSkeleton: PropTypes.node,
tryAgainText: PropTypes.string,
loadError: PropTypes.bool,
onTryAgain: PropTypes.func,
onCompleteCallback: PropTypes.func,
onErrorCallback: PropTypes.func
};
ContentLoadWrapper.defaultProps = {
failedToLoadText: "Failed To Load",
tryAgainText: "Retry"
};