reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,144 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useLoaderData } from "react-router";
|
||||
|
||||
import { HeroSection } from "@/components/home/HeroSection";
|
||||
import { CategoryFilter, CinemaGrid } from "@/components/site/CinemaGrid";
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { filterCinemas, CINEMA_CATEGORIES, DEFAULT_CATEGORY, publiclyVisible, type Cinema, type CinemaCategory } from "@/lib/cinemas";
|
||||
import { dailyOrder, dayKey } from "@/lib/daily-order";
|
||||
import { computePopularity } from "@/lib/popularity.server";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { sortByDistance } from "@/lib/geo";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
|
||||
/** head (title/description) ไม่เปลี่ยนตามภาษา — meta() ไม่มี access ต่อ cookie */
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
export function meta() {
|
||||
return [
|
||||
{ title: APP_TITLE },
|
||||
{ name: "description", content: HEAD_MESSAGES.meta.homeDescription },
|
||||
];
|
||||
}
|
||||
|
||||
/** จำนวนการ์ดที่แสดงก่อนกด "แสดงเพิ่ม" */
|
||||
const INITIAL_VISIBLE = 4;
|
||||
|
||||
/** อันดับยอดนิยม + คีย์วันที่สำหรับสลับลำดับการ์ด (memo 5 นาที) — ส่งมากับ loader */
|
||||
export async function loader() {
|
||||
return { popularity: await computePopularity(), orderKey: dayKey() };
|
||||
}
|
||||
|
||||
export default function HomeRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { popularity, orderKey } = useLoaderData<typeof loader>();
|
||||
const { cinemas } = useContent();
|
||||
const { status: nearMeStatus, distances, requestLocation } = useNearMe();
|
||||
const [category, setCategory] = useState<CinemaCategory>(DEFAULT_CATEGORY);
|
||||
const [query, setQuery] = useState("");
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
|
||||
const matched = useMemo(() => {
|
||||
// ลำดับการ์ดสลับทุกวัน (ไม่ให้โรงใดอยู่ตำแหน่งเดิมสองวันติดกัน)
|
||||
const base = dailyOrder(publiclyVisible(cinemas), (cinema) => cinema.slug, orderKey);
|
||||
const byStats =
|
||||
category === "ยอดนิยม" && popularity.ready && query.trim() === "";
|
||||
if (!byStats) return filterCinemas(base, { category, query });
|
||||
|
||||
// ใช้เฉพาะโรงที่ยังไม่ถูกซ่อน และเรียงตามอันดับสถิติ
|
||||
const bySlug = new Map(base.map((cinema) => [cinema.slug, cinema]));
|
||||
return popularity.slugs
|
||||
.map((slug) => bySlug.get(slug))
|
||||
.filter((cinema): cinema is Cinema => cinema !== undefined);
|
||||
}, [cinemas, category, query, popularity, orderKey]);
|
||||
// เรียงจากใกล้สุดไปไกลสุดเมื่อทราบตำแหน่งแล้ว (ไม่กรองตามรัศมี — ไกลแค่ไหนก็ยังแสดง)
|
||||
const ordered =
|
||||
nearMeStatus === "ready" ? sortByDistance(matched, distances) : matched;
|
||||
const visibleCinemas = showAll ? ordered : ordered.slice(0, INITIAL_VISIBLE);
|
||||
const hasMore = ordered.length > visibleCinemas.length;
|
||||
|
||||
const keyword = query.trim();
|
||||
|
||||
// เก็บสถิติการค้นหา: ยิงครั้งเดียวหลังผู้ใช้หยุดพิมพ์ 900ms และมีคำค้นอย่างน้อย 2 ตัวอักษร
|
||||
useEffect(() => {
|
||||
if (keyword.length < 2) return;
|
||||
const timer = setTimeout(() => {
|
||||
trackEvent({
|
||||
type: "search",
|
||||
query: keyword,
|
||||
category,
|
||||
result_count: matched.length,
|
||||
locale,
|
||||
});
|
||||
}, 900);
|
||||
return () => clearTimeout(timer);
|
||||
}, [keyword, category, matched.length, locale]);
|
||||
|
||||
function handleRequestLocation() {
|
||||
requestLocation();
|
||||
trackEvent({
|
||||
type: "near_me",
|
||||
category,
|
||||
query: keyword || undefined,
|
||||
result_count: matched.length,
|
||||
locale,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<SiteShell variant="home">
|
||||
<main className="relative z-10 mx-auto max-w-[1440px] px-5 pb-12 md:px-[108px] md:pb-16">
|
||||
<HeroSection
|
||||
query={query}
|
||||
onQueryChange={setQuery}
|
||||
nearMeStatus={nearMeStatus}
|
||||
onRequestLocation={handleRequestLocation}
|
||||
/>
|
||||
|
||||
<section className="mt-16 flex flex-col gap-6 md:mt-[65px]">
|
||||
<div className="flex min-h-[72px] items-center border-b border-[#1F1F1F] py-2">
|
||||
<h2 className="text-[28px] font-semibold leading-[1.3]">
|
||||
{messages.list.title}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<CategoryFilter
|
||||
active={category}
|
||||
categories={CINEMA_CATEGORIES}
|
||||
onChange={setCategory}
|
||||
/>
|
||||
|
||||
{visibleCinemas.length === 0 ? (
|
||||
<p className="py-16 text-center text-sm text-[#B3B3B3]">
|
||||
{messages.list.empty}
|
||||
</p>
|
||||
) : (
|
||||
<div className="mt-2">
|
||||
<CinemaGrid
|
||||
cinemas={visibleCinemas}
|
||||
source={keyword ? "search" : "category"}
|
||||
searchQuery={keyword || undefined}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasMore ? (
|
||||
<div className="flex justify-center pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAll(true)}
|
||||
className="h-10 w-[200px] rounded-lg border border-[#8F0808] bg-[#8F0808] transition hover:bg-[#a30a0a]"
|
||||
>
|
||||
{messages.list.showMore}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { footerIcon } from "@/components/site/footer-icons";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { COLORS } from "@/lib/design-tokens";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
export function meta() {
|
||||
return [
|
||||
{ title: `${HEAD_MESSAGES.about.title} — ${APP_TITLE}` },
|
||||
{ name: "description", content: HEAD_MESSAGES.about.lead },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* หน้า "เกี่ยวกับเรา" — เนื้อหามาจากหลังบ้าน (data/content) แยกตามภาษา
|
||||
* ภาษาภาพเดียวกับหน้าแรก/หน้ารายละเอียด: กรอบ 1440 + px-[108px], การ์ดขอบโทน #332B2B,
|
||||
* chip แดง, ตัวเลขในวงกลมไล่แสง (glowSoft) และไอคอนโซเชียลชุดเดียวกับ footer
|
||||
*/
|
||||
export default function AboutRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { site, about } = useContent();
|
||||
const content = about[locale];
|
||||
|
||||
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 transition hover:text-[#D47272]"
|
||||
>
|
||||
<IconArrowBackUp size={24} />
|
||||
{messages.nav.home}
|
||||
</Link>
|
||||
|
||||
<header className="flex flex-col gap-4">
|
||||
<h1 className="text-[32px] font-bold leading-[1.3] md:text-[40px]">
|
||||
{content.title}
|
||||
</h1>
|
||||
<p className="font-content max-w-[860px] text-[19px] leading-[1.8] text-[#C4C4C4] md:text-[21px]">
|
||||
{content.lead}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<section className="gap-6 lg:columns-2">
|
||||
{content.sections.map((section, index) => (
|
||||
<article
|
||||
key={`${section.heading}-${index}`}
|
||||
className="mb-8 flex break-inside-avoid flex-col gap-5 rounded-xl bg-[#1B1B1B]/70 p-7 backdrop-blur-sm transition hover:bg-[#1B1B1B] md:p-8"
|
||||
style={{ border: `1px solid ${COLORS.border}` }}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span
|
||||
className="flex size-12 shrink-0 items-center justify-center rounded-full text-sm font-semibold text-[#D47272]"
|
||||
style={{
|
||||
background: "rgba(143,8,8,0.16)",
|
||||
border: "1px solid rgba(169,38,38,0.45)",
|
||||
}}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{String(index + 1).padStart(2, "0")}
|
||||
</span>
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{section.heading}
|
||||
</h2>
|
||||
</div>
|
||||
<p className="font-content text-[17px] leading-[1.95] text-[#C7C7C7] md:text-[18px]">
|
||||
{section.body}
|
||||
</p>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section
|
||||
className="flex flex-col gap-6 rounded-xl p-6 backdrop-blur-sm lg:flex-row lg:items-center lg:justify-between"
|
||||
style={{
|
||||
border: "1px solid rgba(169,38,38,0.45)",
|
||||
background:
|
||||
"linear-gradient(180deg, rgba(143,8,8,0.18) 0%, rgba(27,27,27,0.85) 65%, rgba(13,13,13,0.7) 100%)",
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col gap-3">
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{content.contactHeading}
|
||||
</h2>
|
||||
<p className="font-content max-w-[720px] text-[16px] leading-[1.9] text-[#C4C4C4] md:text-[17px]">
|
||||
{content.contactNote}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{site.footer.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{site.footer.map((item) => {
|
||||
const Icon = footerIcon(item.icon_name);
|
||||
return (
|
||||
<a
|
||||
key={item.id}
|
||||
href={item.href}
|
||||
aria-label={item.label}
|
||||
title={item.label}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex size-11 items-center justify-center rounded-full bg-white/90 text-[#0D0D0D] transition hover:bg-white"
|
||||
>
|
||||
<Icon size={20} />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,86 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none focus:border-[#A92626]";
|
||||
|
||||
export default function AdminLoginRoute() {
|
||||
const navigate = useNavigate();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function submit(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/admin/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const payload = (await response.json().catch(() => ({}))) as {
|
||||
statusMessage?: string;
|
||||
message?: string;
|
||||
};
|
||||
setError(payload.statusMessage ?? payload.message ?? "เข้าสู่ระบบไม่สำเร็จ");
|
||||
return;
|
||||
}
|
||||
navigate("/admin");
|
||||
} catch {
|
||||
setError("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-[#0D0D0D] px-5 text-white">
|
||||
<form
|
||||
onSubmit={submit}
|
||||
className="w-full max-w-sm rounded-2xl border border-[#303030] bg-[#141414] p-6"
|
||||
>
|
||||
<h1 className="text-2xl font-semibold">เข้าสู่ระบบหลังบ้าน</h1>
|
||||
<p className="mt-1 text-sm text-[#999]">AlterFlixHub · เฉพาะผู้ดูแล</p>
|
||||
|
||||
<label className="mt-6 block text-sm text-[#B3B3B3]">
|
||||
ชื่อผู้ใช้
|
||||
<input
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="mt-4 block text-sm text-[#B3B3B3]">
|
||||
รหัสผ่าน
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{error ? (
|
||||
<p role="alert" className="mt-4 text-sm text-[#D47272]">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={busy}
|
||||
className="mt-6 h-10 w-full rounded-lg bg-[#8F0808] text-sm font-medium transition hover:bg-[#a30a0a] disabled:opacity-60"
|
||||
>
|
||||
{busy ? "กำลังเข้าสู่ระบบ…" : "เข้าสู่ระบบ"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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