Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Clear All" Button added to clear applied Filters #562

Merged
merged 33 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6e0dc88
Cancel btn enabled
mayukh551 Sep 14, 2022
f5a0ea9
Filter cancel btn problem fixed
mayukh551 Sep 14, 2022
7cf7679
onCancel and onClose separate functions for closing filter modal
mayukh551 Sep 14, 2022
94efa85
Changed cancel to close button
mayukh551 Sep 15, 2022
852fa32
Clear All filter btn added
mayukh551 Sep 15, 2022
8870e2c
:active is enabled when clear all btn is clicked
mayukh551 Sep 15, 2022
1877c0c
If no filters applied, click Clear All will not re-render the same page
mayukh551 Sep 15, 2022
0f3d74c
Merge branch 'main' into main
mayukh551 Sep 15, 2022
9b4e57b
Merge branch 'main' of https://github.com/mayukh551/react-play
mayukh551 Sep 16, 2022
8ea382d
Merge branch 'reactplay:main' into main
mayukh551 Sep 16, 2022
8fe1f8e
Merge branch 'reactplay:main' into main
mayukh551 Sep 16, 2022
838acdc
storing the cond of empty filter in a variable
mayukh551 Sep 16, 2022
67f0dbd
removing code that caused the error
mayukh551 Sep 16, 2022
df27305
Problem Persists
mayukh551 Sep 16, 2022
a9daff5
checking if clear filters is causing the error
mayukh551 Sep 17, 2022
4a957de
clear filter function restored
mayukh551 Sep 17, 2022
468035a
Merge branch 'main' of https://github.com/mayukh551/react-play
mayukh551 Sep 20, 2022
5d2e9d8
Clear All Filter button added
mayukh551 Sep 20, 2022
5b8c050
Button changed to link for 'Clear All'
mayukh551 Sep 20, 2022
a75f7b2
resetFilter passed through filterPlayModal component
mayukh551 Sep 20, 2022
68ab501
Merge branch 'reactplay:main' into main
mayukh551 Sep 23, 2022
325b455
filterQuery is not updated | condition for empty filters removed
mayukh551 Sep 23, 2022
9971a12
filterQuery is not updated | condition for empty filters removed
mayukh551 Sep 23, 2022
1dd22fd
commented before clear all link
mayukh551 Sep 23, 2022
eacc8b1
special scenario for clear filter not applied but clicked
mayukh551 Sep 25, 2022
1a9d1e9
scenario updated
mayukh551 Sep 25, 2022
f5e5258
scenario updated
mayukh551 Sep 25, 2022
c82dc1a
Merge branch 'main' into main
mayukh551 Sep 26, 2022
628b680
Merge branch 'main' into main
mayukh551 Sep 30, 2022
ac1ce00
renamed ifFilterApplied to isFilterApplied
mayukh551 Sep 30, 2022
7188403
onClose logic moved to function
Oct 1, 2022
a259bdd
Merge branch 'main' into main
Sachin-chaurasiya Oct 5, 2022
e3e7c76
Merge branch 'main' into main
atapas Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/common/modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Modal =({ title, show, onClose, onSubmit, children, cname })=> {

if (!show) return null;


return ReactDOM.createPortal(
<>
<div className="modal-overlay" onClick={ onClose }></div>
Expand All @@ -28,7 +27,7 @@ const Modal =({ title, show, onClose, onSubmit, children, cname })=> {
{ children }
</div>
<div className={`modal-${cname}-footer`}>
<button className="btn-default-light btn-size--sm" onClick={ onClose }><GoX size="16px" className="icon" /> Cancel</button>
<button className="btn-default-light btn-size--sm" onClick={ onClose }><GoX size="16px" className="icon" /> Close</button>
Sachin-chaurasiya marked this conversation as resolved.
Show resolved Hide resolved
{ onSubmit && <button className="btn-primary btn-size--sm" onClick={ onSubmit }><GoCheck size="16px" className="icon" /> Apply</button> }
</div>
</div>
Expand Down
105 changes: 66 additions & 39 deletions src/common/search/FilterPlays.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ import { FormControl, MenuItem, Select } from "@mui/material";
import { makeStyles } from "@mui/styles";

const useStyles = makeStyles({
menuPaper: {
maxHeight: "250px !important",
},
menuPaper: {
maxHeight: "250px !important",
},
});

const FilterPlaysModalBody = ({ filterQuery, setFilterQuery }) => {
const [loading, error, data] = useFetchFilterData();
const { tags, levels, creators } = data;
const FilterPlaysModalBody = ({ filterQuery, setFilterQuery, onClearAppliedFilters }) => {
const [loading, error, data] = useFetchFilterData();
const { tags, levels, creators } = data;

const classes = useStyles();
const classes = useStyles();

const languages = ["js", "ts"];
const languages = ["js", "ts"];

if (error) {
return <p>{error?.message ?? "Something Went Wrong"}</p>;
}
if (error) {
return <p>{error?.message ?? "Something Went Wrong"}</p>;
}

const defaultOption = {
value: " ",
label: "All",
};
const defaultOption = {
value: " ",
label: "All",
};

const creatorOptions = [
defaultOption,
Expand All @@ -52,29 +52,29 @@ const FilterPlaysModalBody = ({ filterQuery, setFilterQuery }) => {
})) || []),
];

const levelOptions = [
defaultOption,
...(levels?.map((level) => ({
label: level.level.name,
value: level.level.id,
})) || []),
];
const levelOptions = [
defaultOption,
...(levels?.map((level) => ({
label: level.level.name,
value: level.level.id,
})) || []),
];

const tagOptions = [
defaultOption,
...(tags?.map((tag) => ({
label: tag.tag,
value: tag.id,
})) || []),
];
const tagOptions = [
defaultOption,
...(tags?.map((tag) => ({
label: tag.tag,
value: tag.id,
})) || []),
];

const languageOptions = [
defaultOption,
...languages?.map((language) => ({
label: language === "ts" ? "TypeScript" : "JavaScript",
value: language,
})),
];
const languageOptions = [
defaultOption,
...languages?.map((language) => ({
label: language === "ts" ? "TypeScript" : "JavaScript",
value: language,
})),
];

const renderCreator = (value) => {
const selectedCreator = creatorOptions.find((option) => option.value === value);
Expand All @@ -85,6 +85,11 @@ const FilterPlaysModalBody = ({ filterQuery, setFilterQuery }) => {
<>
<div className='form-group'>
{loading && "Loading Data"}
{/* Clear All filters button */}
<div className="modal-clear-filter">
<span onClick={ onClearAppliedFilters }
className="clear-all-filter-btn">Clear All</span>
</div>
<label>Level</label>
<FormControl fullWidth>
<Select
Expand Down Expand Up @@ -201,11 +206,13 @@ const filterObject = {
const FilterPlays = ({ reset }) => {
const location = useLocation();
const navigate = useNavigate();
const { setFilterQuery } = useContext(SearchContext);
const { filterQuery, setFilterQuery } = useContext(SearchContext);
const [showModal, setShowModal] = useState(false);
const [modifiedFilterQuery, setModifiedFilterQuery] = useState({ ...filterObject });
const [noOfAppliedFilter, setnoOfAppliedFilter] = useState(0);

const [isFilterApplied, setIsFilterApplied] = useState(false);

const resetFilter = useCallback(() => {
const filterObj = { ...filterObject };
setModifiedFilterQuery(filterObj);
Expand All @@ -224,6 +231,9 @@ const FilterPlays = ({ reset }) => {

const handleFilter = (event) => {
event.preventDefault();
// if Apply button on Filter Modal is clicked then set true
setIsFilterApplied(true);

setFilterQuery(modifiedFilterQuery);
setnoOfAppliedFilter(getAppliedFilter(modifiedFilterQuery));
navigate("/plays", { replace: true, state: { search: true, filter: false } });
Expand All @@ -234,19 +244,36 @@ const FilterPlays = ({ reset }) => {
<div className='search-filter'>
<Modal
title='Filter Plays By'
onClose={() => setShowModal(false)}
onClose={() => {
setShowModal(false);
const {level_id, tags, owner_user_id, language} = modifiedFilterQuery;
const isFilterEmpty= level_id !== "" || tags.length !== 0 || owner_user_id !== "" || language !== "";
// if user closes modal instead of clicking on Apply after clear All filters
if(!isFilterApplied && !isFilterEmpty) {
setModifiedFilterQuery({...filterQuery});
setnoOfAppliedFilter(getAppliedFilter(filterQuery));
}
}}
Sachin-chaurasiya marked this conversation as resolved.
Show resolved Hide resolved
onSubmit={handleFilter}
show={showModal}
cname='filter'
children={
<FilterPlaysModalBody
filterQuery={modifiedFilterQuery}
setFilterQuery={setModifiedFilterQuery}
onClearAppliedFilters={() => {
setModifiedFilterQuery({...filterObject});
setnoOfAppliedFilter(0);
}}
/>
}
/>

<button onClick={() => setShowModal(true)} className='btn-filter' title='Filter Plays'>
<button onClick={() => {
setShowModal(true);
setIsFilterApplied(false);
}}
className='btn-filter' title='Filter Plays'>
{noOfAppliedFilter === 0 ? null : <div className='badge'>{noOfAppliedFilter}</div>}

<RiFilterFill className='icon' size='28px' color='var(--color-neutral-30)' />
Expand Down
20 changes: 20 additions & 0 deletions src/common/search/search.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,24 @@
font-size: var(--fs-rg);
}

/* CSS attributes for clear All button */

.modal-clear-filter {
width: 100%;
text-align: right;
display:flex;
justify-content: flex-end;
}

.clear-all-filter-btn {
font-size: smaller;
font-weight: bold;
cursor: pointer;
transition: all .2s
}

.clear-all-filter-btn:hover{
text-decoration: underline;
text-underline-offset: 2px;
}