Skip to content

Commit 51932f3

Browse files
committed
removed client root requirement
1 parent da6fe91 commit 51932f3

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/biorepo_components/BiorepoPage.jsx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ import NeonPage from '../lib_components/components/NeonPage/NeonPage';
88
export default function BiorepoPage() {
99
const [config, setConfig] = useState(null);
1010

11-
const getDefaultSidebarLinks = () => {
12-
if (window.location.pathname.endsWith('/publiclist.php')) {
13-
return [
14-
{
15-
name: 'Papers & Publications',
16-
hash: 'https://www.neonscience.org/impact/papers-publications',
17-
},
18-
];
19-
}
20-
return [
21-
{
22-
name: 'Sample Portal',
23-
hash: 'https://biokic4.rc.asu.edu/neon/portal/index.php',
24-
},
25-
];
26-
};
27-
2811
// Get breadcrumbs and sidebar from json based on pathname
2912
const [breadcrumbs, setBreadcrumbs] = useState([]);
3013
const [sidebarLinks, setSidebarLinks] = useState([]);
@@ -66,7 +49,6 @@ export default function BiorepoPage() {
6649

6750
useEffect(() => {
6851
if (!config) return;
69-
setSidebarLinks(getDefaultSidebarLinks());
7052
const fetchBreadcrumbs = async () => {
7153
try {
7254
const response = await fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/breadcrumbs.json`);
@@ -94,9 +76,21 @@ export default function BiorepoPage() {
9476
throw new Error('Failed to fetch sidebar links');
9577
}
9678
const data = await response.json();
97-
const pathname = window.location;
79+
const { pathname } = window.location;
80+
const filename = pathname.split('/').pop();
9881

99-
const sidebarData = data[pathname] || data.default;
82+
const sidebarData = data[filename] || data.default;
83+
if (data[pathname] === undefined) {
84+
sidebarData.links = sidebarData.links.map((link) => {
85+
if (link.name === 'Sample Portal') {
86+
return {
87+
...link,
88+
hash: `${config.CLIENT_ROOT}/${link.hash}`,
89+
};
90+
}
91+
return link;
92+
});
93+
}
10094
setSidebarLinks(sidebarData.links);
10195
setSidebarTitle(sidebarData.sidebarTitle);
10296
} catch (error) {

src/lib_components/components/NeonPage/NeonPage.jsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,17 @@ const NeonPage = (props) => {
418418
const sidebarHashMap = !hasSidebarLinks ? {} : Object.fromEntries(
419419
sidebarLinks.map((link, idx) => [link.hash || '#', idx]),
420420
);
421-
const initialCurrentSidebarHash = sidebarLinks[0].hash;
422-
const [currentSidebarHash, setCurrentSidebarHash] = useState(initialCurrentSidebarHash);
421+
const initialCurrentSidebarHash = (() => {
422+
if (sidebarLinks.length === 5) {
423+
return sidebarLinks[3].hash;
424+
}
425+
if (sidebarLinks.length === 7) {
426+
return sidebarLinks[1].hash;
427+
}
428+
return '#';
429+
})();
430+
const currentSidebarHash = initialCurrentSidebarHash;
431+
// const [currentSidebarHash, setCurrentSidebarHash] = useState(initialCurrentSidebarHash);
423432
const [hashInitialized, setHashInitialized] = useState(false);
424433
const [sidebarExpanded, setSidebarExpanded] = useState(false); // for small viewports only
425434

@@ -441,7 +450,7 @@ const NeonPage = (props) => {
441450
const handleHashChange = () => {
442451
const { hash } = document.location;
443452
if (currentSidebarHash === hash) { return; }
444-
setCurrentSidebarHash(hash);
453+
// setCurrentSidebarHash(hash);
445454
// If standard sidebar mode (scroll to content) also perform the scroll offset here
446455
if (!sidebarLinksAsStandaloneChildren) {
447456
window.setTimeout(() => {
@@ -486,7 +495,7 @@ const NeonPage = (props) => {
486495
(curr.y !== -1 && window.scrollY >= curr.y - detectionBuffer) ? curr.hash : acc
487496
), sidebarLinks[0].hash || '#');
488497
if (currentScrolledHash !== currentSidebarHash) {
489-
setCurrentSidebarHash(currentScrolledHash);
498+
// setCurrentSidebarHash(currentScrolledHash);
490499
}
491500
};
492501
window.addEventListener('scroll', handleScroll);
@@ -503,7 +512,7 @@ const NeonPage = (props) => {
503512
hashInitialized,
504513
setHashInitialized,
505514
currentSidebarHash,
506-
setCurrentSidebarHash,
515+
// setCurrentSidebarHash,
507516
sidebarLinksContainerRef,
508517
getSidebarLinkScrollPosition,
509518
sidebarLinksAsStandaloneChildren,
@@ -808,7 +817,7 @@ const NeonPage = (props) => {
808817
href={hash}
809818
onClick={(
810819
sidebarLinksAsStandaloneChildren ? () => {
811-
setCurrentSidebarHash(hash);
820+
// setCurrentSidebarHash(hash);
812821
if (sidebarExpanded) { setSidebarExpanded(false); }
813822
} : null
814823
)}

0 commit comments

Comments
 (0)