fix(StorePage): update totalRowsCount logic to consider filteredCategories length
The logic for setting the totalRowsCount in the StorePage component has been updated. Previously, it was only considering the count returned from the API response. Now, it takes into account the length of the filteredCategories array as well. If the filteredCategories array is empty, the totalRowsCount is set to the count returned from the API response. Otherwise, it is set to the length of the results array in the API response. This change ensures that the totalRowsCount accurately reflects the number of rows in the search results, taking into account any applied filters. Also, the condition for rendering the PaginatorComponent has been updated. Previously, it was checking if the loading state is false or the searchData array is not empty. Now, it only checks if the loading state is false and the searchData array is not empty. This change ensures that the PaginatorComponent is only rendered when the loading state is false and there are search results available.
This commit is contained in:
parent
d4017af18f
commit
af29139af3
1 changed files with 6 additions and 2 deletions
|
|
@ -84,7 +84,11 @@ export default function StorePage(): JSX.Element {
|
|||
.then((res) => {
|
||||
setLoading(false);
|
||||
setSearchData(res?.results ?? []);
|
||||
setTotalRowsCount(Number(res?.count ?? 0));
|
||||
setTotalRowsCount(
|
||||
filteredCategories?.length === 0
|
||||
? Number(res?.count ?? 0)
|
||||
: res?.results?.length ?? 0
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
setSearchData([]);
|
||||
|
|
@ -291,7 +295,7 @@ export default function StorePage(): JSX.Element {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(!loading || searchData.length !== 0) && (
|
||||
{!loading && searchData.length !== 0 && (
|
||||
<div className="relative my-6">
|
||||
<PaginatorComponent
|
||||
storeComponent={true}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue