Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useEffect, useState } from 'react';
- import { useDispatch, useStore, useSelector} from 'react-redux';
- import { bindActionCreators } from 'redux';
- import { getGyms, saveParams, searchGyms } from 'redux-core/modules/search';
- export default () => {
- const dispatch = useDispatch();
- const store = useStore();
- const getGymsAction = bindActionCreators(getGyms, dispatch);
- const searchGymsAction = bindActionCreators(searchGyms, dispatch);
- const saveParamsAction = bindActionCreators(saveParams, dispatch);
- const zeroValueParams = {
- distance: null,
- limit: null,
- plan: null,
- open_hour: null,
- facilities: '',
- };
- // let currentParams;
- const encoded = useSelector(({ search: { encodedParams } }) => encodedParams);
- const [currentParams, setCurrentParams] = useState({});
- useEffect(() => {
- encodedAsJson = ...
- setCurrentParams(encodedAsJson)
- // return () => {
- // effect
- // };
- }, [encoded])
- const saveCurrentParams = () => {
- };
- // console.log(p)
- console.log(currentParams)
- // console.log(store.getState().search.params)
- // setTimeout(() => {
- // console.log('TIMEOUT', store.getState().search.params)
- // }, 3000);
- // console.log(currentParams)
- const resetToCurrentFilters = () => saveParamsAction({ ...zeroValueParams, ...currentParams });
- const resetAllFilters = () => searchGymsAction(zeroValueParams);
- const applyFilters = () => getGymsAction();
- return {
- resetToCurrentFilters,
- resetAllFilters,
- applyFilters,
- saveCurrentParams,
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement