From 04aeba0c61e0005921b5542504f2ab2f1ba5051b Mon Sep 17 00:00:00 2001 From: SteveGremory Date: Mon, 28 Aug 2023 19:06:44 +0530 Subject: [PATCH] Fixed a bug where the webapp would error out in case there were no previous tasks and the user tried to add one --- app/page.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 4d26790..1b25573 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -208,13 +208,17 @@ export default function Home() { onClose={() => { if (itemType === "task") setTasks((prevTasks) => { - currentItem.key = prevTasks.at(-1)!.key + 1; + currentItem.key = prevTasks.at(-1) + ? prevTasks.at(-1)!.key + 1 + : 0; prevTasks.push(currentItem); return prevTasks; }); else setNotes((prevTasks) => { - currentItem.key = prevTasks.at(-1)!.key + 1; + currentItem.key = prevTasks.at(-1) + ? prevTasks.at(-1)!.key + 1 + : 0; prevTasks.push(currentItem); return prevTasks; });