diff --git a/app/discover/PubListing.tsx b/app/discover/PubListing.tsx index c8c9d741..f12095ed 100644 --- a/app/discover/PubListing.tsx +++ b/app/discover/PubListing.tsx @@ -1,5 +1,6 @@ "use client"; import { AtUri } from "@atproto/syntax"; +import { PubIcon } from "components/ActionBar/Publications"; import { usePubTheme } from "components/ThemeManager/PublicationThemeProvider"; import { BaseThemeProvider } from "components/ThemeManager/ThemeProvider"; import { PubLeafletPublication, PubLeafletThemeColor } from "lexicons/api"; @@ -42,19 +43,8 @@ export const PubListing = (props: { px-3 py-3 selected-outline hover:outline-accent-contrast hover:border-accent-contrast`} > -
- {!record?.icon ? record.name.slice(0, 1).toLocaleUpperCase() : null} -
+ +
diff --git a/app/home/HomeEmpty/HomeEmpty.tsx b/app/home/HomeEmpty/HomeEmpty.tsx index 56d57142..ecabbabc 100644 --- a/app/home/HomeEmpty/HomeEmpty.tsx +++ b/app/home/HomeEmpty/HomeEmpty.tsx @@ -66,16 +66,16 @@ export function HomeEmptyState() { export const PublicationBanner = (props: { small?: boolean }) => { return (
{props.small ? ( - + ) : (
)} -
+
Start a Publication {" "} @@ -88,7 +88,7 @@ export const PublicationBanner = (props: { small?: boolean }) => { export const DiscoverBanner = (props: { small?: boolean }) => { return (
{props.small ? ( @@ -97,7 +97,7 @@ export const DiscoverBanner = (props: { small?: boolean }) => {
)} -
+
Explore Publications {" "} diff --git a/app/reader/ReaderContent.tsx b/app/reader/ReaderContent.tsx index 05d72428..f99e3a41 100644 --- a/app/reader/ReaderContent.tsx +++ b/app/reader/ReaderContent.tsx @@ -1,92 +1,112 @@ "use client"; +import { AtUri } from "@atproto/api"; +import { getPublicationURL } from "app/lish/createPub/getPublicationURL"; +import { PubIcon } from "components/ActionBar/Publications"; import { ShareSmall } from "components/Icons/ShareSmall"; import { Separator } from "components/Layout"; import { useCardBorderHidden } from "components/Pages/useCardBorderHidden"; +import { SpeedyLink } from "components/SpeedyLink"; +import { usePubTheme } from "components/ThemeManager/PublicationThemeProvider"; +import { BaseThemeProvider } from "components/ThemeManager/ThemeProvider"; +import { PubLeafletDocument, PubLeafletPublication } from "lexicons/api"; import Link from "next/link"; +import { blobRefToSrc } from "src/utils/blobRefToSrc"; +import { Json } from "supabase/database.types"; -export const ReaderContent = (props: { root_entity: string }) => { - let cardBorderHidden = useCardBorderHidden(props.root_entity); +export const ReaderContent = (props: { + root_entity: string; + posts: { + publication: { + href: string; + pubRecord: Json; + uri: string; + }; + documents: { data: Json; uri: string; indexed_at: string }; + }[]; +}) => { return (
- {dummyPosts.map((p) => ( - - ))} + {props.posts?.map((p) => )}
); }; const Post = (props: { - title: string; - description: string; - date: string; - read: boolean; - author: string; - pub: string; - cardBorderHidden: boolean; + publication: { + pubRecord: Json; + uri: string; + href: string; + }; + documents: { data: Json | undefined; uri: string; indexed_at: string }; }) => { + let pubRecord = props.publication.pubRecord as PubLeafletPublication.Record; + + let postRecord = props.documents.data as PubLeafletDocument.Record; + let postUri = new AtUri(props.documents.uri); + + let theme = usePubTheme(pubRecord); + let backgroundImage = pubRecord?.theme?.backgroundImage?.image?.ref + ? blobRefToSrc( + pubRecord?.theme?.backgroundImage?.image?.ref, + new AtUri(props.publication.uri).host, + ) + : null; + + let backgroundImageRepeat = pubRecord?.theme?.backgroundImage?.repeat; + let backgroundImageSize = pubRecord?.theme?.backgroundImage?.width || 500; + + let showPageBackground = pubRecord.theme?.showPageBackground; + return ( -
-
+ -
- - {props.pub} - - -
-

{props.title}

+
+
+ +
+

{postRecord.title}

-

{props.description}

-
-
-
- {props.author} +

{postRecord.description}

+
+ + + {pubRecord.name} + + + NAME HERE + + {postRecord.publishedAt && + new Date(postRecord.publishedAt).toLocaleDateString("en-US", { + year: "numeric", + month: "short", + day: "numeric", + })}
- - {props.date}
-
-
+ + ); }; - -let dummyPosts: { - title: string; - description: string; - date: string; - read: boolean; - author: string; - pub: string; -}[] = [ - { - title: "First Post", - description: "this is a description", - date: "Oct 2", - read: false, - author: "jared", - pub: "a warm space", - }, - { - title: "This is a second Tost", - description: "It has another description, as you can see", - date: "Oct 2", - read: false, - author: "celine", - pub: "Celine's Super Soliloquy", - }, - { - title: "A Third Post, A Burnt Toast", - description: - "If the first post is bread, the second is toast, and inevitably the third is a plate of charcoal.", - date: "Oct 2", - read: false, - author: "brendan", - pub: "Scraps", - }, -]; diff --git a/app/reader/page.tsx b/app/reader/page.tsx index f2de1d5e..925153bc 100644 --- a/app/reader/page.tsx +++ b/app/reader/page.tsx @@ -18,6 +18,9 @@ import { NotFoundLayout } from "components/PageLayouts/NotFoundLayout"; import { DashboardLayout } from "components/PageLayouts/DashboardLayout"; import { ReaderContent } from "./ReaderContent"; import { SubscriptionsContent } from "./SubscriptionsContent"; +import { Json } from "supabase/database.types"; +import { getPublicationURL } from "app/lish/createPub/getPublicationURL"; +import { PubLeafletDocument } from "lexicons/api"; export default async function Reader(props: {}) { let cookieStore = await cookies(); @@ -92,14 +95,44 @@ export default async function Reader(props: {}) { .select(`publications(*, documents_in_publications(documents(*)))`) .eq("identity", auth_res?.atp_did); - let subbedPubs = publications?.map((pub) => { - let subbedPubsArr: string[] = []; - pub.publications?.name && subbedPubsArr.push(pub.publications?.name); - return subbedPubsArr; - }); + // Flatten all posts from all publications into a single array + let posts = + publications?.flatMap((publication) => { + const postsInPub = + publication.publications?.documents_in_publications.filter( + (d) => !!d?.documents, + ); + + if (!postsInPub || postsInPub.length === 0) return []; - console.log(subbedPubs); + return postsInPub + .filter( + (postInPub) => + postInPub.documents?.data && + postInPub.documents?.uri && + postInPub.documents?.indexed_at, + ) + .map((postInPub) => ({ + publication: { + href: getPublicationURL(publication.publications!), + pubRecord: publication.publications?.record || null, + uri: publication.publications?.uri || "", + }, + documents: { + data: postInPub.documents!.data, + uri: postInPub.documents!.uri, + indexed_at: postInPub.documents!.indexed_at, + }, + })); + }) || []; + let sortedPosts = posts.sort((a, b) => { + let recordA = a.documents.data as PubLeafletDocument.Record; + let recordB = b.documents.data as PubLeafletDocument.Record; + const dateA = new Date(recordA.publishedAt || 0); + const dateB = new Date(recordB.publishedAt || 0); + return dateB.getTime() - dateA.getTime(); + }); return ( , - content: , + controls: null, + content: ( + + ), }, subs: { controls: null, @@ -141,7 +179,3 @@ export default async function Reader(props: {}) { ); } - -const FocusToggle = () => { - return
focus
; -}; diff --git a/components/ActionBar/Publications.tsx b/components/ActionBar/Publications.tsx index 696f1a3c..e5fe0502 100644 --- a/components/ActionBar/Publications.tsx +++ b/components/ActionBar/Publications.tsx @@ -93,6 +93,8 @@ const PubListEmpty = () => { export const PubIcon = (props: { record: PubLeafletPublication.Record; uri: string; + small?: boolean; + className?: string; }) => { if (!props.record) return; @@ -104,11 +106,15 @@ export const PubIcon = (props: { backgroundSize: "cover", backgroundImage: `url(/api/atproto_images?did=${new AtUri(props.uri).host}&cid=${(props.record.icon?.ref as unknown as { $link: string })["$link"]})`, }} - className="w-6 h-6 rounded-full" + className={`${props.small ? "w-5 h-5" : "w-6 h-6"} rounded-full ${props.className}`} /> ) : ( -
-
+
+
{props.record?.name.slice(0, 1)}
diff --git a/components/PageHeader.tsx b/components/PageHeader.tsx index 0c41ccfe..89eee9ec 100644 --- a/components/PageHeader.tsx +++ b/components/PageHeader.tsx @@ -6,7 +6,6 @@ export const Header = (props: { cardBorderHidden: boolean; }) => { let [scrollPos, setScrollPos] = useState(0); - console.log(props.cardBorderHidden); useEffect(() => { const homeContent = document.getElementById("home-content");