Skip to content

Commit 77aed5e

Browse files
committed
feat: add loading spinner while fetching search results; resolve #40
1 parent 4e11a3a commit 77aed5e

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/pages/SearchPage.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { generateSchemaWithDatabaseEnum } from "./searchformSchema";
2-
import { Typography, Container, Box, Button } from "@mui/material";
2+
import {
3+
Typography,
4+
Container,
5+
Box,
6+
Button,
7+
CircularProgress,
8+
} from "@mui/material";
39
import Form from "@rjsf/mui";
410
import validator from "@rjsf/validator-ajv8";
511
import DatasetCard from "components/SearchPage/DatasetCard";
@@ -24,10 +30,11 @@ const SearchPage: React.FC = () => {
2430
const registry = useAppSelector(
2531
(state: RootState) => state.neurojson.registry
2632
);
33+
const loading = useAppSelector((state: RootState) => state.neurojson.loading);
2734

2835
const [formData, setFormData] = useState<Record<string, any>>({});
2936
const [showSubjectFilters, setShowSubjectFilters] = useState(false);
30-
const [visibleCount, setVisibleCount] = useState(15);
37+
const [visibleCount, setVisibleCount] = useState(10);
3138

3239
// form UI
3340
const uiSchema = useMemo(() => {
@@ -218,7 +225,7 @@ const SearchPage: React.FC = () => {
218225
setFormData({});
219226
setHasSearched(false);
220227
dispatch(fetchMetadataSearchResults({}));
221-
setVisibleCount(15);
228+
setVisibleCount(10);
222229
};
223230

224231
// show more function
@@ -237,6 +244,7 @@ const SearchPage: React.FC = () => {
237244
width: "100%",
238245
}}
239246
>
247+
<Typography variant="h4">Metadata Search</Typography>
240248
<Box
241249
sx={{
242250
display: "flex",
@@ -254,17 +262,6 @@ const SearchPage: React.FC = () => {
254262
minWidth: "35%",
255263
}}
256264
>
257-
<Form
258-
schema={schema}
259-
onSubmit={handleSubmit}
260-
validator={validator}
261-
// liveValidate
262-
formData={formData}
263-
onChange={({ formData }) => setFormData(formData)}
264-
uiSchema={uiSchema}
265-
fields={customFields}
266-
/>
267-
268265
<Box
269266
sx={{
270267
display: "flex",
@@ -302,6 +299,16 @@ const SearchPage: React.FC = () => {
302299
Reset
303300
</Button>
304301
</Box>
302+
<Form
303+
schema={schema}
304+
onSubmit={handleSubmit}
305+
validator={validator}
306+
// liveValidate
307+
formData={formData}
308+
onChange={({ formData }) => setFormData(formData)}
309+
uiSchema={uiSchema}
310+
fields={customFields}
311+
/>
305312
</Box>
306313
<Box>
307314
{!hasSearched && (
@@ -333,7 +340,14 @@ const SearchPage: React.FC = () => {
333340
>
334341
{hasSearched && (
335342
<Box mt={4}>
336-
{Array.isArray(searchResults) ? (
343+
{loading ? (
344+
<Box textAlign="center" my={4}>
345+
<CircularProgress />
346+
<Typography mt={2} color="text.secondary">
347+
Loading search results...
348+
</Typography>
349+
</Box>
350+
) : Array.isArray(searchResults) ? (
337351
<>
338352
<Typography
339353
variant="h6"

src/pages/searchformSchema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { JSONSchema7 } from "json-schema";
22

33
export const baseSchema: JSONSchema7 = {
4-
title: "Metadata Search",
4+
// title: "Metadata Search",
5+
title: "",
56
type: "object",
67
properties: {
78
keyword: {

0 commit comments

Comments
 (0)