Commit 01700c62 authored by Elisabeth Reuhl's avatar Elisabeth Reuhl
Browse files

Create button for fetching more data

parent 2e635a09
......@@ -44,9 +44,11 @@ export const AppContent = () => {
&& input.selectedObjectId!==0)
});
const {data: dataObjects, loading: loadingObjects, error: errorObjects} =
const {data: dataObjects, loading: loadingObjects, fetchMoreObjects, error: errorObjects} =
useQuery(GET_OBJECTS, {
variables: {
offset: input.offset,
limit: input.limit,
searchTerm: debouncedSearchStr,
catalogIds: input.catalogsCheckedIds,
// only send coordinates if entered values have valid format (floats with at least one decimal place)
......@@ -67,7 +69,7 @@ export const AppContent = () => {
|| (input.boundingBoxCorner1.length!==0 && input.boundingBoxCorner2.length!==0)))
});
const {data: dataObjectsIncremental, loading: loadingFeed, fetchMore} = useQuery(GET_OBJECTS_INCREMENTAL, {
/*const {data: dataObjectsIncremental, loading: loadingFeed, fetchMore} = useQuery(GET_OBJECTS_INCREMENTAL, {
variables: {
searchTerm: debouncedSearchStr,
catalogIds: input.catalogsCheckedIds,
......@@ -81,7 +83,7 @@ export const AppContent = () => {
offset: 0,
limit: 20
}
});
});*/
const {data: dataArchaeoSites, loading: loadingArchaeoSites, error: errorArchaeoSites} = useQuery(GET_ARCHAEOLOGICAL_SITES, {
variables: {
......@@ -148,6 +150,16 @@ export const AppContent = () => {
}
}, [dataObjects, debouncedSearchStr, input.catalogsCheckedIds, input.chronOntologyTerms, input.boundingBoxCorner1, input.boundingBoxCorner2, input.mode, input.arachneCategoriesCheckedIds]);
useEffect(() => {
if (input.fetchMore && dataObjects) {
fetchMoreObjects({
variables: {offset: dataObjects.entitiesMultiFilter.length}
});
dispatch({type: "UPDATE_INPUT", payload: {field: "fetchMore", value: false}});
}
}, [input.fetchMore])
useEffect( () => {
if (dataArchaeoSites && input.mode==="sites" && (debouncedSearchStr
|| (input.boundingBoxCorner1.length!==0 && input.boundingBoxCorner2.length!==0)
......@@ -364,6 +376,10 @@ export const AppContent = () => {
reducer={[input, dispatch]}
/>
<Container maxWidth={"xl"} id="dashboardContainer">
<Button onClick={() => {
//dispatch({type: "UPDATE_INPUT", payload: {field: "offset", value: input.offset + 100}});
dispatch({type: "UPDATE_INPUT", payload: {field: "fetchMore", value: true}});
}}>Fetch more data</Button>
<Layout
bigTile={
(input.bigTileArea==="areaA" && renderAreaA())
......
query searchObjects($searchTerm: String, $catalogIds: [Int], $bbox: [String], $periodTerms: [String], $entityTypes: [RelatedType], $focusAfrica: Boolean, $lang: Languages) {
entitiesMultiFilter(searchString: $searchTerm, catalogIds: $catalogIds, coordinates: $bbox, periods: $periodTerms,
query searchObjects($offset: Int, $limit: Int, $searchTerm: String, $catalogIds: [Int], $bbox: [String], $periodTerms: [String], $entityTypes: [RelatedType], $focusAfrica: Boolean, $lang: Languages) {
entitiesMultiFilter(offset: $offset, limit: $limit, searchString: $searchTerm, catalogIds: $catalogIds, coordinates: $bbox, periods: $periodTerms,
entityTypes: $entityTypes, focusAfrica: $focusAfrica) {
identifier
name
......
......@@ -4,6 +4,9 @@ import { sortByImportance, sortByLabel } from "./utils";
const initialInput = {
//search parameters / filters
offset: 0,
limit: 100,
fetchMore: false,
mode: "objects", //possible values: "objects", "sites", "sitesByRegion"
searchStr: "",
arachneCategoriesCheckedIds: [],
......@@ -19,7 +22,7 @@ const initialInput = {
//for searching related objects or regions
showRelatedObjects: false,
selectedObjectId: 0,
selectedRegionId: 0,
selectedRegionId: 0, //TODO: should this be "selectedSiteId"?
//map
mapBounds: latLngBounds([28.906303, -11.146792], [-3.355435, 47.564145]),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment