Guest User

Untitled

a guest
Aug 9th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.     ...
  3.     SET_FILTERS,
  4.     ...
  5. } from '../actions/lokale';
  6. import Lokal from './../../models/lokal';
  7. import useGetDistance from '../../handler/useGetDistance';
  8.  
  9. const initialState = {
  10.     ...
  11.     filteredLokale: [],
  12.     ...
  13. };
  14.  
  15. const getDistanceHandler = useGetDistance();
  16.  
  17. const lokaleReducer = (state = initialState, action) => {
  18.     switch (action.type) {
  19.         ...
  20.         case SET_FILTERS:
  21.             //TODO
  22.             const filters = action.filter;
  23.             const updatedFilteredLokale = state.lokale.filter((lokal) => {
  24.                 let bool = true;
  25.                 //Name
  26.                 if (filters[0]) {
  27.                     bool = lokal.name.toLowerCase().indexOf(filters[0].toLowerCase()) > -1;
  28.                 }
  29.                 //Category
  30.                 if (bool && filters[1]) {
  31.                     bool = lokal.category.toLowerCase().indexOf(filters[1].toLowerCase()) > -1;
  32.                 }
  33.  
  34.                 if (bool && filters[2]) {
  35.                     getDistanceHandler(region.latitude, region.longitude).then((distance) => {
  36.                        bool = distance <= filters[2];
  37.  
  38.                     });
  39.                 }
  40.  
  41.                 return bool;
  42.             });
  43.             return { ...state, filteredLokale: updatedFilteredLokale };
  44.  
  45.         ...
  46.         default:
  47.             return state;
  48.     }
  49. };
  50.  
  51. export default lokaleReducer;
  52.  
Advertisement
Add Comment
Please, Sign In to add comment