diff --git a/app/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx b/app/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx
index 24ef7241..e8148046 100644
--- a/app/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx
+++ b/app/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx
@@ -25,6 +25,7 @@ import { PageWrapper } from "components/Pages/Page";
import { decodeQuotePosition } from "./quotePosition";
import { PollData } from "./fetchPollData";
import { SharedPageProps } from "./PostPages";
+import { PostPrevNextButtons } from "./PostPrevNextButtons";
export function LinearDocumentPage({
blocks,
@@ -56,6 +57,8 @@ export function LinearDocumentPage({
const isSubpage = !!pageId;
+ console.log("prev/next?: " + preferences.showPrevNext);
+
return (
<>
-
+
{
+ let postData = useContext(PostPageContext);
+ let pub = postData?.documents_in_publications[0]?.publications;
+
+ if (!props.showPrevNext || !pub || !postData) return;
+
+ function getPostLink(uri: string) {
+ return pub && uri
+ ? `${getPublicationURL(pub)}/${new AtUri(uri).rkey}`
+ : "leaflet.pub/not-found";
+ }
+ let prevPost = postData?.prevNext?.prev;
+ let nextPost = postData?.prevNext?.next;
+
+ return (
+
+ {/*
*/}
+
+ {nextPost ? (
+
+
+ {nextPost.title}
+
+ ) : (
+
+ )}
+ {prevPost ? (
+
+ {prevPost.title}
+
+
+ ) : (
+
+ )}
+
+
+ );
+};
diff --git a/app/lish/[did]/[publication]/[rkey]/getPostPageData.ts b/app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
index 395b5348..aa0cc515 100644
--- a/app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
+++ b/app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
@@ -10,7 +10,10 @@ export async function getPostPageData(uri: string) {
data,
uri,
comments_on_documents(*, bsky_profiles(*)),
- documents_in_publications(publications(*, publication_subscriptions(*))),
+ documents_in_publications(publications(*,
+ documents_in_publications(documents(uri, data)),
+ publication_subscriptions(*))
+ ),
document_mentions_in_bsky(*),
leaflets_in_publications(*)
`,
@@ -51,10 +54,64 @@ export async function getPostPageData(uri: string) {
?.record as PubLeafletPublication.Record
)?.theme || (document?.data as PubLeafletDocument.Record)?.theme;
+ // Calculate prev/next documents from the fetched publication documents
+ let prevNext:
+ | {
+ prev?: { uri: string; title: string };
+ next?: { uri: string; title: string };
+ }
+ | undefined;
+
+ const currentPublishedAt = (document.data as PubLeafletDocument.Record)
+ ?.publishedAt;
+ const allDocs =
+ document.documents_in_publications[0]?.publications
+ ?.documents_in_publications;
+
+ if (currentPublishedAt && allDocs) {
+ // Filter and sort documents by publishedAt
+ const sortedDocs = allDocs
+ .map((dip) => ({
+ uri: dip?.documents?.uri,
+ title: (dip?.documents?.data as PubLeafletDocument.Record).title,
+ publishedAt: (dip?.documents?.data as PubLeafletDocument.Record)
+ .publishedAt,
+ }))
+ .filter((doc) => doc.publishedAt) // Only include docs with publishedAt
+ .sort(
+ (a, b) =>
+ new Date(a.publishedAt!).getTime() -
+ new Date(b.publishedAt!).getTime(),
+ );
+
+ // Find current document index
+ const currentIndex = sortedDocs.findIndex((doc) => doc.uri === uri);
+
+ if (currentIndex !== -1) {
+ prevNext = {
+ prev:
+ currentIndex > 0
+ ? {
+ uri: sortedDocs[currentIndex - 1].uri || "",
+ title: sortedDocs[currentIndex - 1].title,
+ }
+ : undefined,
+ next:
+ currentIndex < sortedDocs.length - 1
+ ? {
+ uri: sortedDocs[currentIndex + 1].uri || "",
+ title: sortedDocs[currentIndex + 1].title,
+ }
+ : undefined,
+ };
+ }
+ }
+
return {
...document,
quotesAndMentions,
theme,
+ prevNext,
};
}
diff --git a/app/lish/[did]/[publication]/dashboard/settings/PostOptions.tsx b/app/lish/[did]/[publication]/dashboard/settings/PostOptions.tsx
index 289cc121..5e4f2275 100644
--- a/app/lish/[did]/[publication]/dashboard/settings/PostOptions.tsx
+++ b/app/lish/[did]/[publication]/dashboard/settings/PostOptions.tsx
@@ -53,7 +53,8 @@ export const PostOptions = (props: {
showPrevNext: showPrevNext,
},
});
- toast({ type: "success", content: "Posts Updated!" });
+ toast({ type: "success", content: Posts Updated! });
+ console.log(record.preferences?.showPrevNext);
props.setLoading(false);
mutate("publication-data");
}}