@@ -4,19 +4,14 @@ import { calculateStats, getFgbData } from "../map/utils.ts";
4
4
import tArea from "@turf/area" ;
5
5
import tBboxPolygon from "@turf/bbox-polygon" ;
6
6
7
+ // TODO move to types.ts
8
+ /* eslint-disable no-unused-vars */
7
9
export enum MapStatus {
8
10
IDLE = "IDLE" ,
9
11
LOADING = "LOADING" ,
10
12
READY = "READY" ,
11
13
}
12
14
13
- export interface AppState {
14
- map : any ;
15
- mapStatus : MapStatus ;
16
- geojson ?: any ;
17
- currentTimestampGeojson ?: any ;
18
- }
19
-
20
15
export enum AppActionTypes {
21
16
SET_MAP_REF = "SET_MAP_REF" ,
22
17
SET_CURRENT_TIMESTAMP = "SET_CURRENT_TIMESTAMP" ,
@@ -26,6 +21,16 @@ export enum AppActionTypes {
26
21
UPDATE_VIEW_ERROR = "UPDATE_VIEW_ERROR" ,
27
22
}
28
23
24
+ export type AppReducer < State , Action > = ( state : State , action : Action ) => State ;
25
+ /* eslint-enable no-unused-vars */
26
+
27
+ export interface AppState {
28
+ map : any ;
29
+ mapStatus : MapStatus ;
30
+ geojson ?: any ;
31
+ currentTimestampGeojson ?: any ;
32
+ }
33
+
29
34
export type AppAction =
30
35
| {
31
36
type : AppActionTypes . SET_MAP_REF ;
@@ -62,13 +67,11 @@ export const appInitialState = {
62
67
} ,
63
68
} ;
64
69
65
- export type AppReducer < State , Action > = ( state : State , action : Action ) => State ;
66
-
67
70
function applyTimestampFilter ( geojson : any , timestamp : string ) {
68
71
return {
69
72
type : "FeatureCollection" ,
70
73
features : geojson . features . filter (
71
- ( f : any ) => f . properties . timestamp === timestamp
74
+ ( f : any ) => f . properties . timestamp === timestamp ,
72
75
) ,
73
76
} ;
74
77
}
@@ -91,17 +94,15 @@ function appReducer(state: AppState, action: AppAction) {
91
94
const currentTimestamp = timestamps [ timestamps . length - 1 ] ;
92
95
const currentTimestampGeojson = applyTimestampFilter (
93
96
geojson ,
94
- currentTimestamp
97
+ currentTimestamp ,
95
98
) ;
96
99
const stats = calculateStats ( currentTimestampGeojson ) ;
97
100
98
101
const bounds = state . map . getBounds ( ) . toArray ( ) ;
99
102
const [ [ minX , minY ] , [ maxX , maxY ] ] = bounds ;
100
103
const poly = tBboxPolygon ( [ minX , minY , maxX , maxY ] ) ;
101
104
const area = tArea ( poly ) ;
102
- const formattedArea = new Intl . NumberFormat ( ) . format (
103
- ( area / 1e6 ) . toFixed ( 2 )
104
- ) ;
105
+ const formattedArea = new Intl . NumberFormat ( ) . format ( area / 1e6 ) ;
105
106
106
107
return {
107
108
...state ,
@@ -118,7 +119,7 @@ function appReducer(state: AppState, action: AppAction) {
118
119
const { currentTimestamp } = action . data ;
119
120
const currentTimestampGeojson = applyTimestampFilter (
120
121
state . geojson ,
121
- currentTimestamp
122
+ currentTimestamp ,
122
123
) ;
123
124
const stats = calculateStats ( currentTimestampGeojson ) ;
124
125
return {
@@ -161,7 +162,7 @@ const asyncActionHandlers: any = {
161
162
} catch ( error ) {
162
163
console . log ( error ) ;
163
164
alert (
164
- "Unexpected error while loading the map, please see console log."
165
+ "Unexpected error while loading the map, please see console log." ,
165
166
) ;
166
167
}
167
168
} ,
@@ -171,6 +172,6 @@ export const useAppReducer = () => {
171
172
return useReducerAsync (
172
173
logReducer ( appReducer ) ,
173
174
appInitialState ,
174
- asyncActionHandlers
175
+ asyncActionHandlers ,
175
176
) ;
176
177
} ;
0 commit comments