reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import { useEffect } from "react";
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { Link, useParams } from "react-router";
|
||||
|
||||
import { CinemaNotFound } from "@/components/cinema/CinemaNotFound";
|
||||
import { CinemaSummary } from "@/components/cinema/CinemaSummary";
|
||||
import { ContactPanel } from "@/components/cinema/ContactPanel";
|
||||
import { FacilitiesSection } from "@/components/cinema/FacilitiesSection";
|
||||
import { Gallery } from "@/components/cinema/Gallery";
|
||||
import { TransportList } from "@/components/cinema/TransportList";
|
||||
import { CinemaGrid } from "@/components/site/CinemaGrid";
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { findCinemaBySlug, listOtherCinemas } from "@/lib/cinemas";
|
||||
import { readContent } from "@/lib/content.server";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { sortByDistance } from "@/lib/geo";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
|
||||
/** head (title) ไม่เปลี่ยนตามภาษา — meta() ไม่มี access ต่อ cookie */
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** อ่านชื่อโรงหนังฝั่งเซิร์ฟเวอร์ เพื่อให้ <title> ถูกตั้งแต่ HTML แรก */
|
||||
export async function loader({ params }: { params: { slug?: string } }) {
|
||||
const content = await readContent();
|
||||
const cinema = findCinemaBySlug(content.cinemas, params.slug);
|
||||
return { name: cinema ? cinema.name : null };
|
||||
}
|
||||
|
||||
export function meta({ loaderData }: { loaderData?: { name?: string | null } }) {
|
||||
const name = loaderData?.name ?? null;
|
||||
return [
|
||||
{
|
||||
title: name
|
||||
? `${name} — ${APP_TITLE}`
|
||||
: `${HEAD_MESSAGES.meta.cinemaNotFoundTitle} — ${APP_TITLE}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export default function CinemaDetailRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { cinemas } = useContent();
|
||||
const { status: nearMeStatus, distances } = useNearMe();
|
||||
const { slug } = useParams();
|
||||
const cinema = findCinemaBySlug(cinemas, slug);
|
||||
|
||||
// เก็บสถิติการเปิดดูหน้ารายละเอียด (ต้องอยู่ก่อน early return เพื่อให้ hook เรียกทุกครั้ง)
|
||||
useEffect(() => {
|
||||
if (!cinema) return;
|
||||
trackEvent({ type: "cinema_view", slug: cinema.slug, locale });
|
||||
}, [cinema, locale]);
|
||||
|
||||
if (!cinema) return <CinemaNotFound />;
|
||||
|
||||
const otherCinemas = listOtherCinemas(cinemas, cinema.slug);
|
||||
const orderedOthers =
|
||||
nearMeStatus === "ready"
|
||||
? sortByDistance(otherCinemas, distances)
|
||||
: otherCinemas;
|
||||
|
||||
return (
|
||||
<SiteShell variant="detail">
|
||||
<main className="relative z-10 mx-auto flex w-full max-w-[1440px] flex-col gap-10 px-5 pb-16 pt-4 md:px-[108px] md:pt-6">
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex w-fit items-center gap-2 text-xl font-medium"
|
||||
>
|
||||
<IconArrowBackUp size={24} />
|
||||
{messages.detail.back}
|
||||
</Link>
|
||||
|
||||
<Gallery photos={cinema.photos} cinemaName={cinema.name} />
|
||||
|
||||
<section className="grid gap-10 lg:grid-cols-[minmax(0,749px)_minmax(0,384px)] lg:justify-between">
|
||||
<div className="flex flex-col gap-12">
|
||||
<CinemaSummary cinema={cinema} />
|
||||
<TransportList transport={cinema.transport} />
|
||||
</div>
|
||||
<ContactPanel cinema={cinema} />
|
||||
</section>
|
||||
|
||||
<FacilitiesSection cinema={cinema} />
|
||||
|
||||
<section className="flex flex-col gap-8">
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{messages.detail.otherCinemas}
|
||||
</h2>
|
||||
<CinemaGrid cinemas={orderedOthers} source="other_cinemas" />
|
||||
</section>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user