Skip to content

Commit caba5a1

Browse files
committed
feat: support preset deeplink to default database to openneuro; refs #95
1 parent c176b90 commit caba5a1

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/pages/SearchPage.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const matchesKeyword = (item: RegistryItem, keyword: string) => {
5454
);
5555
};
5656

57+
const getPresetKey = () => {
58+
return new URLSearchParams(window.location.search).get("preset");
59+
};
60+
5761
const SearchPage: React.FC = () => {
5862
const dispatch = useAppDispatch();
5963
const [hasSearched, setHasSearched] = useState(false);
@@ -115,6 +119,20 @@ const SearchPage: React.FC = () => {
115119
value !== "any"
116120
);
117121

122+
useEffect(() => {
123+
// If a #query=... already exists, existing effect will handle it.
124+
if (window.location.hash.startsWith("#query=")) return;
125+
126+
const key = getPresetKey(); // "openneuro"
127+
if (key === "openneuro") {
128+
const initial = { database: "openneuro" };
129+
// set initial form/filter state
130+
setFormData(initial);
131+
setAppliedFilters(initial);
132+
setHasSearched(false); // set it to true if want to auto-run search
133+
}
134+
}, []);
135+
118136
// parse query from url on page load
119137
useEffect(() => {
120138
const hash = window.location.hash;
@@ -359,7 +377,7 @@ const SearchPage: React.FC = () => {
359377
const showNoResults =
360378
hasSearched &&
361379
!loading &&
362-
!hasDbMatches &&
380+
// !hasDbMatches &&
363381
(!hasDatasetMatches || backendEmpty);
364382
return (
365383
<Container
@@ -838,10 +856,23 @@ const SearchPage: React.FC = () => {
838856

839857
{/* Single place to show the red message */}
840858
{showNoResults && (
841-
<Typography sx={{ color: Colors.error }}>
842-
No results found based on your criteria. Please adjust
843-
the filters and try again.
844-
</Typography>
859+
<Box sx={{ minHeight: 200 }}>
860+
<Typography
861+
variant="h6"
862+
sx={{
863+
mb: 1.5,
864+
mt: 1.5,
865+
borderBottom: "1px solid lightgray",
866+
}}
867+
>
868+
Search Results
869+
</Typography>
870+
871+
<Typography sx={{ color: Colors.error }}>
872+
No datasets or subjects found. Please adjust the
873+
filters and try again.
874+
</Typography>
875+
</Box>
845876
)}
846877

847878
{hasSearched &&

src/pages/UpdatedDatasetDetailPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const UpdatedDatasetDetailPage: React.FC = () => {
6060

6161
const handleSelectRevision = (newRev?: string | null) => {
6262
setSearchParams((prev) => {
63-
const p = new URLSearchParams(prev);
63+
const p = new URLSearchParams(prev); // copy of the query url
6464
if (newRev) p.set("rev", newRev);
6565
else p.delete("rev");
6666
return p;

0 commit comments

Comments
 (0)