"use client";
import { AtUri } from "@atproto/api";
import Link from "next/link";
import {
PublicationPostItemSmall,
PublicationPostItemMedium,
PublicationPostItemLarge,
} from "app/(app)/lish/[did]/[publication]/PublicationPostItem";
import { LocalizedDate } from "app/(app)/lish/[did]/[publication]/LocalizedDate";
import {
getDocumentURL,
getPublicationURL,
} from "app/(app)/lish/createPub/getPublicationURL";
import { getFirstParagraph } from "src/utils/getFirstParagraph";
import { blobRefToSrc } from "src/utils/blobRefToSrc";
import { useStandardSitePost } from "components/StandardSitePostDataProvider";
import { useEntity, useReplicache } from "src/replicache";
import { InteractionPreview } from "components/InteractionsPreview";
import { PubIcon } from "components/ActionBar/Publications";
import { PublicationThemeProvider } from "components/ThemeManager/PublicationThemeProvider";
import type { StandardSitePostData } from "app/api/rpc/[command]/get_standard_site_posts";
export type StandardSitePostSize = "large" | "medium" | "small";
export function StandardSitePostItem({
uri,
size = "medium",
currentPublicationUri,
}: {
uri: string;
size?: StandardSitePostSize;
currentPublicationUri?: string | null;
}) {
const { data, isLoading } = useStandardSitePost(uri);
const { rootEntity } = useReplicache();
const pageWidth = useEntity(rootEntity, "theme/page-width")?.data.value;
if (isLoading) {
return (
);
}
if (!data) {
return
Post not found.
;
}
return (
);
}
export function WithStandardSitePostPublicationTheme({
post,
enabled,
children,
}: {
post: StandardSitePostData;
enabled: boolean;
children: React.ReactNode;
}) {
const record = post.publication?.record;
if (!enabled || !record || (!record.theme && !record.basicTheme)) {
return <>{children}>;
}
let pubCreator: string;
try {
pubCreator = new AtUri(post.publication!.uri).host;
} catch {
return <>{children}>;
}
return (
{children}
);
}
function StandardSitePostItemPlaceholder({
size,
pageWidth,
}: {
size: StandardSitePostSize;
pageWidth?: number;
}) {
if (size === "small") {
return (
<>
>
);
}
if (size === "medium") {
return (
<>
>
);
}
const widePage = (pageWidth ?? 0) >= 768;
return (
<>
>
);
}
export function StandardSitePostItemView({
post,
size = "medium",
currentPublicationUri,
}: {
post: StandardSitePostData;
size?: StandardSitePostSize;
currentPublicationUri?: string | null;
}) {
const docUrl = getDocumentURL(
post.record,
post.uri,
post.publication ?? undefined,
);
const authorLabel =
post.author?.displayName ||
(post.author?.handle ? `@${post.author.handle}` : undefined);
const date = post.record.publishedAt ? (
) : undefined;
const description = post.record.description || getFirstParagraph(post.record);
let postDid: string | undefined;
try {
postDid = new AtUri(post.uri).host;
} catch {
postDid = undefined;
}
const coverImageSrc =
post.record.coverImage && postDid
? blobRefToSrc(post.record.coverImage.ref, postDid)
: undefined;
const { rootEntity } = useReplicache();
const pageWidth = useEntity(rootEntity, "theme/page-width")?.data.value;
const publicationPrefs = post.publication?.record?.preferences;
const showComments = publicationPrefs?.showComments !== false;
const showMentions = publicationPrefs?.showMentions !== false;
const showRecommends = publicationPrefs?.showRecommends !== false;
const commentsCount = showComments ? post.commentsCount : 0;
const interactions = (
);
const showPubFooter =
!!post.publication?.record &&
(!currentPublicationUri || post.publication.uri !== currentPublicationUri);
const pubFooter =
showPubFooter && post.publication ? (
) : null;
const commonProps = {
href: docUrl,
title: post.record.title,
author: authorLabel,
date,
interactions,
footer: pubFooter,
};
if (size === "large") {
return (
);
}
if (size === "medium") {
return (
);
}
return ;
}
function PubFooter({
publication,
}: {
publication: NonNullable;
}) {
if (!publication.record) return null;
const pubUrl = getPublicationURL(publication);
return (
{publication.record.name}
);
}