import cloneObj from '../clone' ; type Actions = { type : string ; id ? : string ; data ? : any ; status ? : boolean ; topicId ? : string ; unreadNotice ? : any ; online ? : any ; tab ? : string ; topicTab ? : string ; } ; const initialState = { online : { connect : 0 , member : 0 , visitor : 0 } , data : { users : 0 , posts : 0 , comments : 0 , replys : 0 } , onlineUserCount : 0 , unreadNotice : [ ] , tab : 'home' , topicTab : '' , notificationPermission : false } ; export default ( state = cloneObj ( initialState ) , action ) => { switch ( action . type ) { case 'SET_ONLINE_STATUS' : state . online = action . online ; break ; case 'SET_UNREAD_NOTICE' : state . unreadNotice = action . unreadNotice ; break ; case 'SET_TOPIC_TAB' : state . topicTab = action . topicTab ; break ; case 'SET_TAB' : if ( action . tab ) state . tab = action . tab ; break ; case 'SET_NOTIFICATION_PERMISSION' : if ( action . status ) state . notificationPermission = action . status ; break ; case 'SET_OPERATING_STATUS' : if ( action . data ) { state . data . posts = action . data . countPosts . count ; state . data . users = action . data . countUsers . count ; state . data . comments = action . data . countComments . count ; state . data . replys = action . data . countReply . count ; } break ; case 'CLEAN' : state . unreadNotice = [ ] ; state . tab = 'home' ; state . topicTab = '' ; break ; default : return state ; } return cloneObj ( state ) ; } ; export const getOnline = ( state ) => state . website . online ; export const getOnlineUserCount = ( state ) => state . website . onlineUserCount ; export const getUnreadNotice = ( state ) => state . website . unreadNotice ; export const getTopicTab = ( state ) => state . website . topicTab ; export const getTab = ( state ) => state . website . tab ; export const getOperatingStatus = ( state ) => state . website . data ;