({
config,
participant,
onCreated,
}: {
config: AppConfig | null;
participant: Participant | null;
onCreated: (challenge: Challenge) => void;
})
| 392 | } |
| 393 | |
| 394 | function CreateView({ |
| 395 | config, |
| 396 | participant, |
| 397 | onCreated, |
| 398 | }: { |
| 399 | config: AppConfig | null; |
| 400 | participant: Participant | null; |
| 401 | onCreated: (challenge: Challenge) => void; |
| 402 | }) { |
| 403 | const [place, setPlace] = useState<SelectedPlace>(defaultPlace); |
| 404 | const [name, setName] = useState(""); |
| 405 | const [query, setQuery] = useState(""); |
| 406 | const [suggestions, setSuggestions] = useState<PlaceSuggestion[]>([]); |
| 407 | const [radius, setRadius] = useState(500); |
| 408 | const [duration, setDuration] = useState(72); |
| 409 | const [resolution, setResolution] = useState(11); |
| 410 | const [busy, setBusy] = useState(false); |
| 411 | const [searching, setSearching] = useState(false); |
| 412 | const [message, setMessage] = useState(""); |
| 413 | const canCreate = name.trim().length >= 2 && place.name.trim().length > 0; |
| 414 | |
| 415 | function applyPlace(next: SelectedPlace) { |
| 416 | setPlace(next); |
| 417 | if (!name.trim() || name.startsWith("一起点亮")) { |
| 418 | setName(`一起点亮${next.name}`); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | async function searchPlaces() { |
| 423 | const keyword = query.trim(); |
| 424 | if (!keyword) { |
| 425 | setMessage("先输入学校、公园、商场或街区名称。"); |
| 426 | return; |
| 427 | } |
| 428 | setSearching(true); |
| 429 | setMessage(""); |
| 430 | try { |
| 431 | const AMap = await loadAmap(config, ["AMap.PlaceSearch"]); |
| 432 | const placeSearch = new AMap.PlaceSearch({ |
| 433 | city: "全国", |
| 434 | pageSize: 8, |
| 435 | pageIndex: 1, |
| 436 | extensions: "base", |
| 437 | }); |
| 438 | const result = await new Promise<any>((resolve, reject) => { |
| 439 | placeSearch.search(keyword, (status: string, data: any) => { |
| 440 | if (status === "complete") resolve(data); |
| 441 | else reject(new Error("地点搜索失败,请换个关键词。")); |
| 442 | }); |
| 443 | }); |
| 444 | const pois = result?.poiList?.pois || []; |
| 445 | const items = pois |
| 446 | .filter((poi: any) => poi.location) |
| 447 | .map((poi: any) => ({ |
| 448 | id: String(poi.id || `${poi.name}-${poi.location.lng}-${poi.location.lat}`), |
| 449 | name: String(poi.name), |
| 450 | address: [poi.cityname, poi.adname, poi.address].filter(Boolean).join(" · "), |
| 451 | lat: Number(poi.location.lat), |
nothing calls this directly
no test coverage detected