Add auto complete
This commit is contained in:
parent
013d5692bf
commit
c65cce9de7
@ -1,4 +1,5 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import AutocompleteInput from "./AutocompleteInput";
|
||||
import {
|
||||
getGroceryLists,
|
||||
createGroceryList,
|
||||
@ -31,6 +32,15 @@ function GroceryLists({ user, onShowToast }) {
|
||||
const [editItems, setEditItems] = useState([]);
|
||||
const [newItem, setNewItem] = useState("");
|
||||
|
||||
// Extract unique items from all lists for autocomplete
|
||||
const uniqueItems = Array.from(
|
||||
new Set(
|
||||
lists.flatMap(list =>
|
||||
list.items.map(item => item.startsWith("✓ ") ? item.substring(2) : item)
|
||||
).filter(Boolean)
|
||||
)
|
||||
).sort();
|
||||
|
||||
useEffect(() => {
|
||||
loadLists();
|
||||
}, []);
|
||||
@ -352,12 +362,18 @@ function GroceryLists({ user, onShowToast }) {
|
||||
<div className="form-group">
|
||||
<label>פריטים</label>
|
||||
<div className="add-item-row">
|
||||
<input
|
||||
<AutocompleteInput
|
||||
type="text"
|
||||
placeholder="הוסף פריט..."
|
||||
value={newItem}
|
||||
onChange={(e) => setNewItem(e.target.value)}
|
||||
onKeyPress={(e) => e.key === "Enter" && (e.preventDefault(), handleAddItem())}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
handleAddItem();
|
||||
}
|
||||
}}
|
||||
suggestions={uniqueItems}
|
||||
/>
|
||||
<button type="button" className="btn primary" onClick={handleAddItem}>
|
||||
הוסף
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user