Skip to content

Commit

Permalink
Merge pull request #163 from aodn/features/5861-load-more-button-bug
Browse files Browse the repository at this point in the history
Fix case where load more not work
  • Loading branch information
NekoLyn authored Sep 15, 2024
2 parents 880c7a5 + 350de49 commit 69feba1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/pages/search-page/subpages/ResultSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import {
DEFAULT_SEARCH_PAGE,
fetchResultAppendStore,
} from "../../../components/common/store/searchReducer";
import React, { useCallback, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import ResultCards from "../../../components/result/ResultCards";
import { OGCCollection } from "../../../components/common/store/OGCCollectionDefinitions";
import {
OGCCollection,
OGCCollections,
} from "../../../components/common/store/OGCCollectionDefinitions";
import { useSelector } from "react-redux";
import store, {
getComponentState,
Expand Down Expand Up @@ -45,12 +48,13 @@ const ResultSection: React.FC<SearchResultListProps> = ({
const reduxContents = useSelector<RootState, CollectionsQueryType>(
searchQueryResult
);

// Use to remember last layout, it is either LIST or GRID at the moment
const [currentLayout, setCurrentLayout] = useState<
SearchResultLayoutEnum.LIST | SearchResultLayoutEnum.GRID
>(SearchResultLayoutEnum.LIST);

const fetchMore = useCallback(() => {
const fetchMore = useCallback(async () => {
// This is very specific to how elastic works and then how to construct the query
const componentParam: ParameterState = getComponentState(store.getState());
// Use standard param to get fields you need, record is stored in redux,
Expand All @@ -60,9 +64,9 @@ const ResultSection: React.FC<SearchResultListProps> = ({
pagesize: DEFAULT_SEARCH_PAGE,
searchafter: reduxContents.result.search_after,
});

dispatch(fetchResultAppendStore(paramPaged));
}, [dispatch, reduxContents]);
// Must use await so that record updated before you exit this call
await dispatch(fetchResultAppendStore(paramPaged));
}, [dispatch, reduxContents.result.search_after]);

const onChangeLayout = useCallback(
(layout: SearchResultLayoutEnum) => {
Expand Down

0 comments on commit 69feba1

Please sign in to comment.