From f9e8428e40b81ba884e05065012fd5a2d13dc393 Mon Sep 17 00:00:00 2001 From: Tanner Gill Date: Sun, 22 Sep 2024 10:12:59 -0700 Subject: [PATCH] List path is no longer optional where applicable --- src/components/ListItem.tsx | 7 +- src/components/forms/AddItemForm.tsx | 145 ++++++++++++------------- src/views/authenticated/List.tsx | 16 ++- src/views/authenticated/ManageList.tsx | 14 ++- 4 files changed, 94 insertions(+), 88 deletions(-) diff --git a/src/components/ListItem.tsx b/src/components/ListItem.tsx index 09e3b68..df0597f 100644 --- a/src/components/ListItem.tsx +++ b/src/components/ListItem.tsx @@ -6,7 +6,7 @@ import { moreThan24HoursPassed } from "../utils"; interface Props { item: ListItem; - listPath: string | null; + listPath: string; } interface None { kind: "none"; @@ -35,11 +35,6 @@ export function ListItemCheckBox({ item, listPath }: Props) { // Temporarily store the updated check state setUpdatedCheckState({ kind: "set", value: newCheckedState }); - if (!listPath) { - toast.error("Error: listPath is missing or invalid."); - return; - } - try { await toast.promise(updateItem(listPath, item), { loading: `Marking ${item.name} as purchased!`, diff --git a/src/components/forms/AddItemForm.tsx b/src/components/forms/AddItemForm.tsx index a518822..59d17cb 100644 --- a/src/components/forms/AddItemForm.tsx +++ b/src/components/forms/AddItemForm.tsx @@ -6,7 +6,7 @@ import toast from "react-hot-toast"; import { useNavigate } from "react-router-dom"; interface Props { - listPath: string | null; + listPath: string; data: ListItem[]; } @@ -90,82 +90,73 @@ export function AddItemForm({ listPath, data: unfilteredListItems }: Props) { return (
- {listPath && ( - <> -
handleSubmit(e, listPath)}> -

First, add your item!

- -
-

Next, pick when you plan on buying this item again!

-
- When to buy: - -
- -
- -
- -
-

Let's go look at your list!

- - - )} +
handleSubmit(e, listPath)}> +

First, add your item!

+ +
+

Next, pick when you plan on buying this item again!

+
+ When to buy: + +
+ +
+ +
+ +
+

Let's go look at your list!

+
); } diff --git a/src/views/authenticated/List.tsx b/src/views/authenticated/List.tsx index d040a3b..1721aa0 100644 --- a/src/views/authenticated/List.tsx +++ b/src/views/authenticated/List.tsx @@ -44,12 +44,22 @@ export function List({ data: unfilteredListItems, listPath }: Props) { ); } - // Main content when list is not empty - return ( - <> + const Header = () => { + return (

Hello from the /list page!

+ ); + }; + + if (!listPath) { + return
; + } + + // Main content when list is not empty + return ( + <> +
diff --git a/src/views/authenticated/ManageList.tsx b/src/views/authenticated/ManageList.tsx index 881ecaf..9cdd3cf 100644 --- a/src/views/authenticated/ManageList.tsx +++ b/src/views/authenticated/ManageList.tsx @@ -8,11 +8,21 @@ interface Props { } export function ManageList({ listPath, data }: Props) { - return ( -
+ const Header = () => { + return (

Hello from the /manage-list page!

+ ); + }; + + if (!listPath) { + return
; + } + + return ( +
+