Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/core/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const App = (props) => {
const [loading, setLoading] = useState(true); // shapes loading

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

const { user } = props;

Expand Down Expand Up @@ -92,7 +93,9 @@ const App = (props) => {
<>
<Header {...props}
searchTerm={searchTerm}
setSearchTerm={setSearchTerm}/>
setSearchTerm={setSearchTerm}
sort={sort}
setSort={setSort} />
{loading ? (
<Loader
style={{margin: '20% auto auto 42%'}}
Expand All @@ -102,7 +105,7 @@ const App = (props) => {
width={300}
/>
) : (
<ShapeList {...props} data={ data } searchTerm={searchTerm} />
<ShapeList {...props} data={ data } searchTerm={searchTerm} sort={sort} />
)}
</>
);
Expand Down
30 changes: 24 additions & 6 deletions components/utils/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const NavbarSearchInputControl = styled(FormControl)`

const CloseIcon = styled(FiX)`
margin: 0.37rem;
cursor: pointer;
`;

const UserThumb = styled.div`
Expand Down Expand Up @@ -131,7 +132,9 @@ const Header = ({
user,
setUser,
searchTerm,
setSearchTerm
setSearchTerm,
sort,
setSort
}) => {

const [searchterm, setSearchterm] = useState('');
Expand Down Expand Up @@ -167,12 +170,27 @@ const Header = ({
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<CloseIcon color='#ffffff' size='24px' />
<CloseIcon title="Clear Search Query" color='#ffffff' size='24px' onClick={() => setSearchTerm('')}/>
</NavbarSearchInput>
<DropdownButton variant="outline-secondary" size="sm" id="dropdown-basic-button" title="View by Popularity" className="border-0">
<Dropdown.Item href="#/action-1">Likes</Dropdown.Item>
<Dropdown.Item href="#/action-2" active>Popularity</Dropdown.Item>
<Dropdown.Item href="#/action-3">Newly Added</Dropdown.Item>
<DropdownButton variant="outline-secondary" size="sm" id="dropdown-basic-button" title={`Sort by ${sort}`} className="border-0">
<Dropdown.Item
href="#"
active={sort==='oldest'}
onClick={() =>setSort('oldest')}>
Oldest
</Dropdown.Item>
<Dropdown.Item
href="#"
active={sort==='popularity'}
onClick={() =>setSort('popularity')}>
Popularity
</Dropdown.Item>
<Dropdown.Item
href="#"
active={sort==='recent'}
onClick={() =>setSort('recent')}>
Recent
</Dropdown.Item>
</DropdownButton>
</NavbarSearchInputContainer>

Expand Down
28 changes: 21 additions & 7 deletions components/utils/ShapeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ const LikeFilledIcon = styled(BsFillHeartFill)`
cursor: pointer;
`;

const ShapeList = ({ setOpen, user, data, searchTerm }) => {
const ShapeList = (
{
setOpen,
user,
data,
searchTerm,
sort
}) => {

const filterShape = (shapes, searchTerm) => {
if (!searchTerm) {
Expand All @@ -209,8 +216,16 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
const [shapeToExport, setShapeToExport] = useState();

useEffect(() =>{
setFilteredShape(filterShape(shapes, searchTerm));
}, [searchTerm, shapes]);
const copy = [...shapes];
if(sort === 'recent') {
copy.sort((a, b) => b.__createdtime__ - a.__createdtime__);
} else if(sort === 'popularity') {
copy.sort((a, b) => b.likes - a.likes);
} else if(sort === 'oldest') {
copy.sort((a, b) => a.__createdtime__ - b.__createdtime__);
}
setFilteredShape(filterShape(copy, searchTerm));
}, [searchTerm, shapes, sort]);

const handleSwicth = (shapeName) => {

Expand Down Expand Up @@ -359,19 +374,18 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
/>
<ShapeActions className="shape-actions">
<ShapeActionsContainer>
<span
title="Like"
<span
onClick={(event, shapeId) => performLike(event, shape['shape_id'])}>
{
shape.liked ?
(
<Button variant="danger" className="btn-icon">
<Button title="Remove Like" variant="danger" className="btn-icon">
<LikeFilledIcon size={24} />
</Button>
)
:
(
<Button variant="outline-light" className="btn-icon">
<Button title="Add Like" variant="outline-light" className="btn-icon">
<LikeIcon size={24} />
</Button>
)
Expand Down