From 3ac0abc82bd266eecb7c5f468481e364790be665 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Fri, 14 Oct 2022 20:09:11 -0400 Subject: Rewrite toaster hook to not re-create the window (#217) --- frontend/src/components/Toast.tsx | 2 +- frontend/src/toaster.tsx | 37 +++++++++++++------------------------ 2 files changed, 14 insertions(+), 25 deletions(-) (limited to 'frontend/src') diff --git a/frontend/src/components/Toast.tsx b/frontend/src/components/Toast.tsx index 559c37c6..01a436d7 100644 --- a/frontend/src/components/Toast.tsx +++ b/frontend/src/components/Toast.tsx @@ -32,7 +32,7 @@ const Toast: FunctionComponent = ({ toast }) => { return (
{ - const ret = this.node.stateNode.__proto__.render.call(this.node.stateNode, ...args); - if (ret) { - this.instanceRetPatch = afterPatch(ret, 'type', (_: any, ret: any) => { - if (ret?.props?.children[1]?.children?.props) { - const currentToast = ret.props.children[1].children.props.notification; - if (currentToast?.decky) { - if (currentToast == toast) { - ret.props.children[1].children = renderedToast; - } else { - toast = currentToast; - renderedToast = ; - ret.props.children[1].children = renderedToast; - } - } else { - toast = null; - renderedToast = null; - } - } - return ret; - }); + afterPatch(this.node, 'type', (args: any[], ret: any) => { + const currentToast = args[0].notification; + if (currentToast?.decky) { + if (currentToast !== toast) { + toast = currentToast; + renderedToast = ; + } + ret.props.children = renderedToast; + } else { + toast = null; + renderedToast = null; } return ret; - }; - this.node.stateNode.forceUpdate(); + }); this.settingsModule = findModuleChild((m) => { if (typeof m !== 'object') return undefined; for (let prop in m) { -- cgit v1.2.3