linking lists with reducer

This commit is contained in:
Tykayn 2025-09-25 17:43:02 +02:00 committed by tykayn
parent c0761da046
commit e9d273c5a2
7 changed files with 101 additions and 27 deletions

View file

@ -9,6 +9,7 @@ import {ChatbotMessage} from '../services/chatbot.message.type';
export enum ActionTypes {
UPDATE_USER = '[User] Update User',
UPDATE_APP = '[App] Update App',
UPDATE_FILTER = '[App] Update Filter',
UPDATE_CONVERSATIONS_LIST = '[Conversations] Update Conversations List',
UPDATE_ACTIVE_CONVERSATION = '[Conversations] Update Active Conversation',
POST_MESSAGE_TO_ACTIVE_CONVERSATION = '[Conversations] Post message to Active Conversation',
@ -58,6 +59,14 @@ export interface UpdateAppAction {
};
}
export interface UpdateFilterAction {
type: ActionTypes.UPDATE_FILTER;
payload: {
name: string;
enabled?: boolean;
};
}
export interface UpdateConversationsListAction {
type: ActionTypes.UPDATE_CONVERSATIONS_LIST;
payload: Array<ChatbotConversation>;
@ -103,6 +112,7 @@ export interface SwitchToNextLanguageAction {
export type AppActions =
| UpdateUserAction
| UpdateAppAction
| UpdateFilterAction
| UpdateConversationsListAction
| UpdateActiveConversationAction
| UpdateConversationPanelAction
@ -168,6 +178,16 @@ function appReducer(state = initialState.app, action: AppActions) {
...state,
...action.payload
};
case ActionTypes.UPDATE_FILTER:
return {
...state,
filters: state.filters.map(f => {
if (f.name !== action.payload.name) return f;
const nextEnabled =
typeof action.payload.enabled === 'boolean' ? action.payload.enabled : !f.enabled;
return { ...f, enabled: nextEnabled };
})
};
case ActionTypes.SWITCH_TO_NEXT_THEME:
// Find the main-button of the current active theme
const currentThemeIndex = state.themesList.indexOf(state.activeTheme);