fix: ui fixes in transcript listing for books

This commit is contained in:
gosangam
2026-06-17 14:14:45 +05:30
parent fc2aef0c3d
commit bc1798b31b
2 changed files with 20 additions and 2 deletions
@@ -8,7 +8,7 @@ import { buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { ChevronLeft, ChevronRight, Menu, Calendar, Clock, MapPin } from "lucide-react";
import { PlayAudioButton } from "@/app/(app)/transcriptions/[slug]/play-audio-button";
import { parseChapter } from "@/lib/book-reference";
import { parseChapter, parseVerse } from "@/lib/book-reference";
import {
Drawer,
DrawerClose,
@@ -105,7 +105,11 @@ function buildSections(
.map(([k, v]) => ({
key: k,
label: v.label,
transcriptions: v.items,
// Order lectures by verse ascending (e.g. 2.1, 2.3, 2.4…),
// irrespective of year. Stable sort keeps year order within a verse.
transcriptions: v.items
.slice()
.sort((a, b) => parseVerse(a.reference) - parseVerse(b.reference)),
})),
}));
}
+14
View File
@@ -28,6 +28,20 @@ export function bookTitle(code: string): string {
return b ? b.title : "";
}
/**
* Extract the (starting) verse number from a reference, for ordering lectures
* within a chapter. The verse is the last dotted numeric component, and for a
* range we take the start: "BG 2.13" → 13, "SB 1.2.3" → 3, "SB 3.27.11–16" →
* 11, "CC Madhya-līlā 20.101" → 101, "ISO Mantra 4" → 4. References with no
* number (e.g. bare "NOD") sort last (stable → keep their incoming order).
*/
export function parseVerse(reference: string | null): number {
const m = (reference ?? "").trim().match(/(\d+(?:\.\d+)*)/);
if (!m) return Number.MAX_SAFE_INTEGER;
const parts = m[1].split(".");
return Number(parts[parts.length - 1]);
}
/** A section is a canto (SB) or līlā (CC); null for books without that level. */
export type ChapterSection = {
key: string;