diff --git a/src/templates/DatasetSearch/index.jsx b/src/templates/DatasetSearch/index.jsx index d74a85c5..999b912a 100644 --- a/src/templates/DatasetSearch/index.jsx +++ b/src/templates/DatasetSearch/index.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { useSearchParams, useLocation } from 'react-router-dom'; import qs from 'qs'; import { useSearchAPI, separateFacets } from '@civicactions/data-catalog-services'; @@ -47,6 +47,8 @@ const DatasetSearch = ({ }) => { const [currentResultNumbers, setCurrentResultNumbers] = useState(null); const [noResults, setNoResults] = useState(false); + const [loadingData, setLoadingData] = useState(true); + const loadingRef = useRef(); const location = useLocation(); let [searchParams, setSearchParams] = useSearchParams(); const [filterText, setFilterText] = useState(''); @@ -111,6 +113,14 @@ const DatasetSearch = ({ } }, [page, sort, sortOrder, fulltext, selectedFacets]); + useEffect(() => { + // when loading state was previously true and is now false, display data + if (!loading && loadingRef.current === true) { + setLoadingData(false) + } + loadingRef.current = loading; + }, [loading]) + useEffect(() => { const baseNumber = Number(totalItems) > 0 ? 1 : 0; const startingNumber = baseNumber + (Number(pageSize) * Number(page) - Number(pageSize)); @@ -136,7 +146,10 @@ const DatasetSearch = ({
-+ Showing {currentResultNumbers.startingNumber} -{' '} + {currentResultNumbers.endingNumber} of {currentResultNumbers.total} datasets +
+ )}- Showing {currentResultNumbers.startingNumber} -{' '} - {currentResultNumbers.endingNumber} of {currentResultNumbers.total} datasets + {selectedFacetsMessage(selectedFacets, { + theme: 'Categories', + keyword: 'Tags', + })}
- )} -- {selectedFacetsMessage(selectedFacets, { - theme: 'Categories', - keyword: 'Tags', - })} -
-