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

@ -48,6 +48,7 @@ import { calculateAchievements } from "./Achievements/Achievements";
import React from "react"; import React from "react";
import { setupUncaughtPromiseHandler } from "./UncaughtPromiseHandler"; import { setupUncaughtPromiseHandler } from "./UncaughtPromiseHandler";
import { Typography } from "@mui/material";
const Engine: { const Engine: {
_lastUpdate: number; _lastUpdate: number;
@ -401,11 +402,21 @@ const Engine: {
() => () =>
AlertEvents.emit( AlertEvents.emit(
<> <>
Offline for {timeOfflineString}. While you were offline: <Typography>Offline for {timeOfflineString}. While you were offline:</Typography>
<ul> <ul>
<li>Your scripts generated{" "} <Money money={offlineHackingIncome} /></li> <li>
<li>Your Hacknet Nodes generated {hacknetProdInfo}</li> <Typography>
<li>You gained{" "} <Reputation reputation={offlineReputation} /> reputation divided amongst your factions</li> Your scripts generated <Money money={offlineHackingIncome} />
</Typography>
</li>
<li>
<Typography>Your Hacknet Nodes generated {hacknetProdInfo}</Typography>
</li>
<li>
<Typography>
You gained <Reputation reputation={offlineReputation} /> reputation divided amongst your factions
</Typography>
</li>
</ul> </ul>
</>, </>,
), ),

@ -3,7 +3,7 @@ import { EventEmitter } from "../../utils/EventEmitter";
import { Modal } from "./Modal"; import { Modal } from "./Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import {sha256} from "js-sha256"; import { sha256 } from "js-sha256";
export const AlertEvents = new EventEmitter<[string | JSX.Element]>(); export const AlertEvents = new EventEmitter<[string | JSX.Element]>();
@ -23,8 +23,8 @@ export function AlertManager(): React.ReactElement {
i++; i++;
setAlerts((old) => { setAlerts((old) => {
const hash = getMessageHash(text); const hash = getMessageHash(text);
if (old.some(a => a.hash === hash)) { if (old.some((a) => a.hash === hash)) {
console.log('Duplicate message'); console.log("Duplicate message");
return old; return old;
} }
return [ return [
@ -51,7 +51,7 @@ export function AlertManager(): React.ReactElement {
}, []); }, []);
function getMessageHash(text: string | JSX.Element): string { 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)); return sha256(JSON.stringify(text.props));
} }
@ -66,7 +66,8 @@ export function AlertManager(): React.ReactElement {
{alerts.length > 0 && ( {alerts.length > 0 && (
<Modal open={true} onClose={close}> <Modal open={true} onClose={close}>
<Box overflow="scroll" sx={{ overflowWrap: "break-word", whiteSpace: "pre-line" }}> <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> </Box>
</Modal> </Modal>
)} )}