reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
IconArrowRight,
|
||||
IconBuildingCommunity,
|
||||
IconMapPin,
|
||||
} from "@tabler/icons-react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import {
|
||||
CARD_GRADIENTS,
|
||||
cinemaCategoryLabel,
|
||||
cinemaLocationLabel,
|
||||
cinemaName,
|
||||
type Cinema,
|
||||
} from "@/lib/cinemas";
|
||||
import { formatDistance } from "@/lib/geo";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
type CinemaCardProps = {
|
||||
cinema: Cinema;
|
||||
/** ลำดับการ์ด ใช้เลือก gradient ให้สลับสีสม่ำเสมอ */
|
||||
index?: number;
|
||||
/** ที่มาของการ์ด ใช้บันทึกสถิติการคลิก */
|
||||
source?: string;
|
||||
/** คำค้นปัจจุบัน (แนบไปกับการคลิกเพื่อวัด CTR ของคำค้น) */
|
||||
searchQuery?: string;
|
||||
};
|
||||
|
||||
export function CinemaCard({
|
||||
cinema,
|
||||
index = 0,
|
||||
source = "list",
|
||||
searchQuery,
|
||||
}: CinemaCardProps) {
|
||||
const { locale, messages } = useI18n();
|
||||
const { distances } = useNearMe();
|
||||
const gradient = CARD_GRADIENTS[index % CARD_GRADIENTS.length];
|
||||
// รูปแรก = ปกการ์ด (ถ้าไม่มีรูป ใช้ gradient เดิมเป็นพื้นหลัง)
|
||||
const cover = cinema.photos.find((photo) => photo.trim() !== "");
|
||||
const distanceLabel = formatDistance(
|
||||
distances[cinema.slug],
|
||||
messages.card.distanceFallback,
|
||||
);
|
||||
|
||||
return (
|
||||
<article
|
||||
className={`relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 lg:aspect-auto lg:h-[308px] ${gradient}`}
|
||||
>
|
||||
{cover ? (
|
||||
<>
|
||||
<img
|
||||
src={cover}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
loading="lazy"
|
||||
className="absolute inset-0 size-full object-cover"
|
||||
/>
|
||||
{/* ไล่เงาเพื่อให้ตัวอักษรบนการ์ดอ่านได้ */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0 bg-gradient-to-t from-[#0D0D0D]/95 via-[#0D0D0D]/35 to-transparent"
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl">
|
||||
<span className="text-[10px] text-[#B3B3B3]">{distanceLabel}</span>
|
||||
<h3 className="text-sm font-semibold">{cinemaName(cinema, locale)}</h3>
|
||||
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
|
||||
<IconMapPin size={12} />
|
||||
{cinemaLocationLabel(cinema, locale) || messages.card.locationFallback}
|
||||
</p>
|
||||
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
|
||||
<IconBuildingCommunity size={12} />
|
||||
{cinemaCategoryLabel(cinema, messages) ||
|
||||
messages.card.categoryFallback}
|
||||
</p>
|
||||
<Link
|
||||
to={`/cinema/${cinema.slug}`}
|
||||
onClick={() =>
|
||||
trackEvent({
|
||||
type: "cinema_select",
|
||||
slug: cinema.slug,
|
||||
source,
|
||||
query: searchQuery,
|
||||
position: index + 1,
|
||||
locale,
|
||||
})
|
||||
}
|
||||
className="mt-3 flex items-center justify-end gap-2 text-xs font-medium"
|
||||
>
|
||||
{messages.card.seeDetail} <IconArrowRight size={12} />
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { CinemaCard } from "@/components/site/CinemaCard";
|
||||
import type { Cinema, CinemaCategory } from "@/lib/cinemas";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
/** กริดการ์ดโรงหนัง — ใช้ทั้งหน้าแรกและส่วน "โรงหนังอิสระอื่นๆ" */
|
||||
export function CinemaGrid({
|
||||
cinemas,
|
||||
source = "list",
|
||||
searchQuery,
|
||||
}: {
|
||||
cinemas: Cinema[];
|
||||
source?: string;
|
||||
searchQuery?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{cinemas.map((cinema, index) => (
|
||||
<CinemaCard
|
||||
key={cinema.slug}
|
||||
cinema={cinema}
|
||||
index={index}
|
||||
source={source}
|
||||
searchQuery={searchQuery}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type CategoryFilterProps = {
|
||||
/** เก็บคีย์หมวดเป็นภาษาไทยเสมอ เพื่อใช้กรองข้อมูลได้ทุกภาษา */
|
||||
active: CinemaCategory;
|
||||
categories: readonly CinemaCategory[];
|
||||
onChange: (category: CinemaCategory) => void;
|
||||
};
|
||||
|
||||
export function CategoryFilter({
|
||||
active,
|
||||
categories,
|
||||
onChange,
|
||||
}: CategoryFilterProps) {
|
||||
const { messages } = useI18n();
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{categories.map((category) => {
|
||||
const isActive = category === active;
|
||||
return (
|
||||
<button
|
||||
key={category}
|
||||
type="button"
|
||||
onClick={() => onChange(category)}
|
||||
aria-pressed={isActive}
|
||||
className={
|
||||
isActive
|
||||
? "rounded-[18px] border border-[#A92626] bg-gradient-to-b from-[#8F0808]/30 to-[#1B1B1B]/0 px-4 py-2 text-sm text-[#D47272]"
|
||||
: "rounded-[18px] border border-[#303030] bg-[#242424] px-4 py-2 text-sm text-[#B3B3B3] transition hover:border-[#A92626]/60"
|
||||
}
|
||||
>
|
||||
{messages.categories[category]}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { LOCALE_OPTIONS } from "@/lib/i18n/messages";
|
||||
import { COLORS } from "@/lib/design-tokens";
|
||||
|
||||
/** ธงชาติไทยย่อส่วน */
|
||||
function FlagTh() {
|
||||
return (
|
||||
<span
|
||||
className="block h-4 w-[21px] shrink-0 rounded-[1px]"
|
||||
style={{ background: COLORS.flagGradient }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** ธงสหราชอาณาจักรย่อส่วน */
|
||||
function FlagEn() {
|
||||
return (
|
||||
<span
|
||||
className="relative block h-4 w-[21px] shrink-0 overflow-hidden rounded-[1px]"
|
||||
style={{ background: "#012169" }}
|
||||
>
|
||||
<span
|
||||
className="absolute inset-0"
|
||||
style={{
|
||||
background:
|
||||
"linear-gradient(45deg, transparent 44%, #F4F5F8 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, #F4F5F8 44% 56%, transparent 56%)",
|
||||
}}
|
||||
/>
|
||||
<span
|
||||
className="absolute inset-0"
|
||||
style={{
|
||||
background:
|
||||
"linear-gradient(90deg, transparent 40%, #F4F5F8 40% 60%, transparent 60%), linear-gradient(0deg, transparent 33%, #F4F5F8 33% 67%, transparent 67%)",
|
||||
}}
|
||||
/>
|
||||
<span
|
||||
className="absolute inset-0"
|
||||
style={{
|
||||
background:
|
||||
"linear-gradient(90deg, transparent 44%, #C8102E 44% 56%, transparent 56%), linear-gradient(0deg, transparent 40%, #C8102E 40% 60%, transparent 60%)",
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const FLAGS = { th: FlagTh, en: FlagEn } as const;
|
||||
|
||||
/**
|
||||
* สลับภาษาเป็นปุ่มสองปุ่ม (TH / EN) — ไม่มีเมนูให้เปิด/ปิด
|
||||
* จึงไม่มีปัญหาคลิกพลาดหรือเมนูถูกบัง และกดครั้งเดียวเปลี่ยนทันที
|
||||
*/
|
||||
export function LocaleSwitcher() {
|
||||
const { locale, setLocale } = useI18n();
|
||||
|
||||
return (
|
||||
<div role="group" aria-label="ภาษา" className="flex items-center gap-1">
|
||||
{LOCALE_OPTIONS.map((option) => {
|
||||
const Flag = FLAGS[option.locale];
|
||||
const isActive = option.locale === locale;
|
||||
return (
|
||||
<button
|
||||
key={option.locale}
|
||||
type="button"
|
||||
lang={option.locale}
|
||||
onClick={() => setLocale(option.locale)}
|
||||
aria-pressed={isActive}
|
||||
title={option.name}
|
||||
className={`flex items-center gap-1.5 rounded-lg px-1.5 py-1 text-sm transition sm:gap-2 sm:px-2 ${
|
||||
isActive
|
||||
? "bg-[#242424] font-semibold text-[#D47272]"
|
||||
: "text-[#B3B3B3] hover:text-white"
|
||||
}`}
|
||||
>
|
||||
<span className="hidden sm:block">
|
||||
<Flag />
|
||||
</span>
|
||||
<span className="text-base font-medium leading-none sm:text-lg">
|
||||
{option.code}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { LOGO_SPEC } from "@/lib/design-tokens";
|
||||
import { logoClasses } from "@/components/site/Logo";
|
||||
|
||||
/**
|
||||
* กันการเผลอเปลี่ยนโลโก้: สเปกใน DESIGN.md ถูกตรึงไว้ที่นี่
|
||||
* ถ้าเทสต์นี้พัง แปลว่ามีคนแก้สเปกโลโก้ — ต้องขออนุมัติก่อน
|
||||
*/
|
||||
describe("โลโก้ AlterFlixHub (สเปกที่ห้ามเปลี่ยน)", () => {
|
||||
it("ใช้คำว่า AlterFlixHub เท่านั้น", () => {
|
||||
expect(LOGO_SPEC.wordmark).toBe("AlterFlixHub");
|
||||
});
|
||||
|
||||
it("ฟอนต์ต้องเป็น Jersey 15", () => {
|
||||
expect(LOGO_SPEC.fontFamily).toContain("Jersey 15");
|
||||
expect(logoClasses("md")).toContain("font-['Jersey_15']");
|
||||
expect(logoClasses("sm")).toContain("font-['Jersey_15']");
|
||||
});
|
||||
|
||||
it("สีต้องเป็นแดงแบรนด์ #8F0808", () => {
|
||||
expect(LOGO_SPEC.color).toBe("#8F0808");
|
||||
});
|
||||
|
||||
it("header 36px (md) และ footer 24px (sm) เท่านั้น", () => {
|
||||
expect(LOGO_SPEC.sizes.md).toBe("text-4xl");
|
||||
expect(LOGO_SPEC.sizes.sm).toBe("text-2xl");
|
||||
expect(logoClasses("md")).toContain("text-4xl");
|
||||
expect(logoClasses("sm")).toContain("text-2xl");
|
||||
});
|
||||
|
||||
it("ไม่มีตัวเลือกขนาดอื่นนอกเหนือจาก sm/md", () => {
|
||||
expect(Object.keys(LOGO_SPEC.sizes).sort()).toEqual(["md", "sm"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { LOGO_SPEC, type LogoSize } from "@/lib/design-tokens";
|
||||
|
||||
type LogoProps = {
|
||||
className?: string;
|
||||
/** sm = footer (24px) · md = header (36px) */
|
||||
size?: LogoSize;
|
||||
};
|
||||
|
||||
/**
|
||||
* โลโก้ AlterFlixHub — ตาม DESIGN.md หัวข้อ "โลโก้ (ห้ามเปลี่ยนแปลง)"
|
||||
* ฟอนต์ Jersey 15 สี #8F0808 และมีสองขนาดเท่านั้น (sm/md)
|
||||
*/
|
||||
export function logoClasses(size: LogoSize = "md"): string {
|
||||
return `font-['Jersey_15'] leading-none ${LOGO_SPEC.sizes[size]}`;
|
||||
}
|
||||
|
||||
export function Logo({ className = "", size = "md" }: LogoProps) {
|
||||
return (
|
||||
<span
|
||||
className={`${logoClasses(size)} ${className}`}
|
||||
style={{ fontFamily: LOGO_SPEC.fontFamily, color: LOGO_SPEC.color }}
|
||||
>
|
||||
{LOGO_SPEC.wordmark}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { footerIcon } from "@/components/site/footer-icons";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
/**
|
||||
* Footer ใช้คอนเทนเนอร์เดียวกับ <main> ของทุกหน้า (max-w-[1440px] + px เดียวกัน)
|
||||
* ขอบซ้าย/ขวาจึงตรงกับกริดการ์ดโรงหนังเป๊ะ ไม่ว่าหน้าจะแสดงการ์ดกี่ใบ
|
||||
*/
|
||||
export function SiteFooter() {
|
||||
const { site } = useContent();
|
||||
const { messages } = useI18n();
|
||||
|
||||
return (
|
||||
<footer className="relative z-10 mx-auto w-full max-w-[1440px] px-5 pb-6 md:px-[108px]">
|
||||
<div className="flex flex-col items-center gap-3 border-t border-white/10 pt-4 sm:flex-row sm:justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<Logo size="sm" />
|
||||
<nav aria-label="เมนูล่าง" className="flex items-center gap-3 text-xs">
|
||||
<Link
|
||||
to="/about"
|
||||
className="text-[#B3B3B3] transition hover:text-white"
|
||||
>
|
||||
{messages.nav.about}
|
||||
</Link>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
||||
{site.footer.map((item) => {
|
||||
const Icon = footerIcon(item.icon_name);
|
||||
const isExternal = item.href.startsWith("http");
|
||||
return (
|
||||
<a
|
||||
key={item.id}
|
||||
href={item.href || "#"}
|
||||
aria-label={item.label}
|
||||
title={item.label}
|
||||
target={isExternal ? "_blank" : undefined}
|
||||
rel={isExternal ? "noreferrer" : undefined}
|
||||
className="flex size-8 items-center justify-center rounded-full bg-white/90 text-[#0D0D0D] transition hover:bg-white"
|
||||
>
|
||||
<Icon size={18} />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-[#999]">Copyright © AlterFlixHub</p>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Link, useLocation } from "react-router";
|
||||
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { LocaleSwitcher } from "@/components/site/LocaleSwitcher";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
/**
|
||||
* Header: โลโก้ชิดซ้าย · ด้านขวาเป็น [เกี่ยวกับเรา] + [ปุ่มภาษา TH/EN]
|
||||
* ไม่มีเมนู "หน้าแรก" — กลับหน้าแรกได้ด้วยการกดโลโก้
|
||||
*/
|
||||
export function SiteHeader() {
|
||||
const { messages } = useI18n();
|
||||
const { pathname } = useLocation();
|
||||
const isAbout = pathname.startsWith("/about");
|
||||
|
||||
return (
|
||||
<header className="relative z-10 mx-auto flex h-[68px] w-full max-w-[1440px] items-center justify-between gap-4 px-5 md:px-[108px]">
|
||||
<Link to="/" aria-label={`AlterFlixHub — ${messages.nav.home}`} className="shrink-0">
|
||||
<Logo />
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center gap-1.5 sm:gap-2">
|
||||
<Link
|
||||
to="/about"
|
||||
aria-current={isAbout ? "page" : undefined}
|
||||
className={`rounded-lg border px-2 py-1 text-xs transition sm:px-3 sm:py-1.5 sm:text-sm ${
|
||||
isAbout
|
||||
? "border-[#A92626] bg-[#8F0808]/20 text-white"
|
||||
: "border-[#303030] text-[#B3B3B3] hover:border-[#A92626]/60 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
{messages.nav.about}
|
||||
</Link>
|
||||
|
||||
<LocaleSwitcher />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { SiteFooter } from "@/components/site/SiteFooter";
|
||||
import { SiteHeader } from "@/components/site/SiteHeader";
|
||||
|
||||
type ShellVariant = "home" | "detail";
|
||||
|
||||
const HERO_IMAGE = "/images/hero.png";
|
||||
|
||||
/**
|
||||
* กรอบของตกแต่งพื้นหลัง
|
||||
* ต้องมี overflow-hidden ไม่งั้น glow ที่วางด้วย top/bottom แบบ px
|
||||
* จะยืด scrollHeight ของหน้าให้ยาวเกินเนื้อหา → เกิดพื้นที่ว่างใต้ footer
|
||||
*/
|
||||
function BackdropFrame({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute inset-0 overflow-hidden"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** พื้นหลังหน้าแรก: รูปฮีโร่ + ไล่สีลงพื้นหลัง + แสงแดงสองจุด */
|
||||
function HomeBackdrop() {
|
||||
return (
|
||||
<BackdropFrame>
|
||||
<img
|
||||
src={HERO_IMAGE}
|
||||
alt=""
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-[553px] w-full object-cover"
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-x-0 top-0 h-[553px] bg-gradient-to-b from-transparent via-[#0D0D0D]/60 to-[#0D0D0D]" />
|
||||
<div className="pointer-events-none absolute left-1/2 top-0 size-[382px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#8F0808] blur-[237px]" />
|
||||
{/* จุดล่างยึดกับขอบล่างของหน้า (เดิมใช้ top-[1620px] ตายตัว จึงล้นเลย footer เมื่อแสดงโรงหนังแบบย่อ) */}
|
||||
<div className="pointer-events-none absolute bottom-[-140px] left-1/2 size-[382px] -translate-x-1/2 rounded-full bg-[#4C0404]/70 blur-[237px]" />
|
||||
</BackdropFrame>
|
||||
);
|
||||
}
|
||||
|
||||
/** พื้นหลังหน้ารายละเอียด: แสงแดงจุดเดียวตามระยะใน Figma */
|
||||
function DetailBackdrop() {
|
||||
return (
|
||||
<BackdropFrame>
|
||||
<div className="pointer-events-none absolute left-1/2 top-[649px] size-[382px] -translate-x-1/2 rounded-full bg-[#4C0404] opacity-[0.66] blur-[237px]" />
|
||||
</BackdropFrame>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* โครงหน้าเว็บที่ทุก route ใช้ร่วมกัน (พื้นหลัง + header + footer)
|
||||
* variant เลือกชุดพื้นหลัง ไม่ใช่ layout — เนื้อหายังคงอยู่ใน route
|
||||
*/
|
||||
export function SiteShell({
|
||||
variant,
|
||||
children,
|
||||
}: {
|
||||
variant: ShellVariant;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="relative flex min-h-dvh w-full flex-col overflow-x-hidden bg-[#0D0D0D] text-white">
|
||||
{variant === "home" ? <HomeBackdrop /> : <DetailBackdrop />}
|
||||
<SiteHeader />
|
||||
{/* flex-1 ดัน footer ไปท้ายจอเมื่อเนื้อหาสั้น — เป็น block ธรรมดา
|
||||
(ไม่ใช้ flex-col เพื่อไม่ให้ main ที่มี mx-auto หดเหลือ max-content จนล้นจอมือถือ) */}
|
||||
<div className="flex-1">{children}</div>
|
||||
<SiteFooter />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
IconBrandFacebook,
|
||||
IconBrandInstagram,
|
||||
IconBrandLinkedin,
|
||||
IconBrandTelegram,
|
||||
IconBrandTiktok,
|
||||
IconBrandX,
|
||||
IconBrandYoutube,
|
||||
IconLink,
|
||||
IconMail,
|
||||
IconPhone,
|
||||
type Icon as TablerIcon,
|
||||
} from "@tabler/icons-react";
|
||||
|
||||
/** ไอคอนที่เลือกใช้ได้ใน footer — เพิ่มชื่อใหม่ได้โดยเติมใน map นี้ */
|
||||
export const FOOTER_ICONS: Record<string, TablerIcon> = {
|
||||
IconBrandFacebook,
|
||||
IconBrandInstagram,
|
||||
IconBrandLinkedin,
|
||||
IconBrandYoutube,
|
||||
IconBrandTelegram,
|
||||
IconBrandTiktok,
|
||||
IconBrandX,
|
||||
IconMail,
|
||||
IconPhone,
|
||||
IconLink,
|
||||
};
|
||||
|
||||
export const FOOTER_ICON_NAMES = Object.keys(FOOTER_ICONS);
|
||||
|
||||
export function footerIcon(name: string): TablerIcon {
|
||||
return FOOTER_ICONS[name] ?? IconLink;
|
||||
}
|
||||
Reference in new issue
Block a user