Skip to content

Commit

Permalink
map bounds changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed May 7, 2024
1 parent 3b747ae commit 80a292a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 46 deletions.
Binary file removed client/cypress/downloads/downloads.html
Binary file not shown.
30 changes: 15 additions & 15 deletions client/cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
describe('navigation', () => {
// it('redirects to project page', () => {
// cy.visit('/').url().should('be.equal', 'http://localhost:3000/projects');
// });
it('redirects to project page', () => {
cy.visit('/').url().should('be.equal', 'http://localhost:3000/projects');
});

// it('access to project detail page and switch dashboard', () => {
// cy.visit('/').wait(10000);
// cy.get('[data-cy="projects-list-tab"]').should('exist');
// cy.get('[data-cy="projects-list-tab"]').click();
// cy.get('[data-cy="project-item-link"]').first().click();
// // cy.get('button[data-cy="project-dashboard-button"]').click().wait(3000);
// // cy.get('[data-cy="project-dashboard"]').should('exist');
// // cy.get('button[data-cy="project-dashboard-button"]').click();
// // cy.get('[data-cy="project-dashboard"]').should('not.exist');
// });
it('access to project detail page and switch dashboard', () => {
cy.visit('/').wait(10000);
cy.get('[data-cy="projects-list-tab"]').should('exist');
cy.get('[data-cy="projects-list-tab"]').click();
cy.get('[data-cy="project-item-link"]').first().click();
cy.get('button[data-cy="project-dashboard-button"]').click().wait(3000);
cy.get('[data-cy="project-dashboard"]').should('exist');
cy.get('button[data-cy="project-dashboard-button"]').click();
cy.get('[data-cy="project-dashboard"]').should('not.exist');
});

it('access to country detail page', () => {
cy.visit('/').wait(10000);
cy.get('a[data-cy="sidebar-tab-countries"]').click({ force: true }).wait(1000);
// cy.get('[data-cy="country-item"]').first().click().wait(10000);
// cy.get('[data-cy="country-detail-name"]').should('exist');
cy.get('[data-cy="country-item"]').first().click().wait(10000);
cy.get('[data-cy="country-detail-name"]').should('exist');
});

it('access to datasets and displays an info dialog', () => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/map/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const DEFAULT_VIEW_STATE: Partial<ViewState> = {
longitude: 0,
};

export const DEFAULT_BBOX: Bbox = [-84.05,-46.96,227.66,64.23];
export const DEFAULT_BBOX: Bbox = [-84.05, -46.96, 227.66, 64.23];
24 changes: 5 additions & 19 deletions client/src/containers/countries/item.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
'use client';

import { useCallback } from 'react';

import Flag from 'react-world-flags';

import { useRouter } from 'next/navigation';

import { useSetAtom } from 'jotai';
import Link from 'next/link';

import { tmpBboxAtom } from '@/store';

import { useGetCountryIndicatorFields } from '@/types/generated/country-indicator-field';
import { CountryListResponseDataItem } from '@/types/generated/strapi.schemas';
import type { Bbox } from '@/types/map';

import { useSyncQueryParams } from '@/hooks/datasets';
export default function CountryItem({ data }: { data: CountryListResponseDataItem }) {
const setTempBbox = useSetAtom(tmpBboxAtom);

const queryParams = useSyncQueryParams();
const { push } = useRouter();
const queryParams = useSyncQueryParams({ bbox: true });

const { data: projectsCountIndicator } = useGetCountryIndicatorFields(
{
Expand All @@ -36,16 +28,10 @@ export default function CountryItem({ data }: { data: CountryListResponseDataIte
}
);

const handleClick = useCallback(() => {
setTempBbox(data.attributes?.bbox as Bbox);
push(`/countries/${data.id}${queryParams}&bbox=${data.attributes?.bbox}`);
}, [data, push, queryParams, setTempBbox]);

return (
<button
type="button"
<Link
href={`/countries/${data.id}${queryParams}&bbox=[${data.attributes?.bbox}]`}
data-cy="country-item"
onClick={handleClick}
className="flex items-center justify-between space-x-4 rounded-lg border border-gray-100 bg-white py-2 pl-2 pr-4 text-sm text-yellow-900 no-underline shadow-sm transition-all duration-300 hover:border-yellow-500"
>
<div className="flex items-center space-x-4">
Expand All @@ -64,6 +50,6 @@ export default function CountryItem({ data }: { data: CountryListResponseDataIte
{projectsCountIndicator?.attributes?.value === 1 ? 'project' : 'projects'}
</p>
)}
</button>
</Link>
);
}
19 changes: 12 additions & 7 deletions client/src/containers/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import PopupContainer from '@/containers/map/popup';
import MapSettingsManager from '@/containers/map/settings/manager';

import Map from '@/components/map';
import { DEFAULT_BBOX } from '@/components/map/constants';
import Controls from '@/components/map/controls';
import SettingsControl from '@/components/map/controls/settings';
import ZoomControl from '@/components/map/controls/zoom';
Expand All @@ -45,7 +46,7 @@ const DEFAULT_PROPS: CustomMapProps = {
zoom: 2,
pitch: 0,
bearing: 0,
bounds: [68.711178, -11.476973, 131.333249, 21.087406],
bounds: DEFAULT_BBOX as Bbox,
},
minZoom: 2,
maxZoom: 20,
Expand All @@ -72,7 +73,7 @@ export default function MapContainer() {
const layersInteractiveIds = useAtomValue(layersInteractiveIdsAtom);
const setHoveredProjectMap = useSetAtom(hoveredProjectMapAtom);
const [cursor, setCursor] = useState<'grab' | 'pointer'>('grab');
const [bboxURL, setBboxURL] = useSyncBbox();
const [bboxFromURL, setBboxFromURL] = useSyncBbox();

const [tmpBbox, setTmpBbox] = useAtom(tmpBboxAtom);
const sidebarOpen = useAtomValue(openAtom);
Expand Down Expand Up @@ -108,6 +109,7 @@ export default function MapContainer() {
);

const handleMapViewStateChange = useCallback(() => {
console.log('handle view state');
if (map) {
const b = map
.getBounds()
Expand All @@ -116,10 +118,10 @@ export default function MapContainer() {
.map((v: number) => {
return parseFloat(v.toFixed(2));
}) as Bbox;
setBboxURL(b);
setBboxFromURL(b);
setTmpBbox(null);
}
}, [map, setBboxURL, setTmpBbox]);
}, [map, setBboxFromURL, setTmpBbox]);

const handleMapClick = useCallback(
(e: MapLayerMouseEvent) => {
Expand Down Expand Up @@ -266,11 +268,14 @@ export default function MapContainer() {
data-cy="map"
initialViewState={{
...initialViewState,
...(bboxURL && {
bounds: bboxURL as LngLatBoundsLike,
...(bboxFromURL && {
bounds: bboxFromURL as LngLatBoundsLike,
}),
}}
bounds={tmpBounds}
bounds={{
...tmpBounds,
bbox: bboxFromURL as Bbox,
}}
cursor={cursor}
minZoom={minZoom}
maxZoom={maxZoom}
Expand Down
10 changes: 6 additions & 4 deletions client/src/containers/projects/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { MouseEvent, useCallback, useState } from 'react';

import Link from 'next/link';
import { useRouter } from 'next/navigation';

import { useSetAtom } from 'jotai';
Expand Down Expand Up @@ -31,7 +32,7 @@ export default function ProjectsList() {
const [filtersSettings] = useSyncFilters();
const setHoveredProjectList = useSetAtom(hoveredProjectMapAtom);
const router = useRouter();
const queryParams = useSyncQueryParams();
const queryParams = useSyncQueryParams({ bbox: true });

const { data, isFetching, isFetched, isError } = useGetProjects(
{
Expand Down Expand Up @@ -207,17 +208,18 @@ export default function ProjectsList() {
<div className="flex flex-col space-y-2">
{data &&
data.map((project) => (
<button
type="button"
<Link
legacyBehavior={false}
key={project?.id}
data-value={project?.attributes?.project_code}
data-bbox={project?.attributes?.bbox}
onClick={handleClick}
onMouseEnter={handleHover}
onMouseLeave={() => setHoveredProjectList(null)}
href={`/projects/${project?.attributes?.project_code}${queryParams}&bbox=[${project?.attributes?.bbox}]`}
>
<ProjectItem data={project} />
</button>
</Link>
))}
</div>
</ScrollArea>
Expand Down

0 comments on commit 80a292a

Please sign in to comment.