fix react error

This commit is contained in:
Olivier Gagnon
2022-03-20 21:26:10 -04:00
parent edb347e566
commit 10f7d0ebbc
2 changed files with 21 additions and 9 deletions
+6 -5
View File
@@ -3,7 +3,7 @@ import { EventEmitter } from "../../utils/EventEmitter";
import { Modal } from "./Modal";
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
import {sha256} from "js-sha256";
import { sha256 } from "js-sha256";
export const AlertEvents = new EventEmitter<[string | JSX.Element]>();
@@ -23,8 +23,8 @@ export function AlertManager(): React.ReactElement {
i++;
setAlerts((old) => {
const hash = getMessageHash(text);
if (old.some(a => a.hash === hash)) {
console.log('Duplicate message');
if (old.some((a) => a.hash === hash)) {
console.log("Duplicate message");
return old;
}
return [
@@ -51,7 +51,7 @@ export function AlertManager(): React.ReactElement {
}, []);
function getMessageHash(text: string | JSX.Element): string {
if (typeof text === 'string') return sha256(text);
if (typeof text === "string") return sha256(text);
return sha256(JSON.stringify(text.props));
}
@@ -66,7 +66,8 @@ export function AlertManager(): React.ReactElement {
{alerts.length > 0 && (
<Modal open={true} onClose={close}>
<Box overflow="scroll" sx={{ overflowWrap: "break-word", whiteSpace: "pre-line" }}>
<Typography>{alerts[0].text}</Typography>
{typeof alerts[0].text === "string" && <Typography>{alerts[0].text}</Typography>}
{typeof alerts[0].text !== "string" && alerts[0].text}
</Box>
</Modal>
)}