Commit 76f65841 authored by Andrew Hrdy's avatar Andrew Hrdy

Added routes

parent ffedfe28
Pipeline #4009 passed with stages
in 2 minutes and 3 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -10,16 +10,20 @@ ...@@ -10,16 +10,20 @@
"@types/history": "^4.7.2", "@types/history": "^4.7.2",
"@types/mapbox-gl": "^0.51.4", "@types/mapbox-gl": "^0.51.4",
"@types/material-ui": "^0.21.6", "@types/material-ui": "^0.21.6",
"@types/memoize-one": "^4.1.0",
"@types/node": "^11.9.4", "@types/node": "^11.9.4",
"@types/phone-formatter": "0.0.2", "@types/phone-formatter": "0.0.2",
"@types/react": "^16.8.3", "@types/react": "^16.8.3",
"@types/react-dom": "^16.8.1", "@types/react-dom": "^16.8.1",
"@types/react-redux": "^7.0.1", "@types/react-redux": "^7.0.1",
"@types/react-router": "^4.4.4",
"@types/react-router-dom": "^4.3.1",
"classnames": "^2.2.5", "classnames": "^2.2.5",
"connected-react-router": "^6.3.1", "connected-react-router": "^6.3.1",
"history": "^4.7.2", "history": "^4.7.2",
"jss": "^9.8.7", "jss": "^9.8.7",
"mapbox-gl": "^0.53.0", "mapbox-gl": "^0.53.0",
"memoize-one": "^5.0.0",
"phone-formatter": "^0.0.2", "phone-formatter": "^0.0.2",
"promise": "8.0.2", "promise": "8.0.2",
"react": "^16.8.1", "react": "^16.8.1",
...@@ -28,6 +32,7 @@ ...@@ -28,6 +32,7 @@
"react-piwik": "^1.6.0", "react-piwik": "^1.6.0",
"react-redux": "^6.0.0", "react-redux": "^6.0.0",
"react-router": "^4.3.1", "react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"redux": "^4.0.1", "redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8", "redux-devtools-extension": "^2.13.8",
"redux-saga": "^1.0.1", "redux-saga": "^1.0.1",
...@@ -62,7 +67,7 @@ ...@@ -62,7 +67,7 @@
"uglifyjs-webpack-plugin": "^1.2.6", "uglifyjs-webpack-plugin": "^1.2.6",
"webpack": "^4.4.1", "webpack": "^4.4.1",
"webpack-cli": "^2.1.5", "webpack-cli": "^2.1.5",
"webpack-dev-server": "^3.1.4" "webpack-dev-server": "^3.2.0"
}, },
"proxy": "http://localhost:3001", "proxy": "http://localhost:3001",
"scripts": { "scripts": {
......
import * as React from 'react'; import * as React from 'react';
import * as classNames from 'classnames';
import { removeBrackets } from '../utils/nameUtils'; import { removeBrackets } from '../utils/nameUtils';
import * as phoneFormatter from 'phone-formatter'; import * as phoneFormatter from 'phone-formatter';
import { IFacility } from '../models/facility.model'; import { IFacility } from '../models/facility.model';
import { trackPiwikEvent } from '../piwik/piwik';
import { Link } from 'react-router-dom';
import TextwTitle from './TextwTitle'; import TextwTitle from './TextwTitle';
import FacilitiesMap from '../containers/FacilitiesMap'; import FacilitiesMap from '../containers/FacilitiesMap';
...@@ -15,7 +16,8 @@ import Typography from '@material-ui/core/Typography'; ...@@ -15,7 +16,8 @@ import Typography from '@material-ui/core/Typography';
import Divider from '@material-ui/core/Divider'; import Divider from '@material-ui/core/Divider';
import CloseIcon from '@material-ui/icons/Close'; import CloseIcon from '@material-ui/icons/Close';
import IconButton from '@material-ui/core/IconButton'; import IconButton from '@material-ui/core/IconButton';
import { trackPiwikEvent } from '../piwik/piwik'; import FacilityDialog from './FacilityDialog';
import { History } from 'history';
class Sidebar extends React.Component<SidebarProps, SidebarState> { class Sidebar extends React.Component<SidebarProps, SidebarState> {
...@@ -27,11 +29,6 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> { ...@@ -27,11 +29,6 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> {
}; };
} }
handleSidebarClose = () => {
this.props.setSelectedFacility(null);
this.props.setSidebar(false);
}
handleMapDialogClose = () => { handleMapDialogClose = () => {
trackPiwikEvent('map-action', 'close'); trackPiwikEvent('map-action', 'close');
...@@ -49,35 +46,40 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> { ...@@ -49,35 +46,40 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> {
} }
render() { render() {
const {facility, isSidebarOpen, facilities} = this.props; const {facility, facilities, history} = this.props;
const {mapDialogOpen} = this.state; const {mapDialogOpen} = this.state;
return ( return (
<div <div className={'sidebar-container'}>
className={classNames(['card-container-offset', (isSidebarOpen && 'card-container-offset-open'), (!isSidebarOpen && 'card-container-offset-closed')])}> <Paper className={'sidebar-root'}>
<Paper <Link to="/">
className={classNames(['sidebar-root', (isSidebarOpen && 'sidebar-open'), (!isSidebarOpen && 'sidebar-closed')])}> <IconButton className={'sidebar-close-btn'}>
<IconButton className={'sidebar-close-btn'} onClick={this.handleSidebarClose}> <CloseIcon />
<CloseIcon /> </IconButton>
</IconButton> </Link>
<div className={'sidebar-row1'}> <div className={'sidebar-row1'}>
<Avatar className={'sidebar-avatar'} src={facility.logo} /> <Avatar className={'sidebar-avatar'} src={facility.logo} />
<div className={'sidebar-title'}> <div className={'sidebar-title'}>
<Typography variant="h4">{removeBrackets(facility.facility_name)}</Typography> <Typography variant="h4">{removeBrackets(facility.facility_name)}</Typography>
</div> </div>
</div> </div>
<Divider className={'sidebar-divider'} /> <Divider className={'sidebar-divider'} />
<div className={'sidebar-scroll'}> <div className={'sidebar-scroll'}>
<div className={'sidebar-label-holder'}> <div className={'sidebar-label-holder'}>
<TextwTitle label="Building" <TextwTitle label="Building"
content={facility.facility_location && facility.facility_location.building} /> content={facility.facility_location && facility.facility_location.building} />
<TextwTitle label="Address" <TextwTitle label="Address"
content={facility.facility_location && facility.facility_location.address} /> content={facility.facility_location && facility.facility_location.address} />
<TextwTitle label="Phone Number" <TextwTitle label="Phone Number"
content={facility.phone_number ? phoneFormatter.format(facility.phone_number, '(NNN) NNN-NNNN') : 'Unknown'} /> content={facility.phone_number ? phoneFormatter.format(facility.phone_number, '(NNN) NNN-NNNN') : 'Unknown'} />
<TextwTitle label="Hours" content={<WeekHours facility={facility} />} /> <TextwTitle label="Hours" content={<WeekHours facility={facility} />} />
</div> </div>
</div> </div>
<div className={'sidebar-row2'}> <div className={'sidebar-row2'}>
<div className={'sidebar-map-container'} onClick={this.handleMapDialogOpen}> <div className={'sidebar-map-container'} onClick={this.handleMapDialogOpen}>
<FacilitiesMap <FacilitiesMap
...@@ -96,17 +98,17 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> { ...@@ -96,17 +98,17 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> {
/> />
</div> </div>
</Paper> </Paper>
<FacilityDialog facility={facility} facilities={facilities} isOpen={true} onClose={() => history.push('/')} />
</div> </div>
); );
} }
} }
export interface SidebarProps { export interface SidebarProps {
history: History;
facility: IFacility; facility: IFacility;
isSidebarOpen: boolean;
facilities: IFacility[]; facilities: IFacility[];
setSelectedFacility: (facility: IFacility | null) => void;
setSidebar: (isOpen: boolean) => void;
} }
export interface SidebarState { export interface SidebarState {
......
...@@ -6,13 +6,14 @@ import FacilityUtils from '../utils/facilityUtils'; ...@@ -6,13 +6,14 @@ import FacilityUtils from '../utils/facilityUtils';
import { IFacility } from '../models/facility.model'; import { IFacility } from '../models/facility.model';
import { ApplicationState } from '../store'; import { ApplicationState } from '../store';
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { addFavoriteFacility, removeFavoriteFacility, setSelectedFacility, setSidebarExpansion } from '../store/ui/ui.actions'; import { addFavoriteFacility, removeFavoriteFacility } from '../store/ui/ui.actions';
import { trackPiwikEvent } from '../piwik/piwik'; import { NavLink } from 'react-router-dom';
import { withRouter, RouteComponentProps } from 'react-router';
import { Location } from 'history';
import FacilityStatus from '../components/FacilityStatus'; import FacilityStatus from '../components/FacilityStatus';
import FavoriteButton from '../components/FavoriteButton'; import FavoriteButton from '../components/FavoriteButton';
import FacilityCategory from '../components/FacilityCategory'; import FacilityCategory from '../components/FacilityCategory';
import FacilityDialog from '../components/FacilityDialog';
import Card from '@material-ui/core/Card'; import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent'; import CardContent from '@material-ui/core/CardContent';
...@@ -30,8 +31,10 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState> ...@@ -30,8 +31,10 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState>
}; };
} }
getSlugFromLocation = (location: Location) => location.pathname.substring(10);
shouldComponentUpdate = (nextProps: FacilityCardProps) => { shouldComponentUpdate = (nextProps: FacilityCardProps) => {
if (this.isFacilitySelected() !== (nextProps.selectedFacility.slug === this.props.facility.slug)) { if (this.isFacilitySelected() !== (this.getSlugFromLocation(nextProps.location) === this.props.facility.slug)) {
return true; return true;
} }
...@@ -48,21 +51,10 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState> ...@@ -48,21 +51,10 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState>
return false; return false;
} }
isFacilitySelected = (): boolean => this.props.selectedFacility.slug === this.props.facility.slug; isFacilitySelected = (): boolean => this.getSlugFromLocation(this.props.location) === this.props.facility.slug;
handleCardClick = () => {
const newState = !this.isFacilitySelected();
trackPiwikEvent('card-action', 'click');
setTimeout(() => {
this.props.setSelectedFacility(newState ? this.props.facility : null);
this.props.setSidebarExpansion(newState);
}, 0);
}
render() { render() {
const {facility, facilities, favorites, addFavoriteFacility, removeFavoriteFacility} = this.props; const {facility, favorites, addFavoriteFacility, removeFavoriteFacility} = this.props;
const dayOfWeek = [6, 0, 1, 2, 3, 4, 5][new Date().getDay()]; const dayOfWeek = [6, 0, 1, 2, 3, 4, 5][new Date().getDay()];
...@@ -87,72 +79,68 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState> ...@@ -87,72 +79,68 @@ class FacilityCard extends React.Component<FacilityCardProps, FacilityCardState>
facility.facility_location.building; facility.facility_location.building;
return ( return (
<Card onClick={this.handleCardClick} className={classNames('fc-root', this.isFacilitySelected() && 'fc-selected')} <NavLink to={this.isFacilitySelected() ? '/' : `/facility/${facility.slug}`} style={{textDecoration: 'none', color: 'black'}}>
elevation={3}> <Card className={classNames('fc-root', this.isFacilitySelected() && 'fc-selected')}
<div className={'fc-logo-container'}> elevation={3}>
<img className={'fc-logo'} <div className={'fc-logo-container'}>
alt={facility.slug} src={facility.logo} /> <img className={'fc-logo'}
</div> alt={facility.slug} src={facility.logo} />
</div>
<FavoriteButton slug={facility.slug} initialState={favorites.includes(facility.slug)}
addFavoriteFacility={addFavoriteFacility} <FavoriteButton slug={facility.slug} initialState={favorites.includes(facility.slug)}
removeFavoriteFacility={removeFavoriteFacility} /> addFavoriteFacility={addFavoriteFacility}
removeFavoriteFacility={removeFavoriteFacility} />
<CardContent className={'fc-card-content'}>
<Grid container={true} alignItems={'center'} direction={'column'}> <CardContent className={'fc-card-content'}>
<Grid item={true} <Grid container={true} alignItems={'center'} direction={'column'}>
className={classNames('fc-small-grid-item-spacing', 'fc-ellipsis-container', 'fc-title-container')}> <Grid item={true}
<Typography variant={'subtitle1'} align={'center'} className={classNames('fc-small-grid-item-spacing', 'fc-ellipsis-container', 'fc-title-container')}>
className={classNames('fc-title', 'fc-one-line-ellipsis')}> <Typography variant={'subtitle1'} align={'center'}
{removeBrackets(facility.facility_name)} className={classNames('fc-title', 'fc-one-line-ellipsis')}>
</Typography> {removeBrackets(facility.facility_name)}
</Typography>
</Grid>
<Grid item={true} className={'fc-small-grid-item-spacing'}>
<FacilityCategory category={facility.facility_category} />
</Grid>
<Grid item={true} className={'fc-small-grid-item-spacing fc-display-hours'}>
<Typography variant={'body1'}>
{`Today: ${getDisplayHours()}`}
</Typography>
</Grid>
</Grid> </Grid>
<Grid item={true} className={'fc-small-grid-item-spacing'}> <Grid container={true} justify={'space-around'}>
<FacilityCategory category={facility.facility_category} /> <Grid item={true} className={'fc-extra-info'}>
</Grid> <FacilityStatus facility={facility} />
</Grid>
<Grid item={true} className={'fc-small-grid-item-spacing fc-display-hours'}>
<Typography variant={'body1'}> <Grid item={true} className={'fc-extra-info'}>
{`Today: ${getDisplayHours()}`} <Typography variant={'caption'}>
</Typography> <LocationOnIcon className={'fc-card-map-marker-icon'} />
</Typography>
<Typography title={buildingName} variant={'caption'} align={'center'}
className={'fc-two-line-ellipsis'}>
{buildingName}
</Typography>
</Grid>
</Grid> </Grid>
</Grid> </CardContent>
</Card>
<Grid container={true} justify={'space-around'}> </NavLink>
<Grid item={true} className={'fc-extra-info'}>
<FacilityStatus facility={facility} />
</Grid>
<Grid item={true} className={'fc-extra-info'}>
<Typography variant={'caption'}>
<LocationOnIcon className={'fc-card-map-marker-icon'} />
</Typography>
<Typography title={buildingName} variant={'caption'} align={'center'}
className={'fc-two-line-ellipsis'}>
{buildingName}
</Typography>
</Grid>
</Grid>
</CardContent>
<FacilityDialog facility={facility} facilities={facilities} isOpen={this.isFacilitySelected()}
onClose={this.handleCardClick} />
</Card>
); );
} }
} }
export interface FacilityCardProps { export interface FacilityCardProps extends RouteComponentProps<{slug: string}> {
facility: IFacility; facility: IFacility;
facilities: IFacility[]; facilities: IFacility[];
favorites: string[]; favorites: string[];
selectedFacility: IFacility;
setSelectedFacility: (facility: IFacility) => void;
addFavoriteFacility: (slug: string) => void; addFavoriteFacility: (slug: string) => void;
removeFavoriteFacility: (slug: string) => void; removeFavoriteFacility: (slug: string) => void;
setSidebarExpansion: (isOpen: boolean) => void;
} }
export interface FacilityCardState { export interface FacilityCardState {
...@@ -160,15 +148,12 @@ export interface FacilityCardState { ...@@ -160,15 +148,12 @@ export interface FacilityCardState {
} }
const mapStateToProps = (state: ApplicationState) => ({ const mapStateToProps = (state: ApplicationState) => ({
favorites: state.ui.favorites, favorites: state.ui.favorites
selectedFacility: state.ui.selectedFacility
}); });
const mapDispatchToProps = (dispatch: Dispatch) => ({ const mapDispatchToProps = (dispatch: Dispatch) => ({
setSelectedFacility: (facility: IFacility) => dispatch(setSelectedFacility(facility)),
addFavoriteFacility: (slug: string) => dispatch(addFavoriteFacility(slug)), addFavoriteFacility: (slug: string) => dispatch(addFavoriteFacility(slug)),
removeFavoriteFacility: (slug: string) => dispatch(removeFavoriteFacility(slug)), removeFavoriteFacility: (slug: string) => dispatch(removeFavoriteFacility(slug))
setSidebarExpansion: (isOpen: boolean) => dispatch(setSidebarExpansion(isOpen))
}); });
export default connect(mapStateToProps, mapDispatchToProps)(FacilityCard); export default withRouter(connect(mapStateToProps, mapDispatchToProps)(FacilityCard));
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,7 @@ import { ApplicationState } from '../store'; ...@@ -6,7 +6,7 @@ import { ApplicationState } from '../store';
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { fetchFacilities } from '../store/facility/facility.actions'; import { fetchFacilities } from '../store/facility/facility.actions';
import { fetchAlerts } from '../store/alert/alert.actions'; import { fetchAlerts } from '../store/alert/alert.actions';
import { setSidebarExpansion, setSelectedFacility } from '../store/ui/ui.actions'; import { Route, withRouter, RouteComponentProps } from 'react-router-dom';
import CardContainer from '../components/CardContainer'; import CardContainer from '../components/CardContainer';
import AppBar from '../components/AppBar'; import AppBar from '../components/AppBar';
...@@ -23,11 +23,12 @@ class Layout extends React.Component<LayoutProps> { ...@@ -23,11 +23,12 @@ class Layout extends React.Component<LayoutProps> {
} }
render() { render() {
const {isSidebarOpen, selectedFacility, facilities, searchTerm, campusRegion, setSidebarExpansion, setSelectedFacility} = this.props; const {facilities, searchTerm, campusRegion, history} = this.props;
return ( return (
<div className={'layout-root'}> <div className={'layout-root'}>
<AppBar /> <AppBar />
<div className={'layout-container'}> <div className={'layout-container'}>
<div className={'layout-main-content'}> <div className={'layout-main-content'}>
<div className={'layout-card-container'}> <div className={'layout-card-container'}>
...@@ -36,26 +37,23 @@ class Layout extends React.Component<LayoutProps> { ...@@ -36,26 +37,23 @@ class Layout extends React.Component<LayoutProps> {
</div> </div>
</div> </div>
<Sidebar facilities={facilities} facility={selectedFacility} isSidebarOpen={isSidebarOpen} <Route path="/facility/:slug" render={(props) => {
setSidebar={setSidebarExpansion} setSelectedFacility={setSelectedFacility}/> return <Sidebar facility={facilities.find(facility => facility.slug === props.match.params.slug)} facilities={facilities} history={history} />;
}} />
</div> </div>
</div> </div>
); );
} }
} }
export interface LayoutProps { export interface LayoutProps extends RouteComponentProps {
facilities: IFacility[]; facilities: IFacility[];
alerts: IAlert[]; alerts: IAlert[];
favorites: string[]; favorites: string[];
searchTerm: string; searchTerm: string;
campusRegion: CampusRegion; campusRegion: CampusRegion;
selectedFacility: IFacility;
isSidebarOpen: boolean;
fetchFacilities: () => any; fetchFacilities: () => any;
fetchAlerts: () => any; fetchAlerts: () => any;
setSidebarExpansion: (isOpen: boolean) => any;
setSelectedFacility: (facility: IFacility) => any;
} }
const mapStateToProps = (state: ApplicationState) => ({ const mapStateToProps = (state: ApplicationState) => ({
...@@ -63,16 +61,12 @@ const mapStateToProps = (state: ApplicationState) => ({ ...@@ -63,16 +61,12 @@ const mapStateToProps = (state: ApplicationState) => ({
alerts: state.alerts.alerts, alerts: state.alerts.alerts,
favorites: state.ui.favorites, favorites: state.ui.favorites,
searchTerm: state.ui.search.searchTerm, searchTerm: state.ui.search.searchTerm,
campusRegion: state.ui.search.campusRegion, campusRegion: state.ui.search.campusRegion
selectedFacility: state.ui.selectedFacility,
isSidebarOpen: state.ui.sidebar.isOpen
}); });
const mapDispatchToProps = (dispatch: Dispatch) => ({ const mapDispatchToProps = (dispatch: Dispatch) => ({
fetchFacilities: () => dispatch(fetchFacilities()), fetchFacilities: () => dispatch(fetchFacilities()),
fetchAlerts: () => dispatch(fetchAlerts()), fetchAlerts: () => dispatch(fetchAlerts())
setSidebarExpansion: (isOpen: boolean) => dispatch(setSidebarExpansion(isOpen)),
setSelectedFacility: (facility: IFacility) => dispatch(setSelectedFacility(facility))
}); });
export default connect(mapStateToProps, mapDispatchToProps)(Layout); export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Layout));
...@@ -2,8 +2,6 @@ import { IFacility, CampusRegion } from '../../models/facility.model'; ...@@ -2,8 +2,6 @@ import { IFacility, CampusRegion } from '../../models/facility.model';
import { Action } from 'redux'; import { Action } from 'redux';
export enum UiActionTypes { export enum UiActionTypes {
SET_SIDEBAR_EXPANSION = 'SET_SIDEBAR_EXPANSION',
SET_SELECTED_FACILITY = 'SET_SELECTED_FACILITY',
SET_SEARCH_TERM = 'SET_SEARCH_TERM', SET_SEARCH_TERM = 'SET_SEARCH_TERM',
SET_SELECTED_CAMPUS_REGION = 'SET_SELECTED_CAMPUS_REGION', SET_SELECTED_CAMPUS_REGION = 'SET_SELECTED_CAMPUS_REGION',
ADD_FAVORITE_FACILITY = 'ADD_FAVORITE_FACILITY', ADD_FAVORITE_FACILITY = 'ADD_FAVORITE_FACILITY',
...@@ -11,16 +9,6 @@ export enum UiActionTypes { ...@@ -11,16 +9,6 @@ export enum UiActionTypes {
SET_FAVORITE_FACILITIES = 'SET_FAVORITE_FACILITIES' SET_FAVORITE_FACILITIES = 'SET_FAVORITE_FACILITIES'
} }
export interface SetSidebarExpansion extends Action<UiActionTypes> {
type: UiActionTypes.SET_SIDEBAR_EXPANSION;
isOpen: boolean;
}
export interface SetSelectedFacility extends Action<UiActionTypes> {
type: UiActionTypes.SET_SELECTED_FACILITY;
facility: IFacility;
}
export interface SetSearchTerm extends Action<UiActionTypes> { export interface SetSearchTerm extends Action<UiActionTypes> {
type: UiActionTypes.SET_SEARCH_TERM; type: UiActionTypes.SET_SEARCH_TERM;
searchTerm: string; searchTerm: string;
...@@ -47,8 +35,6 @@ export interface SetFavoriteFacilities extends Action<UiActionTypes> { ...@@ -47,8 +35,6 @@ export interface SetFavoriteFacilities extends Action<UiActionTypes> {
} }
export type UiAction = export type UiAction =
SetSidebarExpansion |
SetSelectedFacility |
SetSearchTerm | SetSearchTerm |
SetSelectedCampusRegion | SetSelectedCampusRegion |
AddFavoriteFacility | AddFavoriteFacility |
......
import { SetSidebarExpansion, UiActionTypes, SetSelectedFacility, SetSelectedCampusRegion, SetSearchTerm, AddFavoriteFacility, RemoveFavoriteFacility, SetFavoriteFacilities } from './ui.action-types'; import { UiActionTypes, SetSelectedCampusRegion, SetSearchTerm, AddFavoriteFacility, RemoveFavoriteFacility, SetFavoriteFacilities } from './ui.action-types';
import { IFacility, CampusRegion } from '../../models/facility.model'; import { CampusRegion } from '../../models/facility.model';
export const setSidebarExpansion = (isOpen: boolean): SetSidebarExpansion => ({
type: UiActionTypes.SET_SIDEBAR_EXPANSION,
isOpen: isOpen
});
export const setSelectedFacility = (facility: IFacility): SetSelectedFacility => ({
type: UiActionTypes.SET_SELECTED_FACILITY,
facility: facility
});
export const setSearchTerm = (searchTerm: string): SetSearchTerm => ({ export const setSearchTerm = (searchTerm: string): SetSearchTerm => ({
type: UiActionTypes.SET_SEARCH_TERM, type: UiActionTypes.SET_SEARCH_TERM,
......
...@@ -7,38 +7,12 @@ export interface SearchBarState { ...@@ -7,38 +7,12 @@ export interface SearchBarState {
campusRegion: CampusRegion; campusRegion: CampusRegion;
} }
export interface SidebarState {
isOpen: boolean;
}
export interface UiState { export interface UiState {
selectedFacility: IFacility | {};
sidebar: SidebarState;
search: SearchBarState; search: SearchBarState;
favorites: string[]; favorites: string[];
} }
const selectedFacilityReducer = (state: IFacility | {} = {}, action: UiAction): IFacility | {} => {
switch (action.type) {
case UiActionTypes.SET_SELECTED_FACILITY:
return action.facility || {};
default:
return state;
}
};
const sidebarReducer = (state: SidebarState = {isOpen: false}, action: UiAction): SidebarState => {
switch (action.type) {
case UiActionTypes.SET_SIDEBAR_EXPANSION: