-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathFilter.js
More file actions
56 lines (50 loc) · 1.59 KB
/
Filter.js
File metadata and controls
56 lines (50 loc) · 1.59 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
import React from 'react';
const capitalize = word => {
if (typeof word === 'string') {
return String(word[0]).toUpperCase() + String(word.slice(1));
}
};
const Filter = ({ data, setFilter, filter }) => {
const arr = data.map(mentor =>
mentor.technology.split(',').map(t => t.trim().toLowerCase())
);
const technologies = [...new Set([].concat.apply([], arr))]
// remove technologies with empty string
.filter(tech => tech.length > 0)
.sort();
const countries = [...new Set(data.map(mentor => mentor.country))].sort();
return (
<div className='row col-md-12 filter-row sticky-top mt-5'>
<h3 className='nav-link filter-header mx-auto'>Filter</h3>
<div className='col-md-12 mt-3'>
<p className='filter-set'>Technology</p>
<select
className='form-control dropdown'
name='technology'
onChange={setFilter}
value={filter.technology ? filter.technology : ''}
>
{technologies.map((tec, i) => (
<option key={i} value={tec} className='dropdown-item'>
{capitalize(tec)}
</option>
))}
</select>
</div>
<div className='col-md-12 mt-3'>
<p className='filter-set'>Country</p>
<select
className='form-control dropdown'
name='country'
onChange={setFilter}
value={filter.country ? filter.country : ''}
>
{countries.map((country, i) => (
<option key={i}>{country}</option>
))}
</select>
</div>
</div>
);
};
export default Filter;