1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { connect } from "react-redux";
7 import { RootState } from "~/store/store";
8 import MaterialSnackbar, { SnackbarProps } from "@material-ui/core/Snackbar";
9 import { Dispatch } from "redux";
10 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
12 const mapStateToProps = (state: RootState): SnackbarProps => ({
13 anchorOrigin: { vertical: "bottom", horizontal: "center" },
14 open: state.snackbar.open,
15 message: <span>{state.snackbar.message}</span>,
16 autoHideDuration: state.snackbar.hideDuration
19 const mapDispatchToProps = (dispatch: Dispatch): Pick<SnackbarProps, "onClose"> => ({
20 onClose: (event: any, reason: string) => {
21 if (reason !== "clickaway") {
22 dispatch(snackbarActions.CLOSE_SNACKBAR());
27 export const Snackbar = connect(mapStateToProps, mapDispatchToProps)(MaterialSnackbar);