Djordje Mitrovic 3 лет назад
Родитель
Сommit
f29a43962d
2 измененных файлов: 13 добавлений и 3 удалений
  1. 2
    1
      src/hooks/useOffers/useOffers.js
  2. 11
    2
      src/hooks/useOffers/useQueryString.js

+ 2
- 1
src/hooks/useOffers/useOffers.js Просмотреть файл

@@ -51,8 +51,9 @@ const useOffers = () => {
}, []);

useEffect(() => {
if (history.location.state?.logo) {
if (!queryStringHook.historyStateCleared) {
clearFiltersAndApply();
history.location.state = {};
}
}, [history.location]);


+ 11
- 2
src/hooks/useOffers/useQueryString.js Просмотреть файл

@@ -16,15 +16,23 @@ const useQueryString = () => {
const dispatch = useDispatch();
const [isInitiallyLoaded, setIsInitallyLoaded] = useState(false);
const [queryObject, setQueryObject] = useState({});
const [historyStateCleared, setHistoryStateCleared] = useState(true);

// Initially read filters, sorting and paging from querystring
useEffect(() => {
if ((!isInitiallyLoaded || history.location?.state?.logo) && !history.location?.state?.from) {
if (
(!isInitiallyLoaded || history.location?.state?.logo) &&
!history.location?.state?.from
) {
const queryStringFromUrl = history.location?.search;
setQueryObject(getQueryObjectHelper(queryStringFromUrl));
dispatch(setQueryString(queryStringFromUrl));
}
history.location.state = {}
if (history.location?.state?.logo) {
setHistoryStateCleared(false);
} else {
setHistoryStateCleared(true);
}
}, [history.location]);

// Set initially loaded to true on initial load
@@ -55,6 +63,7 @@ const useQueryString = () => {
queryString,
queryObject,
isInitiallyLoaded,
historyStateCleared,
};
};
export default useQueryString;

Загрузка…
Отмена
Сохранить