Skip to content

Commit 0ba4735

Browse files
authored
Merge pull request #29 from AdaInTheLab/fix/note-card-link
SCMS [SCMS] Make Lab Note cards locale-aware and link to detail view 🔗
2 parents 416feee + ad4b652 commit 0ba4735

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/components/labnotes/LabNoteCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// src/components/labnotes/LabNoteCard.tsx
3131
import React from "react";
3232
import { Link } from "react-router-dom";
33+
const { i18n } = useTranslation("labNotesPage");
3334
import { useTranslation } from "react-i18next";
3435
import type { LabNote } from "@/lib/labNotes";
3536

@@ -83,6 +84,7 @@ type Props = {
8384
};
8485

8586
export function LabNoteCard({ note, index }: Props) {
87+
const locale = i18n.language || "en";
8688
const { t } = useTranslation("labNotesPage");
8789
// Prefer canonical department_id; dept is optional label
8890
const deptKey = (note.dept ?? note.department_id ?? "scms").toLowerCase();
@@ -236,7 +238,7 @@ export function LabNoteCard({ note, index }: Props) {
236238
</span>
237239

238240
<Link
239-
to={`/lab-notes/${note.slug}`}
241+
to={`/${locale}/lab-notes/${note.slug}`}
240242
className={`text-xs font-bold uppercase tracking-widest transition-all ${styles.text} hover:tracking-[0.2em]`}
241243
>
242244
{t("readMore", { defaultValue: "Open Note" })}

src/pages/LabNoteDetailPage.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ import { fetchLabNoteBySlug, getLabNotes } from "@/lib/labNotes";
3232
import type { LabNote } from "@/lib/labNotes";
3333

3434
type RouteParams = {
35-
id?: string; // slug-style id
35+
slug?: string;
36+
locale?: string; // if you add :locale routes
3637
};
3738

3839
export function LabNoteDetailPage() {
39-
const { id } = useParams<RouteParams>();
40+
const { slug, locale: routeLocale } = useParams<RouteParams>();
4041
const { i18n, t } = useTranslation("labNotesPage");
41-
const locale = i18n.language || "en";
42+
const locale = routeLocale || i18n.language || "en";
43+
const base = `/${locale}`;
4244

4345
const [note, setNote] = useState<LabNote | null>(null);
4446
const [loading, setLoading] = useState(true);
4547

4648
useEffect(() => {
47-
if (!id) return;
49+
if (!slug) return;
4850

4951
const controller = new AbortController();
5052
let alive = true;
@@ -53,7 +55,7 @@ export function LabNoteDetailPage() {
5355
setLoading(true);
5456

5557
try {
56-
const data = await fetchLabNoteBySlug(locale, id, controller.signal);
58+
const data = await fetchLabNoteBySlug(locale, slug, controller.signal);
5759

5860
if (!alive) return;
5961
setNote(data);
@@ -71,7 +73,7 @@ export function LabNoteDetailPage() {
7173
console.error(e);
7274

7375
// Local fallback (useful when API is down)
74-
const local = getLabNotes(locale).find((n) => n.id === id) ?? null;
76+
const local = getLabNotes(locale).find((n) => n.id === slug) ?? null;
7577
setNote(local);
7678
} finally {
7779
if (alive) setLoading(false);
@@ -83,7 +85,7 @@ export function LabNoteDetailPage() {
8385
alive = false;
8486
controller.abort();
8587
};
86-
}, [id, locale]);
88+
}, [slug, locale]);
8789

8890
if (loading) {
8991
return (
@@ -108,7 +110,7 @@ export function LabNoteDetailPage() {
108110
This entry has been retracted or never existed in this timeline.
109111
</p>
110112
<Link
111-
to="/lab-notes"
113+
to={`${base}/lab-notes`}
112114
className="mt-8 text-lyric hover:text-ada transition-colors"
113115
>
114116
← Return to Registry
@@ -127,7 +129,7 @@ export function LabNoteDetailPage() {
127129
{/* Breadcrumb */}
128130
<nav className="mb-8 flex items-center justify-between">
129131
<Link
130-
to="/lab-notes"
132+
to={`${base}/lab-notes`}
131133
className="group inline-flex items-center gap-2 rounded-full
132134
border border-slate-800 bg-slate-950/40 px-4 py-2
133135
text-xs font-mono uppercase tracking-[0.2em] text-slate-400

src/router/routes.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ export const router = createBrowserRouter([
9191
// Future-friendly dynamic detail route (if/when needed)
9292
{ path: "departments/:id", element: (<Suspense fallback={<PageLoader />}><DepartmentDetailPage /></Suspense> ) },
9393

94+
// List
9495
{ path: "lab-notes", element: (<Suspense fallback={<PageLoader />}><LabNotesPage /> </Suspense> )},
95-
{ path: "lab-notes/:id", element: <LabNoteDetailPage /> },
96+
{ path: ":locale/lab-notes", element: (<Suspense fallback={<PageLoader />}><LabNotesPage /> </Suspense> )},
97+
98+
// Detail (pick ONE param name; use slug)
9699
{ path: "lab-notes/:slug", element: <LabNoteDetailPage /> },
100+
{ path: ":locale/lab-notes/:slug", element: <LabNoteDetailPage /> },
97101

98102
{ path: "videos", element: (<Suspense fallback={<PageLoader />}><VideoArchivePage /></Suspense> ) },
99103
{ path: "videos/:slug", element: <VideoDetailPage /> },

0 commit comments

Comments
 (0)