From 379a4b9e459735bff68683c2bfbdfc442fecd6cd Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Fri, 24 Apr 2026 13:04:27 +0800 Subject: [PATCH] Fix intraday modal hook order --- .../app/api/system/priority-warm/route.ts | 10 +++ frontend/app/api/system/priority/route.ts | 10 +++ .../dashboard/FutureForecastModal.tsx | 31 +++++++- frontend/lib/system-priority-proxy.ts | 78 +++++++++++++++++++ 4 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 frontend/app/api/system/priority-warm/route.ts create mode 100644 frontend/app/api/system/priority/route.ts create mode 100644 frontend/lib/system-priority-proxy.ts diff --git a/frontend/app/api/system/priority-warm/route.ts b/frontend/app/api/system/priority-warm/route.ts new file mode 100644 index 00000000..e508bc3c --- /dev/null +++ b/frontend/app/api/system/priority-warm/route.ts @@ -0,0 +1,10 @@ +import { NextRequest } from "next/server"; +import { forwardPriorityWarmHint } from "@/lib/system-priority-proxy"; + +export async function GET(req: NextRequest) { + return forwardPriorityWarmHint(req); +} + +export async function POST(req: NextRequest) { + return forwardPriorityWarmHint(req); +} diff --git a/frontend/app/api/system/priority/route.ts b/frontend/app/api/system/priority/route.ts new file mode 100644 index 00000000..e508bc3c --- /dev/null +++ b/frontend/app/api/system/priority/route.ts @@ -0,0 +1,10 @@ +import { NextRequest } from "next/server"; +import { forwardPriorityWarmHint } from "@/lib/system-priority-proxy"; + +export async function GET(req: NextRequest) { + return forwardPriorityWarmHint(req); +} + +export async function POST(req: NextRequest) { + return forwardPriorityWarmHint(req); +} diff --git a/frontend/components/dashboard/FutureForecastModal.tsx b/frontend/components/dashboard/FutureForecastModal.tsx index a062bd47..af1bfa5f 100644 --- a/frontend/components/dashboard/FutureForecastModal.tsx +++ b/frontend/components/dashboard/FutureForecastModal.tsx @@ -709,9 +709,36 @@ export function FutureForecastModal() { const { locale, t } = useI18n(); const detail = store.selectedDetail; const dateStr = store.futureModalDate; + + if (!detail || !dateStr) return null; + + return ( + + ); +} + +function FutureForecastModalContent({ + store, + locale, + t, + detail, + dateStr, +}: { + store: ReturnType; + locale: ReturnType["locale"]; + t: ReturnType["t"]; + detail: NonNullable["selectedDetail"]>; + dateStr: string; +}) { const isPro = store.proAccess.subscriptionActive; const isProLoading = store.proAccess.loading; - const hasModalContext = Boolean(detail && dateStr); + const hasModalContext = true; const [showDeferredTodaySections, setShowDeferredTodaySections] = useState(false); const [freshMarketScan, setFreshMarketScan] = useState( @@ -824,8 +851,6 @@ export function FutureForecastModal() { isToday, ]); - if (!detail || !dateStr) return null; - const view = getFutureModalView(detail, dateStr, locale); const scorePosition = `${50 + view.front.score / 2}%`; const barStyle = { diff --git a/frontend/lib/system-priority-proxy.ts b/frontend/lib/system-priority-proxy.ts new file mode 100644 index 00000000..b0357fc4 --- /dev/null +++ b/frontend/lib/system-priority-proxy.ts @@ -0,0 +1,78 @@ +import { NextRequest, NextResponse } from "next/server"; +import { + applyAuthResponseCookies, + buildBackendRequestHeaders, +} from "@/lib/backend-auth"; + +const API_BASE = process.env.POLYWEATHER_API_BASE_URL; + +function getClientTimezone(req: NextRequest) { + return String( + req.nextUrl.searchParams.get("timezone") || + req.nextUrl.searchParams.get("tz") || + "", + ).trim(); +} + +export async function forwardPriorityWarmHint(req: NextRequest) { + if (!API_BASE) { + return NextResponse.json( + { + ok: false, + skipped: true, + reason: "POLYWEATHER_API_BASE_URL is not configured", + }, + { status: 202 }, + ); + } + + const params = new URLSearchParams(); + const timezone = getClientTimezone(req); + if (timezone) { + params.set("timezone", timezone); + } + + try { + const auth = await buildBackendRequestHeaders(req); + const res = await fetch( + `${API_BASE}/api/system/priority-warm${ + params.size ? `?${params.toString()}` : "" + }`, + { + method: "POST", + headers: auth.headers, + cache: "no-store", + }, + ); + + if (!res.ok) { + const raw = await res.text(); + const response = NextResponse.json( + { + ok: false, + skipped: true, + error: `Backend returned ${res.status}`, + detail: raw.slice(0, 500), + }, + { status: 202 }, + ); + return applyAuthResponseCookies(response, auth.response); + } + + const data = await res.json(); + const response = NextResponse.json(data, { + headers: { "Cache-Control": "no-store" }, + }); + return applyAuthResponseCookies(response, auth.response); + } catch (error) { + return NextResponse.json( + { + ok: false, + skipped: true, + error: "Failed to send priority warm hint", + detail: String(error), + }, + { status: 202 }, + ); + } +}