-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sort.jsx
65 lines (56 loc) · 1.36 KB
/
Sort.jsx
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
import React from 'react';
import styled from 'styled-components';
function Sort({
reviews, setSort,
}) {
const sortByHelpfulness = () => {
setSort('helpful');
};
const sortByNewest = () => {
setSort('newest');
};
const sortByRelevance = () => {
setSort('relevant');
};
const handleSortChange = (event) => {
const selectedSort = event.target.value;
if (selectedSort === 'helpfulness') {
sortByHelpfulness();
} else if (selectedSort === 'newest') {
sortByNewest();
} else if (selectedSort === 'relevance') {
sortByRelevance();
}
};
return (
<StylesDiv>
<label htmlFor="selectedSort">
<b>
{reviews.length}
{' '}
reviews, sorted by
{' '}
<SortSelector id="selectedSort" name="selectedSort" onChange={handleSortChange}>
<option value="relevance">relevance</option>
<option value="helpfulness">helpfulness</option>
<option value="newest">newest</option>
</SortSelector>
</b>
</label>
</StylesDiv>
);
}
const StylesDiv = styled.div`
margin-bottom: 35px
`;
const SortSelector = styled.select`
border: none;
background: none;
outline: none;
border-bottom: 1px solid black;
padding: 1px;
font-size: inherit;
font-family: inherit;
font-weight: bold;
`;
export default Sort;