Fix intraday modal hook order
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -709,9 +709,36 @@ export function FutureForecastModal() {
|
|||||||
const { locale, t } = useI18n();
|
const { locale, t } = useI18n();
|
||||||
const detail = store.selectedDetail;
|
const detail = store.selectedDetail;
|
||||||
const dateStr = store.futureModalDate;
|
const dateStr = store.futureModalDate;
|
||||||
|
|
||||||
|
if (!detail || !dateStr) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FutureForecastModalContent
|
||||||
|
store={store}
|
||||||
|
locale={locale}
|
||||||
|
t={t}
|
||||||
|
detail={detail}
|
||||||
|
dateStr={dateStr}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FutureForecastModalContent({
|
||||||
|
store,
|
||||||
|
locale,
|
||||||
|
t,
|
||||||
|
detail,
|
||||||
|
dateStr,
|
||||||
|
}: {
|
||||||
|
store: ReturnType<typeof useDashboardStore>;
|
||||||
|
locale: ReturnType<typeof useI18n>["locale"];
|
||||||
|
t: ReturnType<typeof useI18n>["t"];
|
||||||
|
detail: NonNullable<ReturnType<typeof useDashboardStore>["selectedDetail"]>;
|
||||||
|
dateStr: string;
|
||||||
|
}) {
|
||||||
const isPro = store.proAccess.subscriptionActive;
|
const isPro = store.proAccess.subscriptionActive;
|
||||||
const isProLoading = store.proAccess.loading;
|
const isProLoading = store.proAccess.loading;
|
||||||
const hasModalContext = Boolean(detail && dateStr);
|
const hasModalContext = true;
|
||||||
const [showDeferredTodaySections, setShowDeferredTodaySections] =
|
const [showDeferredTodaySections, setShowDeferredTodaySections] =
|
||||||
useState(false);
|
useState(false);
|
||||||
const [freshMarketScan, setFreshMarketScan] = useState<MarketScan | null>(
|
const [freshMarketScan, setFreshMarketScan] = useState<MarketScan | null>(
|
||||||
@@ -824,8 +851,6 @@ export function FutureForecastModal() {
|
|||||||
isToday,
|
isToday,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!detail || !dateStr) return null;
|
|
||||||
|
|
||||||
const view = getFutureModalView(detail, dateStr, locale);
|
const view = getFutureModalView(detail, dateStr, locale);
|
||||||
const scorePosition = `${50 + view.front.score / 2}%`;
|
const scorePosition = `${50 + view.front.score / 2}%`;
|
||||||
const barStyle = {
|
const barStyle = {
|
||||||
|
|||||||
@@ -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 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user