Skip to content

Commit 617a6ff

Browse files
author
John Rogers
committed
readded highlighting to build time rendered menubar and reverted to lookup for the study static pages
1 parent 1ec8e37 commit 617a6ff

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

src/app/studies/[slug]/page.tsx

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,57 @@ export default async function StudyPage({
4848
try {
4949
console.log(`Generating static page for study: ${slug}`);
5050

51-
// Fetch the specific study data for this slug
52-
const response = await fetch(
51+
// First, fetch the study by slug to get the UUID
52+
const searchResponse = await fetch(
5353
`https://harmonydataweaviate.azureedge.net/discover/search?query=*&num_results=1&offset=0&resource_type=study&slug=${encodeURIComponent(
5454
slug
5555
)}`
5656
);
5757

58-
if (!response.ok) {
59-
throw new Error(`Failed to fetch study by slug: ${response.statusText}`);
58+
if (!searchResponse.ok) {
59+
throw new Error(
60+
`Failed to fetch study by slug: ${searchResponse.statusText}`
61+
);
6062
}
6163

62-
const data = await response.json();
63-
const studyResult = data.results?.[0];
64+
const searchData = await searchResponse.json();
65+
const studyResult = searchData.results?.[0];
6466

6567
if (!studyResult) {
6668
throw new Error(`Study with slug "${slug}" not found`);
6769
}
6870

69-
console.log(`Found study data for ${slug}:`, studyResult.extra_data?.name);
71+
const uuid = studyResult.extra_data?.uuid;
72+
if (!uuid) {
73+
throw new Error(`Study with slug "${slug}" has no UUID`);
74+
}
75+
76+
console.log(`Found study UUID for ${slug}: ${uuid}`);
77+
78+
// Now fetch the full study data using the UUID via the lookup endpoint
79+
const lookupResponse = await fetch(
80+
`https://harmonydataweaviate.azureedge.net/discover/lookup?uuid=${uuid}`
81+
);
82+
83+
if (!lookupResponse.ok) {
84+
throw new Error(
85+
`Failed to fetch study by UUID: ${lookupResponse.statusText}`
86+
);
87+
}
88+
89+
const lookupData = await lookupResponse.json();
90+
const fullStudyResult = lookupData.results?.[0];
91+
92+
if (!fullStudyResult) {
93+
throw new Error(`Study with UUID "${uuid}" not found in lookup`);
94+
}
95+
96+
console.log(
97+
`Found full study data for ${slug}:`,
98+
fullStudyResult.dataset_schema?.name
99+
);
70100

71-
const study = transformSearchResultToStudyDetail(studyResult);
101+
const study = transformSearchResultToStudyDetail(fullStudyResult);
72102

73103
return <StudyPageClient study={study} />;
74104
} catch (error) {

src/components/Sidebar.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import React from "react";
24
import {
35
Box,
@@ -11,6 +13,7 @@ import Link from "next/link";
1113
import Image from "next/image";
1214
import { LayoutGrid } from "lucide-react";
1315
import { getAssetPrefix } from "@/lib/utils/shared";
16+
import { usePathname } from "next/navigation";
1417

1518
const navigationItems = [
1619
{ text: "Search", icon: getAssetPrefix() + "/icons/discover.svg", href: "/" },
@@ -33,6 +36,8 @@ const navigationItems = [
3336
];
3437

3538
export default function Sidebar() {
39+
const pathname = usePathname();
40+
3641
// Use CSS media queries for responsive behavior instead of client-side logic
3742
return (
3843
<>
@@ -88,17 +93,22 @@ export default function Sidebar() {
8893
key={item.text}
8994
component={Link}
9095
href={item.href}
96+
selected={pathname === item.href}
9197
sx={{
9298
flexDirection: "column",
9399
minWidth: 48,
94100
minHeight: 48,
95101
px: 1,
96102
py: 0.5,
97103
borderRadius: 2,
98-
color: "#444653",
104+
color: pathname === item.href ? "primary.main" : "#444653",
99105
display: "flex",
100106
alignItems: "center",
101107
justifyContent: "center",
108+
bgcolor: pathname === item.href ? "action.selected" : "inherit",
109+
"&.Mui-selected": {
110+
bgcolor: "action.selected",
111+
},
102112
}}
103113
>
104114
<ListItemIcon
@@ -196,12 +206,16 @@ export default function Sidebar() {
196206
<ListItemButton
197207
component={Link}
198208
href={item.href}
209+
selected={pathname === item.href}
199210
sx={{
200211
minHeight: 48,
201212
justifyContent: "center",
202213
px: 2.5,
203214
flexDirection: "column",
204-
color: "#444653",
215+
color: pathname === item.href ? "primary.main" : "#444653",
216+
"&.Mui-selected": {
217+
bgcolor: "action.selected",
218+
},
205219
}}
206220
>
207221
<ListItemIcon

0 commit comments

Comments
 (0)