diff --git a/app/lish/[did]/[publication]/PublicationHomeLayout.tsx b/app/lish/[did]/[publication]/PublicationHomeLayout.tsx new file mode 100644 index 00000000..4324f834 --- /dev/null +++ b/app/lish/[did]/[publication]/PublicationHomeLayout.tsx @@ -0,0 +1,24 @@ +"use client"; + +import { usePreserveScroll } from "src/hooks/usePreserveScroll"; + +export function PublicationHomeLayout(props: { + uri: string; + showPageBackground: boolean; + children: React.ReactNode; +}) { + let { ref } = usePreserveScroll(props.uri); + return ( +
+
+ {props.children} +
+
+ ); +} diff --git a/app/lish/[did]/[publication]/page.tsx b/app/lish/[did]/[publication]/page.tsx index 0d217124..20487e88 100644 --- a/app/lish/[did]/[publication]/page.tsx +++ b/app/lish/[did]/[publication]/page.tsx @@ -15,6 +15,7 @@ import { SpeedyLink } from "components/SpeedyLink"; import { QuoteTiny } from "components/Icons/QuoteTiny"; import { CommentTiny } from "components/Icons/CommentTiny"; import { LocalizedDate } from "./LocalizedDate"; +import { PublicationHomeLayout } from "./PublicationHomeLayout"; export default async function Publication(props: { params: Promise<{ publication: string; did: string }>; @@ -66,131 +67,126 @@ export default async function Publication(props: { record={record} pub_creator={publication.identity_did} > -
-
-
- {record?.icon && ( -
- )} -

- {publication.name} -

-

- {record?.description}{" "} +

+ {record?.icon && ( +
+ )} +

+ {publication.name} +

+

+ {record?.description}{" "} +

+ {profile && ( +

+ by {profile.displayName}{" "} + + @{profile.handle} +

- {profile && ( -

- by {profile.displayName}{" "} - - @{profile.handle} - -

- )} -
- -
+ )} +
+
-
- {publication.documents_in_publications - .filter((d) => !!d?.documents) - .sort((a, b) => { - let aRecord = a.documents - ?.data! as PubLeafletDocument.Record; - let bRecord = b.documents - ?.data! as PubLeafletDocument.Record; - const aDate = aRecord.publishedAt - ? new Date(aRecord.publishedAt) - : new Date(0); - const bDate = bRecord.publishedAt - ? new Date(bRecord.publishedAt) - : new Date(0); - return bDate.getTime() - aDate.getTime(); // Sort by most recent first - }) - .map((doc) => { - if (!doc.documents) return null; - let uri = new AtUri(doc.documents.uri); - let doc_record = doc.documents - .data as PubLeafletDocument.Record; - let quotes = - doc.documents.document_mentions_in_bsky[0].count || 0; - let comments = - record?.preferences?.showComments === false - ? 0 - : doc.documents.comments_on_documents[0].count || 0; +
+
+ {publication.documents_in_publications + .filter((d) => !!d?.documents) + .sort((a, b) => { + let aRecord = a.documents?.data! as PubLeafletDocument.Record; + let bRecord = b.documents?.data! as PubLeafletDocument.Record; + const aDate = aRecord.publishedAt + ? new Date(aRecord.publishedAt) + : new Date(0); + const bDate = bRecord.publishedAt + ? new Date(bRecord.publishedAt) + : new Date(0); + return bDate.getTime() - aDate.getTime(); // Sort by most recent first + }) + .map((doc) => { + if (!doc.documents) return null; + let uri = new AtUri(doc.documents.uri); + let doc_record = doc.documents + .data as PubLeafletDocument.Record; + let quotes = + doc.documents.document_mentions_in_bsky[0].count || 0; + let comments = + record?.preferences?.showComments === false + ? 0 + : doc.documents.comments_on_documents[0].count || 0; - return ( - -
- -

{doc_record.title}

-

- {doc_record.description} -

-
+ return ( + +
+ +

{doc_record.title}

+

+ {doc_record.description} +

+
-
-

- {doc_record.publishedAt && ( - - )}{" "} -

- {comments > 0 || quotes > 0 ? "| " : ""} - {quotes > 0 && ( +
+

+ {doc_record.publishedAt && ( + + )}{" "} +

+ {comments > 0 || quotes > 0 ? "| " : ""} + {quotes > 0 && ( + + {quotes} + + )} + {comments > 0 && + record?.preferences?.showComments !== false && ( - {quotes} + {comments} )} - {comments > 0 && - record?.preferences?.showComments !== false && ( - - {comments} - - )} -
-
- - ); - })} -
+
+
+
+ ); + })}
-
+ ); diff --git a/components/Pages/Page.tsx b/components/Pages/Page.tsx index f9c7144f..59b5183c 100644 --- a/components/Pages/Page.tsx +++ b/components/Pages/Page.tsx @@ -16,6 +16,7 @@ import { focusPage } from "."; import { PageOptions } from "./PageOptions"; import { CardThemeProvider } from "components/ThemeManager/ThemeProvider"; import { useDrawerOpen } from "app/lish/[did]/[publication]/[rkey]/Interactions/InteractionDrawer"; +import { usePreserveScroll } from "src/hooks/usePreserveScroll"; export function Page(props: { entityID: string; @@ -83,6 +84,7 @@ export const PageWrapper = (props: { pageType: "canvas" | "doc"; drawerOpen: boolean | undefined; }) => { + let { ref } = usePreserveScroll(props.id); return ( // this div wraps the contents AND the page options. // it needs to be its own div because this container does NOT scroll, and therefore doesn't clip the absolutely positioned pageOptions @@ -95,6 +97,7 @@ export const PageWrapper = (props: { it needs to be a separate div so that the user can scroll from anywhere on the page if there isn't a card border */}