From c445df4168b5dd6908589fa4d95ec1f325f9d0c0 Mon Sep 17 00:00:00 2001 From: nickofolas Date: Mon, 3 Jan 2022 21:40:58 -0600 Subject: [PATCH] Allow notifications to be dismissed by clicking --- src/ui/React/Snackbar.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ui/React/Snackbar.tsx b/src/ui/React/Snackbar.tsx index 30f59b2bd..a566767d8 100644 --- a/src/ui/React/Snackbar.tsx +++ b/src/ui/React/Snackbar.tsx @@ -19,16 +19,17 @@ export function SnackbarProvider(props: IProps): React.ReactElement { export const SnackbarEvents = new EventEmitter<[string, "success" | "warning" | "error" | "info", number]>(); export function Snackbar(): React.ReactElement { - const { enqueueSnackbar } = useSnackbar(); + const { enqueueSnackbar, closeSnackbar } = useSnackbar(); useEffect(() => - SnackbarEvents.subscribe((s, variant, duration) => - enqueueSnackbar({s}, { + SnackbarEvents.subscribe((s, variant, duration) => { + const id = enqueueSnackbar({s}, { content: (k, m) => {m}, variant: variant, autoHideDuration: duration, - }), - ), + onClick: () => closeSnackbar(id), + }) + }), ); return <>; }