Merge branch '14149-change-app-bar-layout'
[arvados.git] / src / store / snackbar / snackbar-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { SnackbarAction, snackbarActions } from "./snackbar-actions";
6
7 export interface SnackbarState {
8     message: string;
9     open: boolean;
10     hideDuration: number;
11 }
12
13 const DEFAULT_HIDE_DURATION = 3000;
14
15 const initialState: SnackbarState = {
16     message: "",
17     open: false,
18     hideDuration: DEFAULT_HIDE_DURATION
19 };
20
21 export const snackbarReducer = (state = initialState, action: SnackbarAction) => {
22     return snackbarActions.match(action, {
23         OPEN_SNACKBAR: data => ({ ...initialState, ...data, open: true }),
24         CLOSE_SNACKBAR: () => initialState,
25         default: () => state,
26     });
27 };