Skip to content

Commit f816b7b

Browse files
Add ability to search for resources
1 parent 9b73b27 commit f816b7b

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

src/components/Help.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Help extends Component {
1010
this.state = {
1111
query: "",
1212
data: {},
13+
currentResources: [],
1314
};
1415
this.handleQuery = this.handleQuery.bind(this);
1516
this.getData = this.getData.bind(this);
@@ -47,33 +48,63 @@ class Help extends Component {
4748
}
4849

4950
getData() {
50-
let resources = {};
51-
let locationType;
51+
let resources = [];
5252
for (const key of Object.keys(this.state.data)) {
5353
if (key === this.state.query) {
54-
resources = this.state.data[key];
55-
locationType = "multiple";
54+
resources.push({ ...this.state.data[key] });
5655
} else {
5756
for (const dist of Object.keys(this.state.data[key])) {
5857
if (dist === this.state.query) {
59-
resources = this.state.data[key][dist];
60-
locationType = "single";
58+
resources.push({ [key]: this.state.data[key][dist] });
6159
}
6260
}
6361
}
6462
}
65-
this.setState({ currentResources: resources, locationType: locationType });
63+
this.setState({ currentResources: resources });
6664
}
6765

6866
render() {
67+
const res = this.state.currentResources.map((object) => {
68+
for (const key in object) {
69+
if (object.hasOwnProperty(key)) {
70+
for (const key2 in object[key]) {
71+
if (object[key].hasOwnProperty(key2)) {
72+
const result = object[key][key2].map((resource) => (
73+
<div>
74+
<h3>{resource.category}</h3>
75+
<p>Organization: {resource.nameoftheorganisation}</p>
76+
<a href={resource.contact}>Link</a>
77+
<p>Contact: {resource.phonenumber}</p>
78+
</div>
79+
));
80+
return result;
81+
}
82+
}
83+
}
84+
}
85+
return null;
86+
});
6987
return (
7088
<div>
7189
<h1>Help Page</h1>
7290
<p>For Help Please Contact</p>
7391
<Form handleQuery={this.handleQuery} />
92+
{res}
7493
</div>
7594
);
7695
}
7796
}
7897

7998
export default withStyles(styles)(Help);
99+
100+
// 0:
101+
// Gangtok:
102+
// CoVID-19 Testing Lab: Array(1)
103+
// 0:
104+
// category: "CoVID-19 Testing Lab"
105+
// city: "Gangtok"
106+
// contact: "https://covid.icmr.org.in/index.php/testing-labs-deatails#"
107+
// descriptionandorserviceprovided: "Collection Site Only"
108+
// nameoftheorganisation: "Sir Thutob Namgyal Memorial (STNM)"
109+
// phonenumber: "9845562399"
110+
// state: "Sikkim"

0 commit comments

Comments
 (0)