Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import { useEffect, useState } from 'react';
  2. import { useDispatch, useStore, useSelector} from 'react-redux';
  3.  
  4. import { bindActionCreators } from 'redux';
  5. import { getGyms, saveParams, searchGyms } from 'redux-core/modules/search';
  6.  
  7. export default () => {
  8. const dispatch = useDispatch();
  9.  
  10. const store = useStore();
  11.  
  12. const getGymsAction = bindActionCreators(getGyms, dispatch);
  13. const searchGymsAction = bindActionCreators(searchGyms, dispatch);
  14. const saveParamsAction = bindActionCreators(saveParams, dispatch);
  15.  
  16. const zeroValueParams = {
  17. distance: null,
  18. limit: null,
  19. plan: null,
  20. open_hour: null,
  21. facilities: '',
  22. };
  23.  
  24. // let currentParams;
  25.  
  26. const encoded = useSelector(({ search: { encodedParams } }) => encodedParams);
  27. const [currentParams, setCurrentParams] = useState({});
  28.  
  29. useEffect(() => {
  30. encodedAsJson = ...
  31. setCurrentParams(encodedAsJson)
  32.  
  33. // return () => {
  34. // effect
  35. // };
  36. }, [encoded])
  37.  
  38. const saveCurrentParams = () => {
  39.  
  40. };
  41.  
  42. // console.log(p)
  43. console.log(currentParams)
  44.  
  45. // console.log(store.getState().search.params)
  46.  
  47. // setTimeout(() => {
  48. // console.log('TIMEOUT', store.getState().search.params)
  49. // }, 3000);
  50.  
  51. // console.log(currentParams)
  52.  
  53. const resetToCurrentFilters = () => saveParamsAction({ ...zeroValueParams, ...currentParams });
  54.  
  55. const resetAllFilters = () => searchGymsAction(zeroValueParams);
  56.  
  57. const applyFilters = () => getGymsAction();
  58.  
  59. return {
  60. resetToCurrentFilters,
  61. resetAllFilters,
  62. applyFilters,
  63. saveCurrentParams,
  64. };
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement