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: Fix map sort params #823

Merged
merged 2 commits into from
Dec 13, 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { FC, useState, useContext, useEffect, useCallback } from "react";
import { useAppDispatch } from "@hooks/hooks";
import { useAppDispatch, useAppSelector } from "@hooks/hooks";
import COMPLAINT_TYPES from "@apptypes/app/complaint-types";
import { ComplaintFilterContext } from "@providers/complaint-filter-provider";
import { ComplaintFilters } from "@apptypes/complaints/complaint-filters/complaint-filters";
import { ComplaintRequestPayload } from "@/app/types/complaints/complaint-filters/complaint-request-payload";
import LeafletMapWithServerSideClustering from "@components/mapping/leaflet-map-with-server-side-clustering";
import { generateApiParameters, get } from "@common/api";
import config from "@/config";
import { setComplaint, setComplaintSearchParameters, setMappedComplaintsCount } from "@/app/store/reducers/complaints";
import {
selectComplaintSearchParameters,
setComplaint,
setComplaintSearchParameters,
setMappedComplaintsCount,
} from "@/app/store/reducers/complaints";
import { selectDefaultPageSize } from "@/app/store/reducers/app";

type Props = {
type: string;
Expand All @@ -17,11 +23,13 @@ type Props = {
export const generateMapComplaintRequestPayload = (
complaintType: string,
filters: ComplaintFilters,
page: number,
pageSize: number,
sortColumn: string,
sortOrder: string,
searchQuery: string,
): ComplaintRequestPayload => {
const {
sortColumn,
sortOrder,
region,
zone,
community,
Expand Down Expand Up @@ -53,6 +61,8 @@ export const generateMapComplaintRequestPayload = (
outcomeAnimalStartDateFilter: outcomeAnimalStartDate,
outcomeAnimalEndDateFilter: outcomeAnimalEndDate,
query: searchQuery,
page,
pageSize,
};

switch (complaintType) {
Expand Down Expand Up @@ -84,6 +94,8 @@ export const ComplaintMapWithServerSideClustering: FC<Props> = ({ type, searchQu
//-- the state from the context is not the same state as used in the rest of the application
//-- this is self-contained, rename the state locally to make clear
const { state: filters } = useContext(ComplaintFilterContext);
const defaultPageSize = useAppSelector(selectDefaultPageSize);
const storedSearchParams = useAppSelector(selectComplaintSearchParameters);

const fetchMapData = useCallback(
async (
Expand All @@ -100,7 +112,15 @@ export const ComplaintMapWithServerSideClustering: FC<Props> = ({ type, searchQu
},
) => {
setLoadingMapData(true);
let payload = generateMapComplaintRequestPayload(type, filters, searchQuery);
let payload = generateMapComplaintRequestPayload(
type,
filters,
storedSearchParams.page || 1,
storedSearchParams.pageSize || defaultPageSize,
storedSearchParams.sortColumn,
storedSearchParams.sortOrder,
searchQuery,
);
dispatch(setComplaint(null));
dispatch(setComplaintSearchParameters(payload));

Expand Down
Loading