mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 04:47:03 +02:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import React, { useEffect } from "react";
|
|
import { useSnackbar, SnackbarProvider as SB } from "notistack";
|
|
import { EventEmitter } from "../../utils/EventEmitter";
|
|
import Alert from "@mui/material/Alert";
|
|
import Paper from "@mui/material/Paper";
|
|
|
|
interface IProps {
|
|
children: React.ReactNode | React.ReactNode[];
|
|
}
|
|
|
|
export function SnackbarProvider(props: IProps): React.ReactElement {
|
|
return (
|
|
<SB dense maxSnack={9} anchorOrigin={{ horizontal: "right", vertical: "bottom" }} autoHideDuration={2000}>
|
|
{props.children}
|
|
</SB>
|
|
);
|
|
}
|
|
|
|
export const SnackbarEvents = new EventEmitter<[string, "success" | "warning" | "error" | "info"]>();
|
|
|
|
export function Snackbar(): React.ReactElement {
|
|
const { enqueueSnackbar } = useSnackbar();
|
|
|
|
useEffect(() =>
|
|
SnackbarEvents.subscribe((s, variant) =>
|
|
enqueueSnackbar(<Alert severity={variant}>{s}</Alert>, {
|
|
content: (k, m) => <Paper key={k}>{m}</Paper>,
|
|
variant: variant,
|
|
}),
|
|
),
|
|
);
|
|
return <></>;
|
|
// return (
|
|
// <S
|
|
// open={open}
|
|
// anchorOrigin={{
|
|
// vertical: "top",
|
|
// horizontal: "center",
|
|
// }}
|
|
// autoHideDuration={2000}
|
|
// onClose={() => setOpen(false)}
|
|
// >
|
|
// <Paper sx={{ p: 2 }}>
|
|
// <Typography>Game Saved!</Typography>
|
|
// </Paper>
|
|
// </S>
|
|
// );
|
|
}
|