Skip to content

Commit

Permalink
onClose logic moved to function
Browse files Browse the repository at this point in the history
  • Loading branch information
mayukh551 committed Oct 1, 2022
1 parent ac1ce00 commit 7188403
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/common/modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,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" /> Close</button>
<button className="btn-default-light btn-size--sm" onClick={ onClose }><GoX size="16px" className="icon" /> Cancel</button>
{ onSubmit && <button className="btn-primary btn-size--sm" onClick={ onSubmit }><GoCheck size="16px" className="icon" /> Apply</button> }
</div>
</div>
Expand Down
22 changes: 12 additions & 10 deletions src/common/search/FilterPlays.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,22 @@ const FilterPlays = ({ reset }) => {
showModal && setShowModal(false);
};

const filterModalCloseBtnHandler = () => {
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));
}
}

return (
<div className='search-filter'>
<Modal
title='Filter Plays By'
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));
}
}}
onClose={filterModalCloseBtnHandler}
onSubmit={handleFilter}
show={showModal}
cname='filter'
Expand Down

0 comments on commit 7188403

Please sign in to comment.