Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- ...
- SET_FILTERS,
- ...
- } from '../actions/lokale';
- import Lokal from './../../models/lokal';
- import useGetDistance from '../../handler/useGetDistance';
- const initialState = {
- ...
- filteredLokale: [],
- ...
- };
- const getDistanceHandler = useGetDistance();
- const lokaleReducer = (state = initialState, action) => {
- switch (action.type) {
- ...
- case SET_FILTERS:
- //TODO
- const filters = action.filter;
- const updatedFilteredLokale = state.lokale.filter((lokal) => {
- let bool = true;
- //Name
- if (filters[0]) {
- bool = lokal.name.toLowerCase().indexOf(filters[0].toLowerCase()) > -1;
- }
- //Category
- if (bool && filters[1]) {
- bool = lokal.category.toLowerCase().indexOf(filters[1].toLowerCase()) > -1;
- }
- if (bool && filters[2]) {
- getDistanceHandler(region.latitude, region.longitude).then((distance) => {
- bool = distance <= filters[2];
- });
- }
- return bool;
- });
- return { ...state, filteredLokale: updatedFilteredLokale };
- ...
- default:
- return state;
- }
- };
- export default lokaleReducer;
Advertisement
Add Comment
Please, Sign In to add comment