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 bbox not defined issue #161

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-pre-post-scripts=true
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@sentry/react": "^7.81.1",
"@togglecorp/fujs": "^2.1.1",
"@togglecorp/re-map": "^0.2.0-beta-6",
"@turf/bbox": "^6.5.0",
"@turf/circle": "^6.5.0",
"@turf/bbox": "^7.1.0",
"@turf/circle": "^7.1.0",
"graphql": "^16.8.1",
"mapbox-gl": "^1.13.0",
"patch-package": "^8.0.0",
Expand Down
17 changes: 0 additions & 17 deletions patches/@turf+bbox+6.5.0.patch

This file was deleted.

17 changes: 0 additions & 17 deletions patches/@turf+circle+6.5.0.patch

This file was deleted.

61 changes: 36 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/App/PageError/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { useEffect } from 'react';
import { useRouteError } from 'react-router-dom';

function PageError() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const error = useRouteError() as unknown as any;

useEffect(
() => {
// eslint-disable-next-line no-console
console.error(error);
},
[error],
);

return (
<h1>
{error.statusText || error.message}
Expand Down
8 changes: 4 additions & 4 deletions src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function AreaInfoDetail(props: Props) {
const [latStr, lonStr] = centerStr.split(',');
const options = {
steps: 50,
units: 'kilometers',
units: 'kilometers' as const,
};

const point = [+latStr, +lonStr];
Expand All @@ -203,13 +203,13 @@ function AreaInfoDetail(props: Props) {
[selectedFeatureDetails],
);

const selectedPolygonBounds = useMemo(() => {
const selectedPolygonBounds = useMemo((): LngLatBoundsLike => {
if (isDefined(selectedPolygon)) {
return getBbox(selectedPolygon.boundary);
return getBbox(selectedPolygon.boundary) as LngLatBoundsLike;
}

if (isDefined(selectedCircle)) {
return getBbox(selectedCircle.boundary);
return getBbox(selectedCircle.boundary) as LngLatBoundsLike;
}

return defaultBounds;
Expand Down
7 changes: 5 additions & 2 deletions src/views/AlertDetails/CountryAlertMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
MapLayer,
} from '@togglecorp/re-map';
import getBbox from '@turf/bbox';
import type { FillLayer } from 'mapbox-gl';
import type {
FillLayer,
LngLatBoundsLike,
} from 'mapbox-gl';

import BaseMap from '#components/domain/BaseMap';
import { AlertDetailsQuery } from '#generated/types/graphql';
Expand Down Expand Up @@ -70,7 +73,7 @@ function CountryAlertMap(props: Props) {
}, [data]);

const bounds = useMemo(() => (
data?.country ? getBbox(data?.country.bbox) : undefined
data?.country ? getBbox(data.country.bbox) as LngLatBoundsLike : undefined
), [data?.country]);

return (
Expand Down
13 changes: 8 additions & 5 deletions src/views/Home/AlertsMap/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import getBbox from '@turf/bbox';
import {
type FillLayer,
LngLatBoundsLike,
MapboxGeoJSONFeature,
} from 'mapbox-gl';

Expand All @@ -47,7 +46,7 @@ import AlertDataContext from '../../AlertDataContext';

import styles from './styles.module.css';

const defaultBounds: LngLatBoundsLike = [-160, -60, 190, 80];
const defaultBounds: [number, number, number, number] = [-160, -60, 190, 80];

interface MapMinZoomProps {
zoom: number;
Expand Down Expand Up @@ -166,16 +165,20 @@ function Map(props: Props) {
);

const bounds = useMemo(
() => {
(): [number, number, number, number] => {
if (isDefined(activeAdmin1Id) && isDefined(activeAdmin1Details?.public.admin1?.bbox)) {
return getBbox(activeAdmin1Details?.public.admin1?.bbox);
return getBbox(
activeAdmin1Details?.public.admin1?.bbox,
) as [number, number, number, number];
}

if (
isDefined(activeCountryId)
&& isDefined(activeCountryDetails?.public.country?.bbox)
) {
return getBbox(activeCountryDetails?.public.country?.bbox);
return getBbox(
activeCountryDetails?.public.country?.bbox,
) as [number, number, number, number];
}

return defaultBounds;
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"compilerOptions": {
"paths": {
/* Issue with turf library https://github.com/Turfjs/turf/issues/2598#issuecomment-2084656403 */
"@turf/bbox": ["./node_modules/@turf/bbox/dist/js/index.d.ts"],
"@turf/circle": ["./node_modules/@turf/circle/dist/js/index.d.ts"],

"#generated/*": ["./generated/*"],
"#assets/*": ["./src/assets/*"],
"#components/*": ["./src/components/*"],
Expand Down