Add auto complete
This commit is contained in:
parent
013d5692bf
commit
c65cce9de7
@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import AutocompleteInput from "./AutocompleteInput";
|
||||||
import {
|
import {
|
||||||
getGroceryLists,
|
getGroceryLists,
|
||||||
createGroceryList,
|
createGroceryList,
|
||||||
@ -31,6 +32,15 @@ function GroceryLists({ user, onShowToast }) {
|
|||||||
const [editItems, setEditItems] = useState([]);
|
const [editItems, setEditItems] = useState([]);
|
||||||
const [newItem, setNewItem] = 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(() => {
|
useEffect(() => {
|
||||||
loadLists();
|
loadLists();
|
||||||
}, []);
|
}, []);
|
||||||
@ -352,12 +362,18 @@ function GroceryLists({ user, onShowToast }) {
|
|||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label>פריטים</label>
|
<label>פריטים</label>
|
||||||
<div className="add-item-row">
|
<div className="add-item-row">
|
||||||
<input
|
<AutocompleteInput
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="הוסף פריט..."
|
placeholder="הוסף פריט..."
|
||||||
value={newItem}
|
value={newItem}
|
||||||
onChange={(e) => setNewItem(e.target.value)}
|
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}>
|
<button type="button" className="btn primary" onClick={handleAddItem}>
|
||||||
הוסף
|
הוסף
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user