Skip to content

Commit

Permalink
feat: clear filters button
Browse files Browse the repository at this point in the history
  • Loading branch information
zerinoid committed Jul 9, 2023
1 parent 2cd59ba commit 914fa68
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
6 changes: 6 additions & 0 deletions public/clear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/sections/filter/Filter.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const base = [
},
{
label: '2020',
value: 2029
value: 2020
},
{
label: '2021',
Expand Down
12 changes: 9 additions & 3 deletions src/components/sections/gallery/Gallery.module.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.container {
display: grid;
gap: 1rem;
padding: 10px;

@media screen(md) {
padding: 10px;
padding: 15px;
grid-template-columns: repeat(2, minmax(300px, 1fr));
}
}
Expand All @@ -14,6 +15,11 @@
}

.empty p {
margin-top: 80px;
font-size: 30px;
margin-top: 50px;
font-size: 20px;

@media screen(md) {
margin-top: 80px;
font-size: 30px;
}
}
43 changes: 42 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PrimaryLayout from '../components/layouts/primary/PrimaryLayout';
import styles from '../styles/Home.module.css';
import { NextPageWithLayout } from './_app';
import Filter from '../components/sections/filter/Filter';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faXmark, faBars, faEye } from '@fortawesome/free-solid-svg-icons';
import { galleryData } from '@/components/sections/gallery/Gallery.data';
Expand All @@ -18,6 +18,17 @@ const Home: NextPageWithLayout = () => {
});
const [isFilterOpen, setIsFilterOpen] = useState<boolean>(false);
const [searchText, setSearchText] = useState<string>('');
const [showClearButton, setShowClearButton] = useState<boolean>(false);

useEffect(() => {
const isFilterActive = Object.values(filters).some(set => set.size > 0);
if (isFilterActive) {
setShowClearButton(true);
} else {
setShowClearButton(false);
}
}, [filters]);

const projects = galleryData.projects;

const handleSearchTextChange = (text: string) => {
Expand Down Expand Up @@ -75,8 +86,38 @@ const Home: NextPageWithLayout = () => {
return true;
});

const clearFilter = (): void => {
setFilters({
status: new Set(),
year: new Set(),
score: new Set(),
area: new Set(),
program: new Set()
});
};

const clearIcon = (
<svg
xmlns="http://www.w3.org/2000/svg"
width="50"
height="50"
viewBox="0 0 20 20"
>
<path
fill="#dd3333"
d="M10 0a10 10 0 1 0 10 10A10 10 0 0 0 10 0zm5.66 14.24l-1.41 1.41L10 11.41l-4.24 4.25-1.42-1.42L8.59 10 4.34 5.76l1.42-1.42L10 8.59l4.24-4.24 1.41 1.41L11.41 10z"
/>
</svg>
);

return (
<>
{showClearButton && (
<button className={styles.clearButton} onClick={clearFilter}>
{clearIcon}
Clear filters
</button>
)}
<div className={styles.header}>
<div className="flex md:hidden">
<button onClick={() => setIsFilterOpen(isOpen => !isOpen)}>
Expand Down
18 changes: 18 additions & 0 deletions src/styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
text-transform: uppercase;
}

.headerButtons {
display: flex;
justify-content: space-between;
}

.clearButton {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
bottom: 15px;
right: 15px;
font-size: 12px;
text-decoration: underline;
color: red;
z-index: 900;
}

.main {
display: grid;
grid-template-columns: 1fr;
Expand Down

0 comments on commit 914fa68

Please sign in to comment.