Commit d2040517 authored by Mattias J Duffy's avatar Mattias J Duffy
Browse files

favorites now stored in local storage(it is implemented in the reducer which...

favorites now stored in local storage(it is implemented in the reducer which isnt good) will change maybe
parent b5e0ba88
......@@ -4,4 +4,5 @@ export const GET_FACILITIES = 'GET_FACILITIES';
export const SET_SIDEBAR = 'SET_SIDEBAR';
export const SET_SEARCH_TERM = 'SET_SEARCH_TERM';
export const ADD_FAVORITE_FACILITY = 'ADD_FAVORITE_FACILITY';
export const REMOVE_FAVORITE_FACILITY = 'REMOVE_FAVORITE_FACILITY';
\ No newline at end of file
export const REMOVE_FAVORITE_FACILITY = 'REMOVE_FAVORITE_FACILITY';
export const SET_ALL_FAVORITES = 'SET_ALL_FAVORITES';
\ No newline at end of file
......@@ -3,7 +3,8 @@ import {
REMOVE_FAVORITE_FACILITY,
SET_SEARCH_TERM,
SET_SIDEBAR,
TOGGLE_DRAWER
TOGGLE_DRAWER,
SET_ALL_FAVORITES
} from './action-types';
export const toggleDrawer = () => ({
......@@ -30,3 +31,9 @@ export const removeFavoriteFacility = slug => ({
slug
});
export const setAllFavorites = (favorites) => ({
type: SET_ALL_FAVORITES,
favorites,
})
......@@ -2,10 +2,10 @@ import React from 'react';
import {withStyles } from 'material-ui/styles';
import {compose} from 'redux';
import {connect} from 'react-redux';
import {toggleDrawer} from '../actions/ui';
import {toggleDrawer,setAllFavorites} from '../actions/ui';
import AppBar from '../components/AppBar';
import Sidebar from '../components/Sidebar';
import {getFacilities, setFacilities} from '../actions/api';
import { getFacilities, setFacilities } from '../actions/api';
import Button from 'material-ui/Button';
import CardContainer from '../components/CardContainer';
import SearchBar from './SearchBar';
......@@ -57,6 +57,12 @@ class Layout extends React.Component {
const facilities = localStorage.getItem('facilities')
this.props.setFacilities(facilities)
}
if(localStorage.getItem('favorites')){
const favorites = localStorage.getItem('favorites')
this.props.setAllFavorites(favorites);
}
this.props.getFacilities()
}
......@@ -108,4 +114,4 @@ function mapStateToProps(state) {
}
}
export default compose(connect(mapStateToProps,{toggleDrawer,getFacilities,setFacilities}), withStyles(styleSheet))(Layout);
export default compose(connect(mapStateToProps,{toggleDrawer,getFacilities,setFacilities,setAllFavorites}), withStyles(styleSheet))(Layout);
import {
TOGGLE_DRAWER, SET_SIDEBAR, SET_SEARCH_TERM, SET_FILTERED_LIST,
ADD_FAVORITE_FACILITY, REMOVE_FAVORITE_FACILITY
ADD_FAVORITE_FACILITY, REMOVE_FAVORITE_FACILITY,SET_ALL_FAVORITES
} from '../actions/action-types'
function isOpen(state=false,action){
......@@ -46,11 +46,18 @@ const search = (state=searchbarState,facilities=[],action) =>{
//TODO: Favorites should be stored in a cookie, not in the redux store.
const favorites = (state = [], action) => {
let newState;
switch(action.type) {
case ADD_FAVORITE_FACILITY:
return [...state, action.slug];
newState = [...state,action.slug]
localStorage.setItem('favorites',newState)
return newState;
case REMOVE_FAVORITE_FACILITY:
return state.filter(slug => slug !== action.slug);
newState = state.filter(slug => slug !== action.slug);
localStorage.setItem('favorites',newState)
return newState;
case SET_ALL_FAVORITES:
return action.favorites;
default:
return state;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment