From d91adaa005f7a4b68abf42d1d69beffa88ef3fbf Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 18 Apr 2024 13:11:13 +0200 Subject: [PATCH] Make invite errors crash things less --- src/App.js | 6 ++++++ src/CreateInviteModal.js | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 09cf2e1..1ab0e0b 100644 --- a/src/App.js +++ b/src/App.js @@ -16,6 +16,7 @@ function App() { const [excalidrawAPI, setExcalidrawAPI] = useState(null) const [inviteCode, setInviteCode] = useState(null) + const [inviteErr, setInviteErr] = useState(null) const [inviteModalOpen, setInviteModalOpen] = useState(false) const openInviteModal = () => setInviteModalOpen(true) @@ -45,7 +46,11 @@ function App() { setInviteCode(null) openInviteModal() window.electronAPI.createInvite().then((invite) => { + setInviteErr(null) setInviteCode(invite) + }).catch(err => { + setInviteCode(null) + setInviteErr(err) }) } @@ -102,6 +107,7 @@ function App() { isOpen={inviteModalOpen} onClose={closeInviteModal} inviteCode={inviteCode} + inviteErr={inviteErr} /> diff --git a/src/CreateInviteModal.js b/src/CreateInviteModal.js index 0b44c6b..f7db91f 100644 --- a/src/CreateInviteModal.js +++ b/src/CreateInviteModal.js @@ -1,7 +1,7 @@ import Button from './Button' import Modal from './Modal' -function CreateInviteModal({ isOpen, onClose, inviteCode }) { +function CreateInviteModal({ isOpen, onClose, inviteCode, inviteErr }) { const copyInviteToClipboard = () => { window.electronAPI.copyToClipboard(inviteCode).then(() => { onClose() @@ -20,7 +20,12 @@ function CreateInviteModal({ isOpen, onClose, inviteCode }) { return ( - {inviteCode ? ( + {inviteErr ? ( + <> +
Got an error when creating the invite:
+
{inviteErr.toString()}
+ + ) : inviteCode ? ( <> This is an invite code that you can send to a friend to collaborate on this drawing with you.