refactor: 提取 buildNavUrl 工具函数,统一 room API 错误处理

- 将 MatchResult.tsx 和 profile/page.tsx 中重复的导航 URL 构建逻辑提取到 src/lib/navigation.ts
- 7 个 room API 路由从 return NextResponse.json({ error }, { status }) 统一改为 throw ApiError,由 apiHandler 统一捕获
This commit is contained in:
2026-02-26 19:31:00 +08:00
parent c9e20d4c95
commit 9641acbcbd
10 changed files with 21 additions and 58 deletions
+2 -5
View File
@@ -29,6 +29,7 @@ import RestaurantImage from "@/components/RestaurantImage";
import { ProfileCardSkeleton, RecordItemSkeleton } from "@/components/Skeleton";
import { getUserId, getCachedProfile, setCachedProfile, setCachedPreferences, logout } from "@/lib/userId";
import { getAvatarBg, AVATARS } from "@/lib/avatars";
import { buildNavUrl } from "@/lib/navigation";
import type { UserProfile, UserPreferences, DecisionRecord, FavoriteRecord, Restaurant } from "@/types";
function firstImage(r: Restaurant): string {
@@ -279,10 +280,6 @@ export default function ProfilePage() {
if (!profile) return null;
const amapNavUrl = (r: Restaurant) =>
r.location
? `https://uri.amap.com/marker?position=${r.location}&name=${encodeURIComponent(r.name)}&callnative=1`
: `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(r.name)}`;
return (
<div className="h-dvh bg-background pb-16 overflow-y-auto scrollbar-none">
@@ -567,7 +564,7 @@ export default function ProfilePage() {
{history.map((d) => (
<a
key={d.id}
href={amapNavUrl(d.restaurantData)}
href={buildNavUrl(d.restaurantData)}
target="_blank"
rel="noopener noreferrer"
className="flex gap-3 rounded-xl bg-elevated p-2.5 transition-colors active:bg-subtle"