Merge pull request #2335 from nickofolas/clickaway-notifications

Allow notifications to be dismissed by clicking
This commit is contained in:
hydroflame 2022-01-04 19:03:05 -05:00 committed by GitHub
commit f2fa7a3c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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(<Alert severity={variant}>{s}</Alert>, {
SnackbarEvents.subscribe((s, variant, duration) => {
const id = enqueueSnackbar(<Alert severity={variant}>{s}</Alert>, {
content: (k, m) => <Paper key={k}>{m}</Paper>,
variant: variant,
autoHideDuration: duration,
onClick: () => closeSnackbar(id),
})
}),
),
);
return <></>;
}