Skip to content

Commit 911cd6f

Browse files
Add react content loader
1 parent f5c7d38 commit 911cd6f

File tree

8 files changed

+69
-17
lines changed

8 files changed

+69
-17
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"axios": "^0.19.2",
1616
"classnames": "^2.2.6",
1717
"react": "^16.13.1",
18+
"react-content-loader": "^5.0.4",
1819
"react-dom": "^16.13.1",
1920
"react-fade-in": "^1.0.0",
2021
"react-lottie": "^1.2.3",

src/App.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
min-height: 100vh;
88
background-color: #1A1053;
99
color: rgba(255, 255, 255, .9);
10-
/* color: (props)=> props.isDarkMode ? "rgba(255,255,255,.87)": "rgba(255,255,255,.9)", */
1110
text-transform: capitalize;
1211
display: flex;
1312
justify-content: center;

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class App extends Component {
4242
/>
4343
<Route exact path="/symptoms" render={() => <h1>symptoms</h1>} />
4444
<Route exact path="/stay-safe" render={() => <StaySafe />} />
45-
<Route exact path="/help" render={() => <Help />} />
45+
<Route exact path="/essentials" render={() => <Help />} />
4646
<Route
4747
path="/"
4848
render={() => (

src/components/Form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Form extends Component {
2020
handleSubmit(e) {
2121
e.preventDefault();
2222
this.props.handleQuery(this.state.location);
23-
this.setState({ location: "" });
23+
this.setState({ location: "" }, this.props.handleLoading);
2424
}
2525

2626
render() {
@@ -36,7 +36,7 @@ class Form extends Component {
3636
onChange={this.handleChange}
3737
required
3838
/>
39-
<button className={classes.btn}>Get Help</button>
39+
<button className={classes.btn}>Search</button>
4040
</form>
4141
);
4242
}

src/components/Help.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import axios from "axios";
66
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
77
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons";
88
import FadeIn from "react-fade-in";
9+
import Placeholder from "./Placeholder";
910

1011
class Help extends Component {
1112
constructor(props) {
@@ -14,8 +15,10 @@ class Help extends Component {
1415
query: "",
1516
data: {},
1617
currentResources: [],
18+
loadingStatus: null,
1719
};
1820
this.handleQuery = this.handleQuery.bind(this);
21+
this.handleLoading = this.handleLoading.bind(this);
1922
this.getData = this.getData.bind(this);
2023
}
2124

@@ -50,20 +53,25 @@ class Help extends Component {
5053
this.setState({ query: query }, this.getData);
5154
}
5255

56+
handleLoading() {
57+
this.setState({ loadingStatus: "loading" });
58+
}
59+
5360
getData() {
5461
let resources = [];
5562
for (const key of Object.keys(this.state.data)) {
56-
if (key === this.state.query) {
63+
if (key.toLowerCase() === this.state.query.toLowerCase()) {
5764
resources.push({ ...this.state.data[key] });
5865
} else {
5966
for (const dist of Object.keys(this.state.data[key])) {
60-
if (dist === this.state.query) {
67+
if (dist.toLowerCase() === this.state.query.toLowerCase()) {
6168
resources.push({ [key]: this.state.data[key][dist] });
6269
}
6370
}
6471
}
6572
}
66-
this.setState({ currentResources: resources, isLoading: false });
73+
this.setState({ currentResources: resources });
74+
setTimeout(() => this.setState({ loadingStatus: "completeLoading" }), 1500);
6775
}
6876

6977
render() {
@@ -111,9 +119,23 @@ class Help extends Component {
111119
});
112120
return (
113121
<div className={classes.help}>
114-
<h1 className={classes.mainHeading}>Help Page</h1>
115-
<Form handleQuery={this.handleQuery} />
116-
<div className={classes.container}>{res}</div>
122+
<h1 className={classes.mainHeading}>
123+
Search for Essentials and Services
124+
</h1>
125+
<Form
126+
handleQuery={this.handleQuery}
127+
handleLoading={this.handleLoading}
128+
/>
129+
{this.state.loadingStatus === "loading" && (
130+
<div className={classes.container}>
131+
<Placeholder />
132+
<Placeholder />
133+
<Placeholder />
134+
</div>
135+
)}
136+
{this.state.loadingStatus === "completeLoading" && (
137+
<div className={classes.container}>{res}</div>
138+
)}
117139
</div>
118140
);
119141
}

src/components/Navbar.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
faHome,
66
faHeadSideCough,
77
faFlask,
8-
faQuestionCircle,
8+
faBox,
99
} from "@fortawesome/free-solid-svg-icons";
1010
import styles from "../styles/NavbarStyles";
1111
import { NavLink } from "react-router-dom";
@@ -61,16 +61,13 @@ class Navbar extends Component {
6161
<li className={classes.navItem}>
6262
<NavLink
6363
exact
64-
to="/help"
64+
to="/essentials"
6565
className={classes.navLinks}
6666
activeClassName={classes.active}
6767
>
6868
<div className={classes.iconBox}>
69-
<FontAwesomeIcon
70-
icon={faQuestionCircle}
71-
className={classes.icons}
72-
/>
73-
<p>Help</p>
69+
<FontAwesomeIcon icon={faBox} className={classes.icons} />
70+
<p>Essentials</p>
7471
</div>
7572
</NavLink>
7673
</li>

src/components/Placeholder.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react";
2+
import ContentLoader from "react-content-loader";
3+
4+
const MyLoader = () => (
5+
<ContentLoader
6+
speed={2}
7+
width={400}
8+
height={160}
9+
viewBox="0 0 400 160"
10+
backgroundColor="#f3f3f3"
11+
foregroundColor="#ecebeb"
12+
>
13+
<rect x="0" y="0" rx="3" ry="3" width="67" height="11" />
14+
<rect x="458" y="13" rx="3" ry="3" width="140" height="11" />
15+
<rect x="127" y="48" rx="3" ry="3" width="53" height="11" />
16+
<rect x="187" y="48" rx="3" ry="3" width="72" height="11" />
17+
<rect x="-5" y="46" rx="3" ry="3" width="100" height="11" />
18+
<rect x="-2" y="73" rx="3" ry="3" width="339" height="14" />
19+
<rect x="2" y="22" rx="3" ry="3" width="140" height="11" />
20+
<rect x="164" y="21" rx="3" ry="3" width="173" height="11" />
21+
<rect x="2" y="101" rx="0" ry="0" width="338" height="14" />
22+
<rect x="51" y="130" rx="0" ry="0" width="12" height="0" />
23+
<rect x="72" y="131" rx="0" ry="0" width="54" height="0" />
24+
<rect x="145" y="130" rx="0" ry="0" width="3" height="0" />
25+
</ContentLoader>
26+
);
27+
28+
export default MyLoader;

0 commit comments

Comments
 (0)