-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.js
152 lines (148 loc) · 5.01 KB
/
app_test.js
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import axios from 'axios';
import { useState } from 'react';
import './App.css';
const App = () => {
const [chosenType, setChosenType] = useState(null);
const [chosenMag, setChosenMag] = useState(null);
const [chosenLocation, setChosenLocation] = useState(null);
const [chosenDateRange, setChosenDateRange] = useState(null);
const [chosenSortOption, setchosenSortOption] = useState(null);
const [documents, setDocuments] = useState(null);
const sendSearchRequest = () => {
const results = {
method: 'GET',
url: 'http://localhost:3001/results',
params: {
type: chosenType,
mag: chosenMag,
location: chosenLocation,
dateRange: chosenDateRange,
sortOption: chosenSortOption,
},
};
axios
.request(results)
.then((response) => {
console.log(response.data);
setDocuments(response.data);
})
.catch((error) => {
console.error(error);
});
};
return (
<div className='app'>
<nav>
<ul className='nav-bar'>
<li>Earthquake Watch</li>
</ul>
</nav>
<p className='directions'>
{' '}
Search for earthquakes using the following criteria:
</p>
<div className='main'>
<div className='type-selector'>
<ul>
<li>
<select
name='types'
id='types'
value={chosenType}
onChange={(e) => setChosenType(e.target.value)}
>
<option value={null}>Select a Type</option>
<option value='earthquake'>Earthquake</option>
<option value='quarry blast'>Quarry Blast</option>
<option value='ice quake'>Ice Quake</option>
<option value='explosion'>Explosion</option>
</select>
</li>
<li>
<select
name='mag'
id='mag'
value={chosenMag}
onChange={(e) => setChosenMag(e.target.value)}
>
<option value={null}>Select magnitude level</option>
<option value='2.5'>2.5+</option>
<option value='5.5'>5.5+</option>
<option value='6.1'>6.1+</option>
<option value='7'>7+</option>
<option value='8'>8+</option>
</select>
</li>
<li>
<form>
<label>
<input
className='form'
type='text'
placeholder='Enter city, state, country'
value={chosenLocation}
onChange={(e) => setChosenLocation(e.target.value)}
/>
</label>
</form>
</li>
<li>
<select
name='dateRange'
id='dateRange'
value={chosenDateRange}
onChange={(e) => setChosenDateRange(e.target.value)}
>
<option value={null}>Select date range</option>
<option value='7'>Past 7 Days</option>
<option value='14'>Past 14 Days</option>
<option value='21'>Past 21 Days</option>
<option value='30'>Past 30 Days</option>
</select>
</li>
<li>
<select
name='sortOption'
id='sortOption'
value={chosenSortOption}
onChange={(e) => setchosenSortOption(e.target.value)}
>
<option value={null}>Sort by</option>
<option value='desc'>Largest Magnitude First</option>
<option value='asc'>Smallest Magnitude First</option>
</select>
</li>
<li>
<button onClick={sendSearchRequest}>Search</button>
</li>
</ul>
</div>
{documents && (
<div className='search-results'>
{documents.length > 0 ? (
<p> Number of hits: {documents.length}</p>
) : (
<p> No results found. Try broadening your search criteria.</p>
)}
{documents.map((document) => (
<div className='results-card'>
<div className='results-text'>
<p>Type: {document._source.type}</p>
<p>Time: {document._source['@timestamp']}</p>
<p>Location: {document._source.place}</p>
<p>Latitude: {document._source.coordinates.lat}</p>
<p>Longitude: {document._source.coordinates.lon}</p>
<p>Magnitude: {document._source.mag}</p>
<p>Depth: {document._source.depth}</p>
<p>Significance: {document._source.sig}</p>
<p>Event URL: {document._source.url}</p>
</div>
</div>
))}
</div>
)}
</div>
</div>
);
};
export default App;