/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import Slide, { SlideProps } from '@mui/material/Slide';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertColor as Severity } from '@mui/material/Alert';
import { createRoot, Root } from 'react-dom/client';
function removeToast(root: Root) {
root.unmount();
}
function Transition(props: SlideProps) {
return ;
}
interface IToastProps {
message: string;
severity: Severity;
}
export function Toast(props: IToastProps) {
const { message, severity } = props;
const [open, setOpen] = React.useState(true);
const handleClose = () => {
setOpen(false);
};
return (
{message}
);
}
export function makeToast(message: string, severity: Severity) {
const id = Math.floor(Math.random() * 1000);
const container = document.createElement('div');
container.id = `alert-${id}`;
document.body.appendChild(container);
const root = createRoot(container!);
root.render();
setTimeout(() => removeToast(root), 3500);
}
export function makeToaster([toasts, setToasts]: [React.ReactElement[], (arg0: React.ReactElement[]) => void]): [
React.ReactElement[],
(message: string, severity: Severity) => void,
] {
return [
toasts,
(message: string, severity: Severity) => {
setToasts([]);
},
];
}