From 62b9b98ad5d8ddf6c876a36899e9a36ad340d14e Mon Sep 17 00:00:00 2001 From: RossaMania Date: Wed, 4 Sep 2024 23:19:46 -0500 Subject: [PATCH] feat: Refactor list view components by adding prompts to the different forms. Conditionally render buttons to go to and from the "/list" and the "/manage-list" views. Add navigation functionality with useNavigate hook. Co-authored-by: Falak --- src/views/authenticated/List.tsx | 41 +++++++++++++++++++++++--- src/views/authenticated/ManageList.tsx | 11 +++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/views/authenticated/List.tsx b/src/views/authenticated/List.tsx index 9676c5d..e04abc1 100644 --- a/src/views/authenticated/List.tsx +++ b/src/views/authenticated/List.tsx @@ -2,12 +2,15 @@ import { useState, useMemo } from "react"; import { ListItem as ListItemComponent } from "../../components/ListItem"; import { FilterListInput as FilterListComponent } from "../../components/FilterListInput"; import { ListItem } from "../../api"; +import { useNavigate } from "react-router-dom"; interface Props { data: ListItem[]; } export function List({ data: unfilteredListItems }: Props) { + const navigate = useNavigate(); + const [searchTerm, setSearchTerm] = useState(""); const filteredListItems = useMemo(() => { @@ -16,17 +19,47 @@ export function List({ data: unfilteredListItems }: Props) { ); }, [searchTerm, unfilteredListItems]); + const handleAddItemsClick = () => { + navigate("/manage-list"); + }; + return ( <>

Hello from the /list page!

+ {unfilteredListItems.length === 0 && ( +
+

Your list is ready!

+

+ It looks like you haven’t added any items yet. +
+ Let’s get started by adding your first item. +

+ +
+ )} + {unfilteredListItems.length > 0 && ( - +
+ +

Want to add more items to your list?

+ +
)}
    diff --git a/src/views/authenticated/ManageList.tsx b/src/views/authenticated/ManageList.tsx index 18a7dc8..81637a6 100644 --- a/src/views/authenticated/ManageList.tsx +++ b/src/views/authenticated/ManageList.tsx @@ -3,6 +3,7 @@ import { addItem } from "../../api"; import { validateTrimmedString } from "../../utils"; import toast from "react-hot-toast"; +import { useNavigate } from "react-router-dom"; import ShareListForm from "../../components/forms/ShareListForm"; interface Props { @@ -22,6 +23,8 @@ const purchaseTimelines = { }; export function ManageList({ listPath }: Props) { + const navigate = useNavigate(); + const [itemName, setItemName] = useState(""); const [itemNextPurchaseTimeline, setItemNextPurchaseTimeline] = useState( PurchaseTime.soon, @@ -78,6 +81,10 @@ export function ManageList({ listPath }: Props) { } }; + const navigateToListPage = () => { + navigate("/list"); + }; + return (

    @@ -86,6 +93,7 @@ export function ManageList({ listPath }: Props) { {listPath && ( <>

    handleSubmit(e, listPath)}> +

    First, add your item!


    +

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

    When to buy: