Files
2026-06-07 23:57:52 -05:00

224 lines
8.9 KiB
TypeScript

"use client";
import { useEffect, useMemo, useState } from "react";
import { Link, useLocale, useTranslation } from "@/i18n/navigation";
import Footer from "@/app/components/Footer";
import ContentSubmissionModal from "@/app/components/ContentSubmissionModal";
import { apiFetch } from "@/app/lib/api-client";
import { mediaUrl } from "@/app/lib/media";
interface VideoItem {
slug: string;
title: string;
titleEn?: string;
subtitle: string;
subtitleEn?: string;
description?: string;
descriptionEn?: string;
coverImage: string;
durationMinutes?: number;
citySlugs?: string[];
relatedProfiles?: string[];
}
const FALLBACK_VIDEOS: VideoItem[] = [
{
slug: "lin-dali-documentary",
title: "林晓雨:在大理远程工作的现实一天",
titleEn: "A remote work day in Dali",
subtitle: "个人访谈 / 现实纪录片 · 大理",
subtitleEn: "Interview documentary · Dali",
coverImage: "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1200",
durationMinutes: 12,
citySlugs: ["dali"],
relatedProfiles: ["林晓雨"],
},
{
slug: "chen-chengdu-dev",
title: "陈浩然:在成都做独立开发的真实节奏",
titleEn: "Indie dev life in Chengdu",
subtitle: "个人访谈 · 成都",
subtitleEn: "Interview · Chengdu",
coverImage: "https://images.unsplash.com/photo-1547981609-4b6bfe67ca0b?w=1200",
durationMinutes: 14,
citySlugs: ["chengdu"],
relatedProfiles: ["陈浩然"],
},
{
slug: "wang-shenzhen-creator",
title: "王思琪:深圳远程撰稿人的一天",
titleEn: "Remote writer day in Shenzhen",
subtitle: "个人访谈 · 深圳",
subtitleEn: "Interview · Shenzhen",
coverImage: "https://images.unsplash.com/photo-1518837695005-2083093ee35b?w=1200",
durationMinutes: 11,
citySlugs: ["shenzhen"],
relatedProfiles: ["王思琪"],
},
{
slug: "zhang-hangzhou-startup",
title: "张明远:在杭州远程创业的一周",
titleEn: "Remote startup week in Hangzhou",
subtitle: "个人访谈 · 杭州",
subtitleEn: "Interview · Hangzhou",
coverImage: "https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=1200",
durationMinutes: 16,
citySlugs: ["hangzhou"],
relatedProfiles: ["张明远"],
},
{
slug: "li-xiamen-design",
title: "李雅婷:在厦门做远程 UI 设计",
titleEn: "Remote UI design from Xiamen",
subtitle: "个人访谈 · 厦门",
subtitleEn: "Interview · Xiamen",
coverImage: "https://images.unsplash.com/photo-1590559899731-a382839e5549?w=1200",
durationMinutes: 10,
citySlugs: ["xiamen"],
relatedProfiles: ["李雅婷"],
},
];
export default function VideosPage() {
const locale = useLocale();
const { t } = useTranslation("videos");
const [videos, setVideos] = useState<VideoItem[]>(FALLBACK_VIDEOS);
const [loading, setLoading] = useState(true);
const [submissionOpen, setSubmissionOpen] = useState(false);
useEffect(() => {
apiFetch<{ items: VideoItem[] }>("/api/videos")
.then((data) => {
if (data.items?.length) setVideos(data.items);
})
.catch(() => setVideos(FALLBACK_VIDEOS))
.finally(() => setLoading(false));
}, []);
const featured = videos[0];
const rest = useMemo(() => videos.slice(1), [videos]);
const label = (item: VideoItem) => (locale === "zh" ? item.title : item.titleEn || item.title);
const sub = (item: VideoItem) => (locale === "zh" ? item.subtitle : item.subtitleEn || item.subtitle);
return (
<div className="min-h-screen bg-[#0f172a] text-white">
<main className="mx-auto max-w-6xl px-4 py-8 sm:px-6 sm:py-12">
<div className="flex flex-wrap items-center justify-between gap-4">
<div>
<Link href="/" className="text-sm text-white/60 hover:text-white">
← {t("backHome")}
</Link>
<h1 className="mt-4 flex items-center gap-2 text-3xl font-bold sm:text-4xl">
<span className="h-10 w-1 rounded-full bg-[#ff4d4f]" />
{t("title")}
</h1>
<p className="mt-2 max-w-2xl text-white/60">{t("subtitle")}</p>
</div>
<button
type="button"
onClick={() => setSubmissionOpen(true)}
className="rounded-full border border-[#ff7a45] px-4 py-2 text-sm font-semibold text-[#ffb088] hover:bg-[#ff7a45]/10"
>
{t("submit")}
</button>
</div>
{loading ? (
<div className="mt-10 grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 6 }).map((_, index) => (
<div key={index} className="aspect-[4/3] animate-pulse rounded-2xl bg-white/10" />
))}
</div>
) : (
<>
{featured ? (
<Link
href={`/videos/${featured.slug}`}
className="group mt-10 block overflow-hidden rounded-2xl bg-white/5 ring-1 ring-white/10 transition hover:bg-white/10"
>
<div className="grid md:grid-cols-2">
<div className="relative aspect-video md:aspect-auto md:min-h-[280px]">
<img
src={mediaUrl(featured.coverImage)}
alt={label(featured)}
className="h-full w-full object-cover transition duration-300 group-hover:scale-[1.02]"
/>
<span className="absolute left-4 top-4 rounded-full bg-[#ff4d4f] px-3 py-1 text-xs font-semibold">
{t("featured")}
</span>
</div>
<div className="flex flex-col justify-center p-6 sm:p-8">
<p className="text-sm font-semibold text-[#ff7a45]">{t("badge")}</p>
<h2 className="mt-2 text-2xl font-bold leading-snug">{label(featured)}</h2>
<p className="mt-2 text-white/60">{sub(featured)}</p>
<div className="mt-4 flex flex-wrap gap-2 text-xs text-white/50">
{featured.durationMinutes ? (
<span className="rounded-full bg-white/10 px-2.5 py-1">
{featured.durationMinutes} {t("minutes")}
</span>
) : null}
{(featured.relatedProfiles || []).map((name) => (
<span key={name} className="rounded-full bg-white/10 px-2.5 py-1">
@{name}
</span>
))}
</div>
<span className="mt-6 inline-flex w-fit rounded-full bg-white px-4 py-2 text-sm font-semibold text-gray-900">
{t("watch")}
</span>
</div>
</div>
</Link>
) : null}
<div className="mt-10 grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{rest.map((item) => (
<Link
key={item.slug}
href={`/videos/${item.slug}`}
className="group overflow-hidden rounded-2xl bg-white/5 ring-1 ring-white/10 transition hover:-translate-y-0.5 hover:bg-white/10 hover:shadow-xl"
>
<div className="relative aspect-video">
<img
src={mediaUrl(item.coverImage)}
alt={label(item)}
className="h-full w-full object-cover transition duration-300 group-hover:scale-[1.03]"
/>
<div className="absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent" />
{item.durationMinutes ? (
<span className="absolute bottom-3 right-3 rounded-md bg-black/70 px-2 py-1 text-xs">
{item.durationMinutes} {t("minutes")}
</span>
) : null}
<span className="absolute left-3 top-3 rounded-full bg-black/50 px-2 py-1 text-[10px] backdrop-blur">
▶ {t("badge")}
</span>
</div>
<div className="p-4">
<h3 className="line-clamp-2 font-bold leading-snug">{label(item)}</h3>
<p className="mt-1 line-clamp-2 text-sm text-white/55">{sub(item)}</p>
{(item.relatedProfiles || []).length > 0 ? (
<p className="mt-3 text-xs text-[#ffb088]">
{(item.relatedProfiles || []).join(" · ")}
</p>
) : null}
</div>
</Link>
))}
</div>
</>
)}
</main>
<ContentSubmissionModal
open={submissionOpen}
locale={locale}
submissionType="video"
onClose={() => setSubmissionOpen(false)}
/>
<Footer />
</div>
);
}