Skip to content

Commit

Permalink
fix: Fix map sort params (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayr974 authored Dec 13, 2024
1 parent f4d5997 commit bf51907
Showing 1 changed file with 25 additions and 5 deletions.
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

0 comments on commit bf51907

Please sign in to comment.