From c69639b15ec1ea42159fa0371aa6f8e3d37d18b0 Mon Sep 17 00:00:00 2001 From: nemsys Date: Sun, 18 Oct 2026 05:26:11 +0300 Subject: [PATCH 1/4] feat: name field that lists existing look-alike entries Shared by the add-box and add-item forms so both warn about duplicates the same way, with the combobox mechanics BoxPicker already uses. Model: claude-opus-5-5 (effort=high) Assisted-by: claude-opus-5-5 --- src/components/NameInputWithMatches.jsx | 178 ++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/components/NameInputWithMatches.jsx diff --git a/src/components/NameInputWithMatches.jsx b/src/components/NameInputWithMatches.jsx new file mode 100644 index 0000000..823f589 --- /dev/null +++ b/src/components/NameInputWithMatches.jsx @@ -0,0 +1,178 @@ +import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'; +import Fuse from 'fuse.js'; +import { Package, ChevronRight } from 'lucide-react'; +import { useBackHandler } from '../native/backHandler'; +import { getImageRefs, refsToThumbs } from '../utils/imageUtils'; + +const MIN_QUERY = 2; +const MAX_MATCHES = 5; + +/** + * The name field of a create form, with the existing boxes or items whose + * names look like what is being typed listed under it, so "Зимно яке" is + * opened rather than created a second time. + * + * A hint, not a gate: the form's own button still creates, and Enter still + * submits unless the arrows have reached a row first. Not an autocomplete + * either, which is why the list is headed by `heading` ("you already have") + * and a pick opens the existing entry instead of filling in the field. + * + * Fuzzy on the name only, so a typo still finds the duplicate; + * `ignoreLocation` because a long name is as likely to match in the middle as + * at the start. Combobox mechanics follow BoxPicker. + */ +export function NameInputWithMatches({ + label, + value, + onChange, + placeholder, + candidates = [], + heading, + renderLabel, + onPick, +}) { + const id = useId(); + const wrapRef = useRef(null); + const listRef = useRef(null); + const [focused, setFocused] = useState(false); + const [dismissed, setDismissed] = useState(false); + // -1 = nothing highlighted, so Enter submits the form as before. Only the + // arrows move it (no hover tracking, unlike BoxPicker): a pointer resting + // on a row must not turn Enter into "open this one". + const [active, setActive] = useState(-1); + + const fuse = useMemo( + () => new Fuse(candidates, { keys: ['name'], threshold: 0.3, ignoreLocation: true }), + [candidates] + ); + + const q = value.trim(); + const matches = useMemo( + () => (q.length >= MIN_QUERY ? fuse.search(q, { limit: MAX_MATCHES }).map(r => r.item) : []), + [q, fuse] + ); + + const open = focused && !dismissed && matches.length > 0; + + const close = useCallback(() => { + setDismissed(true); + setActive(-1); + }, []); + + // Android Back closes the list before it closes the modal. + useBackHandler(open, close); + + // Keep the highlighted row in view, scrolling the list only, not the + // modal behind it, which would jump under the keyboard. + useEffect(() => { + const list = listRef.current; + const row = list?.querySelector(`[data-index="${active}"]`); + if (!row) return; + if (row.offsetTop < list.scrollTop) { + list.scrollTop = row.offsetTop; + } else if (row.offsetTop + row.offsetHeight > list.scrollTop + list.clientHeight) { + list.scrollTop = row.offsetTop + row.offsetHeight - list.clientHeight; + } + }, [active, open]); + + const handleKeyDown = (e) => { + if (e.nativeEvent.isComposing) return; + if (e.key === 'ArrowDown') { + if (!matches.length) return; + e.preventDefault(); + setDismissed(false); + setActive(i => (open ? Math.min(i + 1, matches.length - 1) : 0)); + } else if (e.key === 'ArrowUp' && open) { + e.preventDefault(); + setActive(i => Math.max(i - 1, -1)); + } else if (e.key === 'Enter' && open && matches[active]) { + e.preventDefault(); + onPick(matches[active]); + } else if (e.key === 'Escape' && open) { + // Stop here, or the modal's Escape listener closes the whole form. + e.preventDefault(); + e.stopPropagation(); + close(); + } + }; + + const optionId = (index) => `${id}-opt-${index}`; + + return ( +
setFocused(true)} + onBlur={(e) => { + if (!wrapRef.current?.contains(e.relatedTarget)) { + setFocused(false); + setActive(-1); + } + }} + > + + { + onChange(e.target.value); + setDismissed(false); + setActive(-1); + }} + onKeyDown={handleKeyDown} + className="input" + placeholder={placeholder} + /> + + {open && ( +
e.preventDefault()} + > + + {matches.map((entry, index) => { + const thumb = refsToThumbs(getImageRefs(entry))[0]; + return ( +
onPick(entry)} + className={`picker-row cursor-pointer ${index === active ? 'box-picker__row--active' : ''}`} + > + {thumb ? ( + + ) : ( + + + + )} + {renderLabel(entry)} +
+ ); + })} +
+ )} +
+ ); +} From 5845567e12e27304dce3227d44201af8e5b9e0f3 Mon Sep 17 00:00:00 2001 From: nemsys Date: Sun, 18 Oct 2026 05:29:11 +0300 Subject: [PATCH 2/4] feat: show existing look-alike items while naming a new one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Зимно яке" typed again used to become a second record; now the existing one is listed under the name and opens in its edit form, where it can be moved, instead. Model: claude-opus-5-5 (effort=high) Assisted-by: claude-opus-5-5 --- src/App.jsx | 1 + src/components/AddItemModal.jsx | 36 ++++++++++++++++--------- src/components/NameInputWithMatches.jsx | 5 ++-- src/translations/bg.json | 4 +++ src/translations/en.json | 4 +++ src/translations/terms.bg.json | 3 ++- src/translations/terms.en.json | 3 ++- 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index e51bf2e..416182b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -2138,6 +2138,7 @@ function App() { availableItems={allItems} availableTags={tagSuggestions} onSelectExisting={handleSelectExistingItem} + onOpenExisting={handleEditItem} askConfirm={askConfirm} /> diff --git a/src/components/AddItemModal.jsx b/src/components/AddItemModal.jsx index 672d08b..74b7022 100644 --- a/src/components/AddItemModal.jsx +++ b/src/components/AddItemModal.jsx @@ -5,6 +5,7 @@ import { CameraCaptureModal } from './CameraCaptureModal'; import { FullscreenImageModal } from './FullscreenImageModal'; import { TagInput } from './TagInput'; import { BoxPicker } from './BoxPicker'; +import { NameInputWithMatches } from './NameInputWithMatches'; import { Upload, Trash2, Search, Camera, Package, X, Check } from 'lucide-react'; import { makeDerivatives, refsToThumbs, getImageRefs } from '../utils/imageUtils'; import { useModalDraft, clearDraft } from '../utils/draftStorage'; @@ -12,7 +13,7 @@ import { usePhotoCapture } from '../native/usePhotoCapture'; import { useTranslation } from '../translations'; import { parseTagInput } from '../utils/tagUtils'; -export function AddItemModal({ isOpen, onClose, onAdd, boxes = [], initialBoxId = '', availableItems = [], availableTags = [], onSelectExisting, askConfirm }) { +export function AddItemModal({ isOpen, onClose, onAdd, boxes = [], initialBoxId = '', availableItems = [], availableTags = [], onSelectExisting, onOpenExisting, askConfirm }) { const { t, lang } = useTranslation(); const [mode, setMode] = useState('create'); // 'create' | 'select' const [name, setName] = useState(''); @@ -66,6 +67,13 @@ export function AddItemModal({ isOpen, onClose, onAdd, boxes = [], initialBoxId if (typeof onClose === 'function') onClose(); }; + // The thing being typed already exists: open it (where it can also be + // moved to this box) instead of filing a second one. + const handleOpenExisting = (item) => { + handleClose(); + if (typeof onOpenExisting === 'function') onOpenExisting(item); + }; + // Filter items that can be selected (exclude items already in current box) const selectableItems = useMemo(() => { return availableItems.filter(item => item.boxId !== initialBoxId); @@ -228,17 +236,21 @@ export function AddItemModal({ isOpen, onClose, onAdd, boxes = [], initialBoxId {/* Create New Mode */} {mode === 'create' && (
-
- - setName(e.target.value)} - className="input" - placeholder={t('item.namePlaceholder')} - /> -
+ t('item.existingMatches', { count })} + renderLabel={(item) => ( + <> + {item.name} + {getBoxName(item.boxId)} + + )} + onPick={handleOpenExisting} + /> diff --git a/src/components/NameInputWithMatches.jsx b/src/components/NameInputWithMatches.jsx index 823f589..cae75d9 100644 --- a/src/components/NameInputWithMatches.jsx +++ b/src/components/NameInputWithMatches.jsx @@ -16,6 +16,7 @@ const MAX_MATCHES = 5; * submits unless the arrows have reached a row first. Not an autocomplete * either, which is why the list is headed by `heading` ("you already have") * and a pick opens the existing entry instead of filling in the field. + * `heading` is a function of the number of matches, for the plural. * * Fuzzy on the name only, so a typo still finds the duplicate; * `ignoreLocation` because a long name is as likely to match in the middle as @@ -138,14 +139,14 @@ export function NameInputWithMatches({ ref={listRef} id={`${id}-list`} role="listbox" - aria-label={heading} + aria-label={heading(matches.length)} className="box-picker__list" // Keep focus where it is: a tap on a row must not blur the // field (and close the list) before the click lands. onPointerDown={(e) => e.preventDefault()} > {matches.map((entry, index) => { const thumb = refsToThumbs(getImageRefs(entry))[0]; diff --git a/src/translations/bg.json b/src/translations/bg.json index b5b6704..3ec98af 100644 --- a/src/translations/bg.json +++ b/src/translations/bg.json @@ -75,6 +75,8 @@ "box.edit": "Редактирай {{box.the}}", "box.editAria": "Редактирай {{name}}", "box.namePlaceholder": "напр. Инструменти от гаража", + "box.existingMatches_one": "Вече имаш {{box.similar}} {{box.one}}:", + "box.existingMatches_other": "Вече имаш подобни {{box.many}}:", "box.descriptionPlaceholder": "Какво има в {{box.the}}?", "box.actions": "Действия с {{box.the}}", "box.removeKeepItems": "Премахни (запази {{item.theMany}})", @@ -114,6 +116,8 @@ "item.editAria": "Редактирай {{name}}", "item.actions": "Действия с {{item.the}}", "item.namePlaceholder": "напр. Чук", + "item.existingMatches_one": "Вече имаш {{item.similar}} {{item.one}}:", + "item.existingMatches_other": "Вече имаш подобни {{item.many}}:", "item.descriptionPlaceholder": "Подробности за {{item.the}}...", "item.tagsPlaceholder": "инструмент, тежко, метал...", "item.tagsHint": "Докосни, за да добавиш", diff --git a/src/translations/en.json b/src/translations/en.json index 2df1faa..5f45207 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -75,6 +75,8 @@ "box.edit": "Edit {{^box.one}}", "box.editAria": "Edit {{name}}", "box.namePlaceholder": "e.g., Garage Tools", + "box.existingMatches_one": "You already have a {{box.similar}} {{box.one}}:", + "box.existingMatches_other": "You already have {{box.similar}} {{box.many}}:", "box.descriptionPlaceholder": "What's in this {{box.one}}?", "box.actions": "{{^box.one}} actions", "box.removeKeepItems": "Remove (keep {{item.many}})", @@ -114,6 +116,8 @@ "item.editAria": "Edit {{name}}", "item.actions": "{{^item.one}} actions", "item.namePlaceholder": "e.g., Hammer", + "item.existingMatches_one": "You already have a {{item.similar}} {{item.one}}:", + "item.existingMatches_other": "You already have {{item.similar}} {{item.many}}:", "item.descriptionPlaceholder": "Details about the {{item.one}}...", "item.tagsPlaceholder": "tool, heavy, metal...", "item.tagsHint": "Tap chips to add", diff --git a/src/translations/terms.bg.json b/src/translations/terms.bg.json index 9ec6767..50ba479 100644 --- a/src/translations/terms.bg.json +++ b/src/translations/terms.bg.json @@ -22,6 +22,7 @@ "optimized": { "m": "оптимизиран", "f": "оптимизирана", "n": "оптимизирано" }, "found": { "m": "намерен", "f": "намерена", "n": "намерено" }, "previous": { "m": "предишен", "f": "предишна", "n": "предишно" }, - "next": { "m": "следващ", "f": "следваща", "n": "следващо" } + "next": { "m": "следващ", "f": "следваща", "n": "следващо" }, + "similar": { "m": "подобен", "f": "подобна", "n": "подобно" } } } diff --git a/src/translations/terms.en.json b/src/translations/terms.en.json index 2b08529..0f140b7 100644 --- a/src/translations/terms.en.json +++ b/src/translations/terms.en.json @@ -22,6 +22,7 @@ "optimized": "Optimized", "found": "found", "previous": "previous", - "next": "next" + "next": "next", + "similar": "similar" } } From 9485e09a2d0611d6f629e47034ba40365f09190c Mon Sep 17 00:00:00 2001 From: nemsys Date: Sun, 18 Oct 2026 05:30:04 +0300 Subject: [PATCH 3/4] feat: show existing look-alike boxes while naming a new one A box that already exists under a similar name is listed under the field and opens directly, so the same box is not created twice. Model: claude-opus-5-5 (effort=high) Assisted-by: claude-opus-5-5 --- src/App.jsx | 2 ++ src/components/AddBoxModal.jsx | 38 +++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 416182b..7a2aab5 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -2127,6 +2127,8 @@ function App() { askConfirm={askConfirm} knownLocations={knownLocations} availableTags={tagSuggestions} + boxes={boxes} + onOpenExisting={handleBoxClick} /> { + handleClose(); + if (typeof onOpenExisting === 'function') onOpenExisting(box); + }; + const handleFileChange = async (e) => { // Capture the firing input up front so we can reset it after the await // (works for both the camera and the gallery input). @@ -115,17 +123,23 @@ export function AddBoxModal({ isOpen, onClose, onAdd, askConfirm, knownLocations return ( -
- - setName(e.target.value)} - className="input" - placeholder={t('box.namePlaceholder')} - /> -
+ t('box.existingMatches', { count })} + renderLabel={(box) => ( + + {box.name} + {box.location && ( + / {box.location} + )} + + )} + onPick={handleOpenExisting} + /> Date: Sun, 18 Oct 2026 05:30:39 +0300 Subject: [PATCH 4/4] docs: describe the duplicate hints in the add forms Model: claude-opus-5-5 (effort=high) Assisted-by: claude-opus-5-5 --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a690c99..334c423 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ A clean, cloud-synced web app for cataloguing your physical storage boxes and th - **Box & Item Catalog** - Create boxes with a name, location, description, tags and photos, and add items to them - **Photos** - Attach several photos to any box or item, taken with the in-app camera or picked from the gallery; open them fullscreen with pinch and double-tap zoom +- **No Accidental Duplicates** - While you type the name of a new box or item, existing ones with a similar name (typos included) are listed under the field; tap one to open it instead of creating it again - **Box Locations** - Record where each box physically is ("attic, shelf 2"); earlier locations are offered as you type - **Fuzzy Search** - Find items by name, description or tag, powered by [Fuse.js](https://www.fusejs.io/). Searching the box list also looks at locations and inside the boxes, and says which item matched - **Tagging System** - Boxes and items share one tag vocabulary; rename, merge or delete a tag everywhere from a central manager @@ -75,6 +76,12 @@ over it. 3. Give it a name and, optionally, a location, a description, tags and photos. 4. Open the box and tap **+** again to start cataloguing its contents. +While you type a name, boxes or items you already have with a similar name are +listed under the field. Tap one (or reach it with the arrow keys and press +Enter) to open it instead: a box opens, an item opens in its edit form, where it +can be moved to another box. The list is only a reminder; **Create Box** and +**Add Item** still create a new one. + ### Navigating | View | How to reach it |