github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/settingsReducer.ts (about) 1 import { 2 DAILY_STATS_KEY_CHANGE, 3 POLL_INTERVAL_CHANGE, 4 SettingsActionTypes, 5 TASK_ROWS_PER_PAGE_CHANGE, 6 THEME_PREFERENCE_CHANGE, 7 TOGGLE_DRAWER, 8 } from "../actions/settingsActions"; 9 import { defaultPageSize } from "../components/TablePaginationActions" 10 import { DailyStatsKey, defaultDailyStatsKey } from "../views/DashboardView"; 11 12 export enum ThemePreference { 13 SystemDefault, 14 Always, 15 Never, 16 } 17 18 export interface SettingsState { 19 // Time duration between data refresh. 20 pollInterval: number; 21 22 // UI theme setting. 23 themePreference: ThemePreference; 24 25 // Whether the drawer (i.e. sidebar) is open or not. 26 isDrawerOpen: boolean; 27 28 // Number of tasks displayed in task table. 29 taskRowsPerPage: number, 30 31 // Type of the chart displayed for "Processed Tasks" section in dashboard. 32 dailyStatsChartType: DailyStatsKey; 33 } 34 35 export const initialState: SettingsState = { 36 pollInterval: 8, 37 themePreference: ThemePreference.SystemDefault, 38 isDrawerOpen: true, 39 taskRowsPerPage: defaultPageSize, 40 dailyStatsChartType: defaultDailyStatsKey, 41 }; 42 43 function settingsReducer( 44 state = initialState, 45 action: SettingsActionTypes 46 ): SettingsState { 47 switch (action.type) { 48 case POLL_INTERVAL_CHANGE: 49 return { 50 ...state, 51 pollInterval: action.value, 52 }; 53 54 case THEME_PREFERENCE_CHANGE: 55 return { 56 ...state, 57 themePreference: action.value, 58 }; 59 60 case TOGGLE_DRAWER: 61 return { 62 ...state, 63 isDrawerOpen: !state.isDrawerOpen, 64 }; 65 66 case TASK_ROWS_PER_PAGE_CHANGE: 67 return { 68 ...state, 69 taskRowsPerPage: action.value, 70 } 71 72 case DAILY_STATS_KEY_CHANGE: 73 return { 74 ...state, 75 dailyStatsChartType: action.value, 76 } 77 78 default: 79 return state; 80 } 81 } 82 83 export default settingsReducer;