Skip to content

Commit b5fc255

Browse files
committed
feat
1 parent 02bcce9 commit b5fc255

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

components/core/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const App = (props) => {
1818
const [loading, setLoading] = useState(true); // shapes loading
1919

2020
const [searchTerm, setSearchTerm] = useState(""); // search
21+
const [sort, setSort] = useState("popularity"); // sort
2122

2223
const { user } = props;
2324

@@ -92,7 +93,9 @@ const App = (props) => {
9293
<>
9394
<Header {...props}
9495
searchTerm={searchTerm}
95-
setSearchTerm={setSearchTerm}/>
96+
setSearchTerm={setSearchTerm}
97+
sort={sort}
98+
setSort={setSort} />
9699
{loading ? (
97100
<Loader
98101
style={{margin: '20% auto auto 42%'}}
@@ -102,7 +105,7 @@ const App = (props) => {
102105
width={300}
103106
/>
104107
) : (
105-
<ShapeList {...props} data={ data } searchTerm={searchTerm} />
108+
<ShapeList {...props} data={ data } searchTerm={searchTerm} sort={sort} />
106109
)}
107110
</>
108111
);

components/utils/Header.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const NavbarSearchInputControl = styled(FormControl)`
9191

9292
const CloseIcon = styled(FiX)`
9393
margin: 0.37rem;
94+
cursor: pointer;
9495
`;
9596

9697
const UserThumb = styled.div`
@@ -131,7 +132,9 @@ const Header = ({
131132
user,
132133
setUser,
133134
searchTerm,
134-
setSearchTerm
135+
setSearchTerm,
136+
sort,
137+
setSort
135138
}) => {
136139

137140
const [searchterm, setSearchterm] = useState('');
@@ -167,12 +170,21 @@ const Header = ({
167170
value={searchTerm}
168171
onChange={(e) => setSearchTerm(e.target.value)}
169172
/>
170-
<CloseIcon color='#ffffff' size='24px' />
173+
<CloseIcon title="Clear Search Query" color='#ffffff' size='24px' onClick={() => setSearchTerm('')}/>
171174
</NavbarSearchInput>
172-
<DropdownButton variant="outline-secondary" size="sm" id="dropdown-basic-button" title="View by Popularity" className="border-0">
173-
<Dropdown.Item href="#/action-1">Likes</Dropdown.Item>
174-
<Dropdown.Item href="#/action-2" active>Popularity</Dropdown.Item>
175-
<Dropdown.Item href="#/action-3">Newly Added</Dropdown.Item>
175+
<DropdownButton variant="outline-secondary" size="sm" id="dropdown-basic-button" title={`Sort by ${sort}`} className="border-0">
176+
<Dropdown.Item
177+
href="#"
178+
active={sort==='popularity'}
179+
onClick={() =>setSort('popularity')}>
180+
Popularity
181+
</Dropdown.Item>
182+
<Dropdown.Item
183+
href="#"
184+
active={sort==='recent'}
185+
onClick={() =>setSort('recent')}>
186+
Recent
187+
</Dropdown.Item>
176188
</DropdownButton>
177189
</NavbarSearchInputContainer>
178190

components/utils/ShapeList.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ const LikeFilledIcon = styled(BsFillHeartFill)`
191191
cursor: pointer;
192192
`;
193193

194-
const ShapeList = ({ setOpen, user, data, searchTerm }) => {
194+
const ShapeList = (
195+
{
196+
setOpen,
197+
user,
198+
data,
199+
searchTerm,
200+
sort
201+
}) => {
195202

196203
const filterShape = (shapes, searchTerm) => {
197204
if (!searchTerm) {
@@ -209,8 +216,14 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
209216
const [shapeToExport, setShapeToExport] = useState();
210217

211218
useEffect(() =>{
212-
setFilteredShape(filterShape(shapes, searchTerm));
213-
}, [searchTerm, shapes]);
219+
const copy = [...shapes];
220+
if(sort === 'recent') {
221+
copy.sort((a, b) => b.__createdtime__ - a.__createdtime__);
222+
} else if(sort === 'popularity') {
223+
copy.sort((a, b) => b.likes - a.likes);
224+
}
225+
setFilteredShape(filterShape(copy, searchTerm));
226+
}, [searchTerm, shapes, sort]);
214227

215228
const handleSwicth = (shapeName) => {
216229

@@ -359,19 +372,18 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
359372
/>
360373
<ShapeActions className="shape-actions">
361374
<ShapeActionsContainer>
362-
<span
363-
title="Like"
375+
<span
364376
onClick={(event, shapeId) => performLike(event, shape['shape_id'])}>
365377
{
366378
shape.liked ?
367379
(
368-
<Button variant="danger" className="btn-icon">
380+
<Button title="Remove Like" variant="danger" className="btn-icon">
369381
<LikeFilledIcon size={24} />
370382
</Button>
371383
)
372384
:
373385
(
374-
<Button variant="outline-light" className="btn-icon">
386+
<Button title="Add Like" variant="outline-light" className="btn-icon">
375387
<LikeIcon size={24} />
376388
</Button>
377389
)

0 commit comments

Comments
 (0)