1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { SnackbarAction, snackbarActions, SnackbarKind, SnackbarMessage } from "./snackbar-actions";
7 export interface SnackbarState {
8 messages: SnackbarMessage[];
12 const DEFAULT_HIDE_DURATION = 3000;
14 const initialState: SnackbarState = {
19 export const snackbarReducer = (state = initialState, action: SnackbarAction) => {
20 return snackbarActions.match(action, {
21 OPEN_SNACKBAR: data => {
24 messages: state.messages.concat({
25 message: data.message,
26 hideDuration: data.hideDuration ? data.hideDuration : DEFAULT_HIDE_DURATION,
27 kind: data.kind ? data.kind : SnackbarKind.INFO,
32 CLOSE_SNACKBAR: () => ({
36 SHIFT_MESSAGES: () => {
37 const messages = state.messages.filter((m, idx) => idx > 0);
39 open: messages.length > 0,