From 10f7d0ebbc39c125dba4eced63fbfa6a350ac08b Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 20 Mar 2022 21:26:10 -0400 Subject: [PATCH] fix react error --- src/engine.tsx | 19 +++++++++++++++---- src/ui/React/AlertManager.tsx | 11 ++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/engine.tsx b/src/engine.tsx index 18689a08f..0f52b571c 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -48,6 +48,7 @@ import { calculateAchievements } from "./Achievements/Achievements"; import React from "react"; import { setupUncaughtPromiseHandler } from "./UncaughtPromiseHandler"; +import { Typography } from "@mui/material"; const Engine: { _lastUpdate: number; @@ -401,11 +402,21 @@ const Engine: { () => AlertEvents.emit( <> - Offline for {timeOfflineString}. While you were offline: + Offline for {timeOfflineString}. While you were offline: , ), diff --git a/src/ui/React/AlertManager.tsx b/src/ui/React/AlertManager.tsx index b1d7f5f0f..dd5d28c32 100644 --- a/src/ui/React/AlertManager.tsx +++ b/src/ui/React/AlertManager.tsx @@ -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 && ( - {alerts[0].text} + {typeof alerts[0].text === "string" && {alerts[0].text}} + {typeof alerts[0].text !== "string" && alerts[0].text} )}