Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/app/story/[storylineId]/[plotIndex]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ import { StoryContent } from "../../../../components/StoryContent";
import { ReadingModeWrapper } from "../../../../components/ReadingModeWrapper";
import Link from "next/link";

/** Deduplicate plots by plot_index, keeping the first occurrence. */
function deduplicateByPlotIndex(plots: { plot_index: number; title: string; content: string | null }[]) {
const seen = new Set<number>();
return plots
.filter((p) => {
if (seen.has(p.plot_index)) return false;
seen.add(p.plot_index);
return true;
})
.map((p) => ({
plotIndex: p.plot_index,
title: p.title || (p.plot_index === 0 ? "Genesis" : `Chapter ${p.plot_index}`),
content: p.content,
}));
}

type Params = Promise<{ storylineId: string; plotIndex: string }>;

const appUrl = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000";
Expand Down Expand Up @@ -112,11 +128,7 @@ export default async function PlotDetailPage({ params }: { params: Params }) {
<ReadingModeWrapper
storylineId={sid}
storylineTitle={sl.title}
chapters={allPlots.map((ap) => ({
plotIndex: ap.plot_index,
title: ap.title || (ap.plot_index === 0 ? "Genesis" : `Chapter ${ap.plot_index}`),
content: ap.content,
}))}
chapters={deduplicateByPlotIndex(allPlots)}
initialPlotIndex={pidx}
/>
</div>
Expand Down
22 changes: 17 additions & 5 deletions src/app/story/[storylineId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ import { CommentSection } from "../../../components/CommentSection";
import { MobileActionBar } from "../../../components/MobileActionBar";
import { UsdPriceTag } from "../../../components/UsdPriceTag";

/** Deduplicate plots by plot_index, keeping the first occurrence. */
function deduplicateByPlotIndex(plots: Plot[]) {
const seen = new Set<number>();
return plots
.filter((p) => {
if (seen.has(p.plot_index)) return false;
seen.add(p.plot_index);
return true;
})
.map((p) => ({
plotIndex: p.plot_index,
title: p.title || (p.plot_index === 0 ? "Genesis" : `Chapter ${p.plot_index}`),
content: p.content,
}));
}

type Params = Promise<{ storylineId: string }>;

const appUrl = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000";
Expand Down Expand Up @@ -157,11 +173,7 @@ export default async function StoryPage({ params }: { params: Params }) {
<ReadingModeWrapper
storylineId={id}
storylineTitle={sl.title}
chapters={plots.map((p) => ({
plotIndex: p.plot_index,
title: p.title || (p.plot_index === 0 ? "Genesis" : `Chapter ${p.plot_index}`),
content: p.content,
}))}
chapters={deduplicateByPlotIndex(plots)}
initialPlotIndex={0}
/>
}
Expand Down
Loading