import { Set , Map } from "immutable" ; import { AnyAction } from "redux" ; import { newsroomActions } from "../actionCreators/newsrooms" ; import { EthAddress , StorageHeader , EthContentHeader , ContentData } from "@joincivil/typescript-types" ; export function currentUserNewsrooms ( state = Set < string > ( ) , action ) { switch ( action . type ) { case newsroomActions . ADD_USER_NEWSROOM : return state . add ( action . data ) ; default : return state ; } } export function contentFetched ( state = Map < string , StorageHeader > ( ) , action ) { switch ( action . type ) { case newsroomActions . FETCH_CONTENT : const key = action . data . uri ; return state . set ( key , action . data ) ; default : return state ; } } export function content ( state = Map < string , ContentData > ( ) , action ) { switch ( action . type ) { case newsroomActions . ADD_CONTENT : return state . set ( action . data . header . uri , action . data . content ) ; default : return state ; } } export function charterRevisions ( state = Map < EthAddress , Map < number , EthContentHeader > > ( ) , action ) { switch ( action . type ) { case newsroomActions . ADD_CHARTER_REVISION : const { address , revisionId , header } = action . data ; let newsroomContentRevisions = state . get ( address ) ; if ( ! newsroomContentRevisions ) { newsroomContentRevisions = Map < number , EthContentHeader > ( ) ; } if ( header . uri ) { return state . set ( address , newsroomContentRevisions . set ( revisionId , header ) ) ; } return state ; default : return state ; } }