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

@@ -28,7 +28,7 @@ export default function CityFilter({ cities, value, onChange }) {
return () => document.removeEventListener("mousedown", onDocMouseDown);
}, [open]);
const { options, canAddCustom } = useCityOptions(cities, value, query);
const { options, typedCity } = useCityOptions(cities, value, query);
const toggle = (city) => {
if (value.includes(city)) {
@@ -40,20 +40,19 @@ export default function CityFilter({ cities, value, onChange }) {
inputRef.current?.focus();
};
const addCustom = () => {
const city = query.trim();
if (city && !value.includes(city)) {
onChange([...value, city]);
}
// Города нет в списке — объявлений там нет, но фильтр всё равно применяем:
// лента покажет «В этом городе нет объявлений»
const applyTyped = () => {
onChange([...value, typedCity]);
setQuery("");
inputRef.current?.focus();
setOpen(false);
};
const handleKeyDown = (e) => {
if (e.key === "Enter") {
e.preventDefault();
if (canAddCustom) {
addCustom();
if (typedCity) {
applyTyped();
} else if (options.length) {
toggle(options[0]);
}
@@ -138,23 +137,10 @@ export default function CityFilter({ cities, value, onChange }) {
{open && (
<div className="f-city-ms-dropdown">
{options.length === 0 && !canAddCustom && (
{options.length === 0 && (
<div className="f-city-ms-empty">{t('feed.filterCitiesEmpty')}</div>
)}
{canAddCustom && (
<button type="button" className="f-city-ms-option f-city-ms-add"
onClick={() => {
addCustom();
setOpen(false);
}}>
<span className="f-city-ms-check">+</span>
<span className="f-city-ms-label">
{t('feed.filterCitiesAdd', { city: query.trim() })}
</span>
</button>
)}
{options.map(city => {
const selected = value.includes(city);
return (