@@ -5,9 +5,11 @@ import Calendar from '../../assets/Calendar.jsx';
55import Reset from '../../assets/Reset.jsx' ;
66import Dropdown from '../../assets/Dropdown.jsx' ;
77import CalendarPicker from '../Calendar/CalendarPicker.jsx' ;
8+ import { useGlobalContext } from '../contexts/ToggleContext' ;
89
910const FilterComponent = ( { isVisible, onClose, className } ) => {
1011 const { selectedFilters, setSelectedFilters } = useFilterContext ( ) ;
12+
1113 const fields = {
1214 Condition : {
1315 options : [ "Good" , "Great" , "Needs washing" , "Needs repair" , "Needs dry cleaning" , "Not usable" ]
@@ -57,6 +59,7 @@ const FilterComponent = ({ isVisible, onClose, className }) => {
5759 const checkboxRefs = useRef ( { } ) ;
5860 const calendarRef = useRef ( null ) ;
5961 const calendarPickerContainerRef = useRef ( null ) ;
62+ const isFilterHidden = useGlobalContext ( ) ;
6063
6164 // Keep selectedOptions in sync with selectedFilters
6265 useEffect ( ( ) => {
@@ -181,7 +184,20 @@ const FilterComponent = ({ isVisible, onClose, className }) => {
181184 } ) ;
182185 } ;
183186
184- // Format date range display text
187+ // Ensure the filter popup is closed if not visible on the sidebar
188+ // const onCloseRef = useRef(onClose);
189+ // useEffect(() => {
190+ // onCloseRef.current = onClose;
191+ // }, [onClose]);
192+
193+ // const prevIsFilterHidden = useRef(isFilterHidden);
194+ // useEffect(() => {
195+ // if (!prevIsFilterHidden.current && isFilterHidden) {
196+ // onCloseRef.current && onCloseRef.current();
197+ // }
198+ // prevIsFilterHidden.current = isFilterHidden;
199+ // }, [isFilterHidden]);
200+
185201 const getDateRangeText = ( ) => {
186202 if ( dateRange . start && dateRange . end ) {
187203 return `${ dateRange . start } - ${ dateRange . end } ` ;
0 commit comments