import { Query , parseQueryToQueryString } from '../models' ; import * as mediaWallAction from '../actions/media-wall-query' ; import * as wallPaginationAction from '../actions/media-wall-pagination' ; export interface State { query : Query ; } export const initialState = { query : { displayString : '' , queryString : '' , routerString : '' , filter : { video : false , image : false } , location : null , timeBound : { since : null , until : null } , from : false } } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case mediaWallAction . ActionTypes . WALL_VALUE_CHANGE : { const query = action . payload ; return Object . assign ( { } , state , { query : { ... state . query , displayString : query } } ) ; } case mediaWallAction . ActionTypes . WALL_QUERY_CHANGE : { const queryPayload = action . payload ; if ( queryPayload ) { const query = Object . assign ( { } , queryPayload , { ... queryPayload , queryString : parseQueryToQueryString ( queryPayload ) } ) ; return Object . assign ( { } , state , { query } ) ; } else { return Object . assign ( { } , state , { query : { ... state . query , queryString : parseQueryToQueryString ( state . query ) , routerString : state . query . displayString } } ) ; } } default : { return state ; } } } export const getMediaWallQuery = ( state ) => state . query ;