From 0d5316bc27f11df30990ce49d4f94e7a74018841 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 2 Jan 2026 17:00:48 -0800 Subject: [PATCH] fix add item formatting and suggestion loigic --- frontend/src/components/forms/AddItemForm.jsx | 95 +++++++--- .../src/components/items/SuggestionList.tsx | 7 +- frontend/src/pages/GroceryList.jsx | 37 ++-- .../src/styles/components/AddItemForm.css | 172 ++++++++++++++++++ frontend/src/styles/pages/GroceryList.css | 4 +- frontend/src/styles/theme.css | 2 + 6 files changed, 268 insertions(+), 49 deletions(-) create mode 100644 frontend/src/styles/components/AddItemForm.css diff --git a/frontend/src/components/forms/AddItemForm.jsx b/frontend/src/components/forms/AddItemForm.jsx index cd26d02..6f889eb 100644 --- a/frontend/src/components/forms/AddItemForm.jsx +++ b/frontend/src/components/forms/AddItemForm.jsx @@ -1,7 +1,8 @@ import { useState } from "react"; +import "../../styles/components/AddItemForm.css"; import SuggestionList from "../items/SuggestionList"; -export default function AddItemForm({ onAdd, onSuggest, suggestions, buttonText = "Add Item" }) { +export default function AddItemForm({ onAdd, onSuggest, suggestions, buttonText = "Add" }) { const [itemName, setItemName] = useState(""); const [quantity, setQuantity] = useState(1); const [showSuggestions, setShowSuggestions] = useState(false); @@ -23,38 +24,76 @@ export default function AddItemForm({ onAdd, onSuggest, suggestions, buttonText const handleSuggestionSelect = (suggestion) => { setItemName(suggestion); setShowSuggestions(false); + onSuggest(suggestion); // Trigger button text update }; + const incrementQuantity = () => { + setQuantity(prev => prev + 1); + }; + + const decrementQuantity = () => { + setQuantity(prev => Math.max(1, prev - 1)); + }; + + const isDisabled = !itemName.trim(); + return ( -
- handleInputChange(e.target.value)} - onBlur={() => setTimeout(() => setShowSuggestions(false), 150)} - onClick={() => setShowSuggestions(true)} - /> +
+ +
+ handleInputChange(e.target.value)} + onBlur={() => setTimeout(() => setShowSuggestions(false), 150)} + onClick={() => setShowSuggestions(true)} + /> - {showSuggestions && suggestions.length > 0 && ( - - )} + {showSuggestions && suggestions.length > 0 && ( + + )} +
- setQuantity(Number(e.target.value))} - /> +
+
+ + + +
- - + +
+ +
); } diff --git a/frontend/src/components/items/SuggestionList.tsx b/frontend/src/components/items/SuggestionList.tsx index fc52eaa..d79791a 100644 --- a/frontend/src/components/items/SuggestionList.tsx +++ b/frontend/src/components/items/SuggestionList.tsx @@ -1,3 +1,5 @@ +import React from "react"; + interface Props { suggestions: string[]; onSelect: (value: string) => void; @@ -8,15 +10,12 @@ export default function SuggestionList({ suggestions, onSelect }: Props) { return (