-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultContainer.js
More file actions
72 lines (63 loc) · 1.9 KB
/
Copy pathResultContainer.js
File metadata and controls
72 lines (63 loc) · 1.9 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
import React, { Component } from 'react';
import { Result } from '../Components/Result/Result';
class ResultContainer extends Component {
constructor(props) {
super(props);
this.state = {
showResult: false,
dataArray: []
}
this.updateShowResult = this.updateShowResult.bind(this);
this.setDataArray = this.setDataArray.bind(this);
}
componentWillReceiveProps(nextProps) {
this.setDataArray();
}
// Generate data to display
// Takes searchTerms and returns single values for each site
// Array returned is in same order as sites array
generateDataArray() {
let dataArray = [];
const term1 = this.props.searchTerms[0];
const term2 = this.props.searchTerms[1];
const sites = this.props.sites;
const results = this.props.results;
sites.forEach(site => {
// Examine each result in results for site and term match
// Add match to dataArray
for (let i = 0; i < results.length; i++) {
if (results[i].site === site && results[i].items.includes(term1) === true && results[i].items.includes(term2) === true) {
dataArray.push(results[i].result);
}
}
}
)
console.log(this.props.searchTerms)
console.log(dataArray)
return dataArray;
}
setDataArray() {
let dataArray = this.generateDataArray();
this.setState({
dataArray: dataArray
})
}
updateShowResult() {
this.setState({
showResult: true
})
}
render() {
return <Result
generateResult={this.generateResult}
showResult={this.state.showResult}
updateSearch={this.props.updateSearch}
updateShowResult={this.updateShowResult}
setDataArray={this.setDataArray}
dataArray={this.state.dataArray}
searchTerms={this.props.searchTerms}
sites={this.props.sites}
/>;
}
}
export default ResultContainer;