Skip to content

Commit

Permalink
chore: update mapbox types, remove types/mapbox-gl and use native types
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael Arce <[email protected]>
  • Loading branch information
raphael-arce committed Oct 14, 2024
1 parent fa5749b commit bf434ae
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 28 deletions.
11 changes: 0 additions & 11 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@technologiestiftung/eslint-plugin": "0.1.1",
"@technologiestiftung/prettier-config": "1.0.0",
"@technologiestiftung/semantic-release-config": "1.2.4",
"@types/mapbox-gl": "3.4.0",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-hovered-pump.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { Pump, usePumpStore } from "./use-pump-store";

export function useHoveredPump(map: mapboxgl.Map | undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-hovered-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { useTreeStore } from "../../tree-detail/stores/tree-store";

export function useHoveredTree(map: mapboxgl.Map | undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-map-interaction.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { useEffect } from "react";
import { useFilterStore } from "../../filter/filter-store";
import { useHoveredPump } from "./use-hovered-pump";
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-map-pumps-interaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { useEffect, useRef } from "react";
import { useFilterStore } from "../../filter/filter-store";
import { useSelectedPump } from "./use-selected-pump";
Expand Down
3 changes: 1 addition & 2 deletions src/components/map/hooks/use-map-setup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import React, { useEffect } from "react";
import { useMapStore } from "../map-store";
import { useTreeCircleStyle } from "./use-tree-circle-style";
Expand Down Expand Up @@ -80,7 +80,6 @@ export function useMapSetup(
type: "circle",
source: "trees",
"source-layer": import.meta.env.VITE_MAPBOX_TREES_TILESET_LAYER,
interactive: true,
paint: {
"circle-pitch-alignment": "map",
"circle-radius": circleRadius,
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-map-trees-interaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { useEffect, useState } from "react";
import { useProfileStore } from "../../../shared-stores/profile-store.tsx";
import { useFilterStore } from "../../filter/filter-store";
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-pump-store.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { create } from "zustand";

export interface Pump {
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-selected-pump.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { Pump, usePumpStore } from "./use-pump-store";

export function useSelectedPump(map: mapboxgl.Map | undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/hooks/use-selected-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { useEffect, useRef } from "react";
import { useTreeStore } from "../../tree-detail/stores/tree-store";
import { useUrlState } from "../../router/store";
Expand Down
5 changes: 4 additions & 1 deletion src/components/map/hooks/use-tree-circle-style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function useTreeCircleStyle() {
TREE_YELLOW_COLOR,
} = useMapConstants();

const circleRadius = {
const circleRadius: {
base: number;
stops: [[number, number], [number, number]];
} = {
base: 1.75,
stops: [
[11, 1],
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/map-store.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";
import { create } from "zustand";

interface MapState {
Expand Down
29 changes: 25 additions & 4 deletions src/components/tree-detail/hooks/use-update-tree-waterings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import mapboxgl from "mapbox-gl";
import * as mapboxgl from "mapbox-gl";

/* eslint-disable-next-line no-shadow */
enum UpdateAction {
ADD = "ADD",
REMOVE = "REMOVE",
}

function getTodaysWaterings(
featureState: { [p: string]: unknown } | null | undefined,
) {
if (!featureState || !featureState.todays_waterings) {
return 0;
}

if (typeof featureState.todays_waterings === "string") {
return parseInt(featureState.todays_waterings);
}

if (typeof featureState.todays_waterings === "number") {
return featureState.todays_waterings;
}

console.error(
"could not parse featureState.todays_watering:",
featureState.todays_waterings,
);

return 0;
}

/* eslint-disable-next-line max-params */
function updateTreeWaterings(
map: mapboxgl.Map | undefined,
Expand All @@ -19,9 +42,7 @@ function updateTreeWaterings(
sourceLayer: "trees",
});

const todaysWateringAmount = featureState
? parseInt(featureState.todays_waterings ?? 0)
: 0;
const todaysWateringAmount = getTodaysWaterings(featureState);

const todaysWateringSum =
updateAction === UpdateAction.ADD
Expand Down

0 comments on commit bf434ae

Please sign in to comment.