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: (payload) => {
33 let newMessages: any = [...state.messages];// state.messages.filter(({ message }) => message !== payload);
35 if (payload === undefined || JSON.stringify(payload) === '{}') {
38 newMessages = state.messages.filter((message, index) => index !== payload);
43 messages: newMessages,
44 open: newMessages.length > 0
47 SHIFT_MESSAGES: () => {
48 const messages = state.messages.filter((m, idx) => idx > 0);
50 open: messages.length > 0,