diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 7f20c3fbd..4a3e36ac1 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -27515,3 +27515,15 @@ - 验证与防复发:`frontend/tests/annual-two-step-2047.test.tsx` 覆盖两步切换、焦点、跳过与开始、前后往返和关闭重开后内容保留、点外面和 Esc 关闭、请求体不变、卡片尺寸和两栏样式;`annual-report.test.tsx` 里钉住旧版式的断言按原值、新值、原因更新。用产品的样式表把两步渲染成静态页面,在桌面和手机宽度下看过截图并量过滚动高度;登录后的真实页面本机起不来,没有在真实页面上看过。 - 关联记录:BUG-1637、BUG-1650、BUG-2037、BUG-2044。 - 修复版本:`claude/annual-two-step-2047`。 + +## BUG-2049 | 海外出生地只能在两个很长的下拉里一级级找,手机上几乎选不了 + +- 状态:fixed-pending-verify(待测试环境真机确认)。 +- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。 +- 触发与现象:在测试环境用一张公开的海外盘建档:国家之后是「州 / 地区」「城市」两级下拉,没有搜索,名字全是英文;英国的地区有 221 项,手机上要滚动一万多像素才能找到;美国的城市有一万六千多个。产品负责人确认内测有海外出生的用户。 +- 触发条件:出生国家或「今年住在哪个城市」选了中国以外的任何国家。 +- 根因:2026-11-06 定的做法是「海外地点逐级选择,不使用搜索」,当时没有按真实的列表长度在手机上走过;产品里也没有可搜索的下拉组件。 +- 修复:选了国外之后先显示一个搜索框,在浏览器里搜已经下载的该国地点表(不联网、不调第三方):城市名优先于地区名,前缀优先于词中,不分大小写和重音,最多 20 条;选中一行同时定下地区和城市。国家一栏可以按中文名或英文名打字筛选。配了一张 185 条的常见城市中文别名表,输入中文也能搜到,别名只用于查找,定位仍用地点表里那一条。逐级选择保留为第二入口。中国的省、市、区三级不变。保存的字段、标签和时区查询流程都没有变。 +- 验证与防复发:`frontend/tests/overseas-place-search-2049.test.tsx`:排序、重音与标点、20 条上限、美国全表的耗时、别名表每一条都能在地点表里找到、中文别名与找不到的状态、国家筛选、搜索选中与两级下拉选中得到完全相同的结果、方向键与回车和 Esc、中国不出现搜索框、样式沿用下拉选项且没有左侧色条。`world-location-table.test.ts` 里「不使用搜索」的断言按原值、新值、原因更新。登录后的页面本机起不来,外观只用产品样式表渲染成静态页面看过(电脑和手机宽度、浅色和深色)。 +- 关联记录:BUG-1506、BUG-2047。 +- 修复版本:`claude/overseas-place-search-2049`。 diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 4e95ee7fe..90bb7e6ed 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -809,6 +809,30 @@ section[popover]:has(> [data-sonner-toaster]), section[popover][aria-label^="页 .birth-place-status > span { min-width: 0; text-wrap: pretty; word-break: auto-phrase; } .birth-place-retry { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; border: 0; background: transparent; color: var(--color-action); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; } .birth-place-retry svg { width: 12px; height: 12px; } +/* BUG-2049: a typed search for overseas places and for the country. The field looks like + .select-trigger and the rows are .select-item, so it reads as one of the existing selects. */ +.birth-place-levels > label.birth-place-search { grid-column: 1 / -1; } +.location-search { position: relative; min-width: 0; } +.location-search-field { display: flex; align-items: center; gap: var(--space-3); min-width: 0; } +.location-search-input { flex: 1 1 auto; width: 100%; min-width: 0; min-height: 44px; padding: 0 var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-canvas); color: var(--color-ink); font: inherit; text-align: left; transition: border-color 160ms ease-out, box-shadow 160ms ease-out, background-color 160ms ease-out; } +.location-search-input::placeholder { color: var(--color-ink-tertiary); } +.location-search-input:hover { border-color: color-mix(in srgb, var(--color-action) 42%, var(--color-border)); background: var(--color-canvas-soft); } +.location-search-input:focus-visible { border-color: var(--color-action); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-action) 18%, transparent); } +.location-search-input:disabled { cursor: not-allowed; opacity: .55; } +.location-search-panel { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; max-height: min(320px, 56dvh); overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-canvas); padding: 5px; box-shadow: var(--shadow-elevated); } +.location-search-list { display: grid; } +.location-search-row { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; } +.location-search-primary { min-width: 0; overflow-wrap: anywhere; } +.location-search-secondary { flex: 0 1 auto; min-width: 0; color: var(--color-ink-tertiary); font-size: var(--type-overline); text-align: right; overflow-wrap: anywhere; } +.location-search-row[data-highlighted] .location-search-secondary { color: inherit; } +.location-search-footer, +.location-search-empty { margin: 0; padding: var(--space-2) var(--space-3); color: var(--color-ink-tertiary); font-size: var(--type-overline); line-height: 1.5; text-wrap: pretty; } +.birth-place-text-button { flex: 0 0 auto; justify-self: start; border: 0; background: transparent; color: var(--color-action); font-size: var(--type-overline); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; } +.birth-place-text-button:disabled { cursor: not-allowed; opacity: .55; } +@media (max-width: 640px) { + /* On a phone the matches sit in the page under the field, so the keyboard never covers a floating list. */ + .location-search-panel { position: static; margin-top: 4px; max-height: 44dvh; box-shadow: none; } +} .save-profile { justify-self: end; } .form-error { color: var(--color-danger); } diff --git a/frontend/src/components/birth-place-picker.tsx b/frontend/src/components/birth-place-picker.tsx index c93fa4787..15c36c387 100644 --- a/frontend/src/components/birth-place-picker.tsx +++ b/frontend/src/components/birth-place-picker.tsx @@ -2,7 +2,8 @@ import { Check, MapPin, RotateCcw } from "lucide-react"; import { InlineSpinner } from "@/components/inline-spinner"; -import { useEffect, useId, useRef, useState } from "react"; +import { useEffect, useId, useMemo, useRef, useState } from "react"; +import { PlaceSearchBox } from "@/components/ui/location-search-box"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { @@ -16,7 +17,24 @@ import { resolveBirthPlaceNode, } from "@/lib/china-birth-place"; import { displayPlaceLabel, STORED_PLACE_SEPARATOR } from "@/lib/place-label"; +import { worldCityAliases } from "@/data/world-city-aliases"; import { worldCountries, type WorldCountryData } from "@/data/world-countries"; +import { + buildPlaceIndex, + chosenPlaceText, + filterCountryOptions, + placeEntryTitle, + searchPlaces, + type CountryOption, +} from "@/lib/world-place-search"; + +// BUG-2049: overseas places are found by typing; the level-by-level selects stay as a second way in. +export const PLACE_SEARCH_PLACEHOLDER = "输入城市或地区的名字,可以输英文"; +export const PLACE_SEARCH_NOT_FOUND = "没有找到这个地方。可以选离它最近的城市,星盘差别很小。地名可以试试输英文。"; +export const PLACE_SEARCH_MORE = "显示前 20 条,继续输入可以缩小范围"; +export const PLACE_SEARCH_BY_LEVELS = "按地区一级级选"; +export const PLACE_SEARCH_BACK = "回到搜索"; +export const PLACE_SEARCH_CHANGE = "换一个"; /** Sentinel for "this city has districts but the user cannot name one". */ const cityCentreOption = "__city_centre__"; @@ -127,10 +145,13 @@ const otherCountryOptions = (() => { const collator = new Intl.Collator("zh-Hans-CN-u-co-pinyin"); return worldCountries .filter((item) => item.code !== "CN") - .map((item) => ({ code: item.code, label: countryLabel(item.code) })) + .map((item) => ({ code: item.code, label: countryLabel(item.code), english: item.name })) .sort((left, right) => collator.compare(left.label, right.label)); })(); +/** China first, then the rest: the list the country field filters as the user types. */ +const countryOptions: readonly CountryOption[] = [{ code: "CN", label: "中国", english: "China" }, ...otherCountryOptions]; + export function BirthPlacePicker({ value, birthDate = "", @@ -155,6 +176,10 @@ export function BirthPlacePicker({ const [globalLoadErrorCountry, setGlobalLoadErrorCountry] = useState(""); const [outcome, setOutcome] = useState(null); const [retryToken, setRetryToken] = useState(0); + const [countryQuery, setCountryQuery] = useState(""); + const [placeQuery, setPlaceQuery] = useState(""); + // The country whose places are being picked level by level; any other country shows the search box. + const [levelsCountry, setLevelsCountry] = useState(""); // The birth moment the value's offset was resolved for. A historical offset depends on it. const birthMoment = `${birthDate}/${birthTime}`; const [valueMoment, setValueMoment] = useState(birthMoment); @@ -205,6 +230,15 @@ export function BirthPlacePicker({ return () => controller.abort(); }, [draft.countryCode]); + const placeIndex = useMemo( + () => (globalData ? buildPlaceIndex(globalData, worldCityAliases) : null), + [globalData], + ); + const placeResult = placeIndex && placeIndex.country === draft.countryCode + ? searchPlaces(placeIndex, placeQuery) + : null; + const byLevels = !isChina && levelsCountry === draft.countryCode; + const globalRegion = !isChina && globalData?.code === draft.countryCode ? globalData.regions.find((item) => item.code === draft.provinceCode) : undefined; @@ -349,6 +383,17 @@ export function BirthPlacePicker({ setDraft((current) => ({ ...current, provinceCode: nextCode, cityCode: "", districtCode: "", cityCentre: false })); } + /** One row of the search sets both levels: the same draft the two selects would have built. */ + function chooseGlobalPlace(regionCode: string, cityCode: string) { + setDraft((current) => ({ ...current, provinceCode: regionCode, cityCode, districtCode: "", cityCentre: false })); + setPlaceQuery(""); + } + + function clearGlobalPlace() { + setDraft((current) => ({ ...current, provinceCode: "", cityCode: "", districtCode: "", cityCentre: false })); + setPlaceQuery(""); + } + // A place with no lookup recorded against it is still being looked up. const settled: TimezoneState = syncKey === "empty" ? { status: "idle" } @@ -389,28 +434,33 @@ export function BirthPlacePicker({ ? "选到区县就够了,同一个县内的差别不影响星盘。" : "选到城市就够了。"; + const placeRows = (placeResult?.hits ?? []).map((item) => ({ + key: `${item.regionCode}/${item.cityCode}`, + primary: placeEntryTitle(item), + secondary: item.cityName ? item.regionName : undefined, + })); + return (
{isChina && ( @@ -482,7 +532,32 @@ export function BirthPlacePicker({ )} - {!isChina && globalData && ( + {!isChina && !byLevels && globalData && ( + + )} + + {byLevels && globalData && (