del add unknown city

This commit is contained in:
SlimusMinus
2026-10-19 00:36:41 +03:00
parent 11bc782e39
commit 838443fcb2
7 changed files with 45 additions and 63 deletions

View File

@@ -42,7 +42,7 @@ export default function CitySheet({ open, onClose, cities, value, onChange }) {
return () => document.removeEventListener("keydown", onKeyDown);
}, [open, onClose]);
const { options, canAddCustom } = useCityOptions(cities, draft, query);
const { options, typedCity } = useCityOptions(cities, draft, query);
// Города, добавленные свободным вводом, в общем списке отсутствуют — показываем их сверху
const q = query.trim().toLowerCase();
@@ -54,14 +54,10 @@ export default function CitySheet({ open, onClose, cities, value, onChange }) {
setDraft(d => d.includes(city) ? d.filter(c => c !== city) : [...d, city]);
};
const addCustom = () => {
const city = query.trim();
if (city && !draft.includes(city)) setDraft(d => [...d, city]);
setQuery("");
};
// Введённый город, которого нет в списке, тоже применяется: лента покажет
// «В этом городе нет объявлений»
const apply = () => {
onChange(draft);
onChange(typedCity ? [...draft, typedCity] : draft);
onClose();
};
@@ -122,27 +118,18 @@ export default function CitySheet({ open, onClose, cities, value, onChange }) {
placeholder={t("feed.filterCitiesSearch")}
onChange={e => setQuery(e.target.value)}
onKeyDown={e => {
if (e.key === "Enter" && canAddCustom) {
if (e.key === "Enter") {
e.preventDefault();
addCustom();
apply();
}
}}
autoComplete="off"
enterKeyHint="done"
enterKeyHint="search"
/>
</div>
<div className="f-sheet-list">
{canAddCustom && (
<button type="button" className="f-sheet-row f-sheet-row-add" onClick={addCustom}>
<span className="f-sheet-check">+</span>
<span className="f-sheet-row-label">
{t("feed.filterCitiesAdd", { city: query.trim() })}
</span>
</button>
)}
{rows.length === 0 && !canAddCustom && (
{rows.length === 0 && (
<div className="f-sheet-empty">{t("feed.filterCitiesEmpty")}</div>
)}