From 9bdbe3beca932174c955ad41a4951eecc12a84ba Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 20 Sep 2024 12:18:44 +0200 Subject: [PATCH] Website: improve loading animation (#349) --- website/package.json | 3 +- website/src/components/PagefindResults.tsx | 83 ++++++++++++---------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/website/package.json b/website/package.json index eba3525..de316cf 100644 --- a/website/package.json +++ b/website/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "build:all": "npm run build && npx pagefind ./out" }, "dependencies": { "@emotion/cache": "^11.11.0", diff --git a/website/src/components/PagefindResults.tsx b/website/src/components/PagefindResults.tsx index 590137d..5b527e4 100644 --- a/website/src/components/PagefindResults.tsx +++ b/website/src/components/PagefindResults.tsx @@ -8,7 +8,6 @@ import { Chip, Container, IconButton, - LinearProgress, List, ListItem, ListItemAvatar, @@ -36,6 +35,33 @@ export type BasicListItem = { key: string; }; +const LoadingSkeleton = () => ( + + + {[0, 1].map((key) => ( + + + + + + + } + secondary={} + /> + + ))} + + +); + const useMobile = () => useMediaQuery(useTheme().breakpoints.down("md")); export function PagefindResults() { @@ -58,25 +84,32 @@ export function PagefindResults() { const isMobile = useMobile(); const [searchResults, setSearchResults] = useState(null); + const [loading, setLoading] = useState(); const [items, setItems] = useState(null); - const { search, loading, error } = usePagefindSearch(); + const { + search, + loading: loadingPagefindModule, + error: errorPagefindModule, + } = usePagefindSearch(); useEffect(() => { const init = async () => { console.log({ search, term, filters: { from, to } }); if (search) { + setLoading(true); let raw = await search(term, { filters: { from, to }, sort: { weight: "desc" }, }); setSearchResults(raw?.results || []); + setLoading(false); } }; init(); }, [term, from, to, search]); - console.log({ search, loading, error }); + console.log({ search, loadingPagefindModule, errorPagefindModule }); const handleChangeRowsPerPage = ( event: React.ChangeEvent @@ -133,43 +166,17 @@ export function PagefindResults() { } }; - if (loading) { - return ( - - - {[0, 1].map((key) => ( - - - - - - - } - secondary={} - /> - - ))} - - - ); + if (loadingPagefindModule) { + return ; } - if (!loading && error) { + if (!loadingPagefindModule && errorPagefindModule) { return ( - + Why this might have happened
    @@ -201,8 +208,8 @@ export function PagefindResults() { }} > - {items === null ? ( - + {loading || items == null ? ( + ) : ( <>