Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case where load more not work #163

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading