Skip to content

Commit

Permalink
fly to project fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed Apr 10, 2024
1 parent 180990e commit 68b1aee
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/src/containers/countries/detail/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function CountryDetailPanel() {
},
}
);
const queryParams = useSyncQueryParams();
const queryParams = useSyncQueryParams({ filters: true });
const jsonToCsv = (json: CountryCountryIndicatorFieldsDataItem['attributes'] & Country) => {
let csv = '';

Expand Down
4 changes: 3 additions & 1 deletion client/src/containers/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ export default function MapContainer() {

const handleMapClick = useCallback(
(e: MapLayerMouseEvent) => {
const ProjectData = e.features && e.features.find(({ layer }) => layer.id === 'projects');
const ProjectData =
e.features && e.features.find(({ layer }) => layer.id === 'projects_circle');
const ProjectsDataGeometry = e.features?.find(({ layer }) => layer.id === 'projects_fill');

if (e.features && e.features.length && map) {
if (ProjectData || ProjectsDataGeometry) {
push(
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/projects/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useSyncQueryParams } from '@/hooks/datasets';

export default function ProjectItem({ data }: { data: ProjectListResponseDataItem }) {
const hoveredProjectMap = useAtomValue(hoveredProjectMapAtom);
const queryParams = useSyncQueryParams();
const queryParams = useSyncQueryParams({ filters: true });

return (
data && (
Expand Down
4 changes: 2 additions & 2 deletions client/src/containers/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export default function Sidebar() {
return (
<div className="rounded-8xl absolute bottom-0 left-2 top-0 z-20 my-2 w-16 bg-yellow-700 py-10 text-xs text-yellow-50 xl:left-3 xl:w-20">
<div className="h-[88%]">
<div className="mx-2 flex hidden items-center pb-12 xl:block">
<div className="mx-2 hidden items-center pb-12 xl:block">
<Image src="/images/logo.svg" alt="logo" width={60} height={29} />
</div>

<div className="mx-2 block flex items-center pb-12 xl:hidden">
<div className="mx-2 flex items-center pb-12 xl:hidden">
<Image src="/images/logo.svg" alt="logo" width={48} height={19} />
</div>

Expand Down
31 changes: 29 additions & 2 deletions client/src/hooks/datasets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,37 @@
import { serialize } from './query-parsers';
import { useSyncFilters, useSyncLayers, useSyncBasemap } from './sync-query';

export const useSyncQueryParams = () => {
// Define a type for the data structure
type QueryParamsData = {
filters: any;
layers: any;
settings: any;
};

// Define a type for the exclusion parameters
type ExcludeParams = {
filters?: boolean;
layers?: boolean;
settings?: boolean;
};

export const useSyncQueryParams = (exclude: ExcludeParams = {}) => {
const [filters] = useSyncFilters();
const [layers] = useSyncLayers();
const [settings] = useSyncBasemap();

return serialize({ filters, layers, settings });
// Construct the data object with correct typing
const data: QueryParamsData = { filters, layers, settings };

// Filter out excluded keys
const result: Partial<QueryParamsData> = {};
Object.keys(data).forEach((key) => {
if (!(key in exclude && exclude[key as keyof ExcludeParams])) {
// Use type assertion here to ensure keys are recognized as valid
result[key as keyof QueryParamsData] = data[key as keyof QueryParamsData];
}
});

// Return the serialized object
return serialize(result);
};

0 comments on commit 68b1aee

Please sign in to comment.