Deselect message history message when topic selection changes

Fixes #93
This commit is contained in:
Thomas Nordquist
2019-04-15 16:45:58 +02:00
parent d24dc41024
commit 38819b0e0a
5 changed files with 70 additions and 10 deletions

View File

@@ -0,0 +1,44 @@
import * as q from '../../../backend/src/Model'
import { Action } from 'redux'
import { createReducer } from './lib'
import { Record } from 'immutable'
interface SidebarModel {
compareMessage?: q.Message
}
const initialStateFactory = Record<SidebarModel>({
compareMessage: undefined,
})
export type Action = SetCompareMessage
export enum ActionTypes {
SIDEBAR_SET_COMPARE_MESSAGE = 'SIDEBAR_SET_COMPARE_MESSAGE',
SIDEBAR_RESET_STORE = 'SIDEBAR_RESET_STORE',
}
export type SidebarState = Record<SidebarModel>
const actions: {[s: string]: (state: SidebarState, action: Action) => SidebarState} = {
SIDEBAR_SET_COMPARE_MESSAGE: setCompareMessage,
SIDEBAR_RESET_STORE: resetStore,
}
export const sidebarReducer = createReducer(initialStateFactory(), actions)
export interface SetCompareMessage {
type: ActionTypes.SIDEBAR_SET_COMPARE_MESSAGE
message?: q.Message
}
function setCompareMessage(state: SidebarState, action: SetCompareMessage): SidebarState {
return state.set('compareMessage', action.message)
}
export interface ResetStore {
type: ActionTypes.SIDEBAR_RESET_STORE
}
function resetStore(): SidebarState {
return initialStateFactory()
}

View File

@@ -5,6 +5,7 @@ import { GlobalState, globalState } from './Global'
import { publishReducer, PublishState } from './Publish'
import { Record } from 'immutable'
import { settingsReducer, SettingsState } from './Settings'
import { sidebarReducer, SidebarState } from './Sidebar'
import { treeReducer, TreeState } from './Tree'
export interface AppState {
@@ -12,6 +13,7 @@ export interface AppState {
tree: TreeState
settings: Record<SettingsState>,
publish: PublishState
sidebar: SidebarState,
connection: ConnectionState
connectionManager: ConnectionManagerState
}
@@ -19,6 +21,7 @@ export interface AppState {
export default combineReducers({
globalState,
publish: publishReducer,
sidebar: sidebarReducer,
connection: connectionReducer,
settings: settingsReducer,
tree: treeReducer,