Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
208 lines
7.2 KiB
TypeScript
208 lines
7.2 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { useAuth } from "@/components/auth/clerk-safe";
|
|
import { AlertCircle, UserRound } from "lucide-react";
|
|
import {
|
|
ApiError,
|
|
followCreator,
|
|
getCreatorProfile,
|
|
listFollowing,
|
|
unfollowCreator,
|
|
} from "@/lib/api";
|
|
import type { CreatorProfile } from "@/lib/types";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import { CreatorsHeader } from "@/components/creators/CreatorsHeader";
|
|
import { CreatorProfileCard } from "@/components/creators/CreatorProfileCard";
|
|
import { FollowButton } from "@/components/creators/FollowButton";
|
|
import { EmptyPanel, ErrorPanel } from "@/components/creators/StatePanels";
|
|
import { friendlyErrorMessage } from "@/src/shared/errors/friendly";
|
|
import { ChannelLink } from "@/src/features/ott-player/ChannelLink";
|
|
|
|
type LoadState = "loading" | "ready" | "error";
|
|
|
|
function errorMessage(err: unknown, fallback: string): string {
|
|
if (err instanceof ApiError) return friendlyErrorMessage(err);
|
|
if (err instanceof Error) return friendlyErrorMessage(err);
|
|
return fallback;
|
|
}
|
|
|
|
interface CreatorProfileClientProps {
|
|
/** The route's `[handle]` segment — a handle OR a user id. */
|
|
readonly creatorRef: string;
|
|
/**
|
|
* The server-rendered profile from `generateMetadata`'s own fetch, so the
|
|
* page paints instantly instead of showing a loading skeleton while this
|
|
* client component re-fetches to seed the signed-in follow state. `null`
|
|
* when the server-side lookup 404'd (the page itself still renders — the
|
|
* owning `page.tsx` only calls `notFound()` before reaching this point).
|
|
*/
|
|
readonly initialProfile: CreatorProfile | null;
|
|
}
|
|
|
|
/**
|
|
* All of this profile's interactivity (follow/unfollow, the signed-in follow
|
|
* toggle's seed state). Split out of `page.tsx` so the server component can
|
|
* fetch the profile once for `generateMetadata` + JSON-LD and hand it down
|
|
* here, instead of every visitor (and every crawler) hitting an empty
|
|
* `"use client"` shell first.
|
|
*/
|
|
export function CreatorProfileClient({ creatorRef, initialProfile }: CreatorProfileClientProps) {
|
|
const { getToken, isLoaded, isSignedIn } = useAuth();
|
|
|
|
const [status, setStatus] = React.useState<LoadState>(initialProfile ? "ready" : "loading");
|
|
const [profile, setProfile] = React.useState<CreatorProfile | null>(initialProfile);
|
|
const [loadError, setLoadError] = React.useState<string>("");
|
|
|
|
const [followerCount, setFollowerCount] = React.useState(initialProfile?.follower_count ?? 0);
|
|
const [following, setFollowing] = React.useState(false);
|
|
const [followBusy, setFollowBusy] = React.useState(false);
|
|
const [followError, setFollowError] = React.useState<string>("");
|
|
const [notFound, setNotFound] = React.useState(false);
|
|
|
|
const load = React.useCallback(async () => {
|
|
if (!creatorRef) {
|
|
setStatus("error");
|
|
setLoadError("No creator was specified.");
|
|
return;
|
|
}
|
|
// The server already fetched this profile for metadata; skip the
|
|
// redundant loading state on first paint, but still refresh (the
|
|
// follow/follower count can be stale by the time this hydrates).
|
|
setLoadError("");
|
|
setNotFound(false);
|
|
try {
|
|
const token = (await getToken()) ?? undefined;
|
|
const result = await getCreatorProfile(creatorRef, { token });
|
|
setProfile(result);
|
|
setFollowerCount(result.follower_count);
|
|
|
|
// Seed the follow toggle: match the fetched handle against the caller's
|
|
// follow list (the SAFE list exposes handles, never user ids). Best-effort —
|
|
// a failure here never blocks rendering the public profile.
|
|
if (isSignedIn && result.handle) {
|
|
try {
|
|
const followees = await listFollowing({ token });
|
|
const handleLower = result.handle.toLowerCase();
|
|
setFollowing(
|
|
followees.some(
|
|
(p) => p.handle && p.handle.toLowerCase() === handleLower,
|
|
),
|
|
);
|
|
} catch {
|
|
setFollowing(false);
|
|
}
|
|
} else {
|
|
setFollowing(false);
|
|
}
|
|
|
|
setStatus("ready");
|
|
} catch (err) {
|
|
if (err instanceof ApiError && err.status === 404) {
|
|
setNotFound(true);
|
|
setStatus("ready");
|
|
return;
|
|
}
|
|
setLoadError(errorMessage(err, "Something went wrong loading this creator."));
|
|
setStatus("error");
|
|
}
|
|
}, [creatorRef, getToken, isSignedIn]);
|
|
|
|
React.useEffect(() => {
|
|
if (isLoaded) void load();
|
|
}, [isLoaded, load]);
|
|
|
|
const handleToggle = React.useCallback(async () => {
|
|
setFollowBusy(true);
|
|
setFollowError("");
|
|
try {
|
|
const token = (await getToken()) ?? undefined;
|
|
const result = following
|
|
? await unfollowCreator(creatorRef, { token })
|
|
: await followCreator(creatorRef, { token });
|
|
setFollowing(result.following);
|
|
setFollowerCount(result.follower_count);
|
|
} catch (err) {
|
|
setFollowError(errorMessage(err, "Couldn't update your follow."));
|
|
} finally {
|
|
setFollowBusy(false);
|
|
}
|
|
}, [creatorRef, following, getToken]);
|
|
|
|
return (
|
|
<main className="min-h-dvh">
|
|
<CreatorsHeader />
|
|
|
|
<section className="container max-w-3xl py-8">
|
|
{status === "loading" && <ProfileSkeleton />}
|
|
|
|
{status === "error" && (
|
|
<ErrorPanel
|
|
title="Couldn't load this creator"
|
|
message={loadError}
|
|
onRetry={() => void load()}
|
|
/>
|
|
)}
|
|
|
|
{status === "ready" && notFound && (
|
|
<EmptyPanel
|
|
icon={<UserRound className="size-6 text-primary" aria-hidden />}
|
|
title="Creator not found"
|
|
description="This creator profile doesn't exist or is no longer available."
|
|
/>
|
|
)}
|
|
|
|
{status === "ready" && !notFound && profile && (
|
|
<div className="space-y-4">
|
|
<CreatorProfileCard
|
|
profile={profile}
|
|
followerCount={followerCount}
|
|
followSlot={
|
|
<FollowButton
|
|
signedIn={Boolean(isSignedIn)}
|
|
following={following}
|
|
busy={followBusy}
|
|
onToggle={() => void handleToggle()}
|
|
/>
|
|
}
|
|
/>
|
|
{profile.handle && <ChannelLink handle={profile.handle} />}
|
|
{followError && (
|
|
<p
|
|
role="alert"
|
|
className="flex items-center gap-1.5 text-sm text-destructive"
|
|
>
|
|
<AlertCircle className="size-4 shrink-0" aria-hidden />
|
|
{followError}
|
|
</p>
|
|
)}
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
function ProfileSkeleton() {
|
|
return (
|
|
<Card>
|
|
<CardContent className="space-y-6 p-6">
|
|
<div className="flex items-start gap-4">
|
|
<Skeleton className="size-16 rounded-full" />
|
|
<div className="flex-1 space-y-2">
|
|
<Skeleton className="h-7 w-48" />
|
|
<Skeleton className="h-4 w-32" />
|
|
<Skeleton className="h-4 w-full max-w-md" />
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-5">
|
|
{Array.from({ length: 5 }).map((_, i) => (
|
|
<Skeleton key={i} className="h-[68px] rounded-lg" />
|
|
))}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|