-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #17
- Loading branch information
Showing
5 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Box, Text } from "theme-ui" | ||
import { EBG_SETTINGS } from "../app/config" | ||
import { useAppSelector } from "../app/hooks" | ||
import { selectActiveEbg } from "../services/configSlice" | ||
import { usePollEcfmpByFir } from "../services/ecfmpApi" | ||
import { DateTime } from "luxon" | ||
|
||
export const ECFMP = () => { | ||
const activeEbg = useAppSelector(selectActiveEbg) | ||
const { data: flowMeasures } = usePollEcfmpByFir(EBG_SETTINGS[activeEbg].fir) | ||
|
||
return flowMeasures?.map((fm) => { | ||
const start = DateTime.fromISO(fm.starttime).toUTC() | ||
const end = DateTime.fromISO(fm.endtime).toUTC() | ||
const active = DateTime.utc() >= start | ||
|
||
return ( | ||
<Box mb={3} key={fm.ident}> | ||
<Box> | ||
<Text variant="label">{fm.ident}</Text>:{" "} | ||
<Text variant="label" sx={{ color: active ? "green" : "blue" }}> | ||
{active | ||
? `Active, expires ${end.toRelative()}` | ||
: `Will be active ${start.toRelative()}`} | ||
</Text>{" "} | ||
( | ||
{`${start.toFormat("y-MM-dd HH:mm")}-${end.toFormat( | ||
"y-MM-dd HH:mm", | ||
)}`} | ||
) | ||
</Box> | ||
<pre style={{ whiteSpace: "pre-wrap" }}>{fm.reason}</pre> | ||
<Box> | ||
<Text variant="label"> | ||
{fm.measure.type.replace("_", " ").toUpperCase()} | ||
</Text> | ||
{fm.measure.value && `: ${fm.measure.value}`} | ||
</Box> | ||
<Box> | ||
{fm.filters | ||
.map( | ||
(f) => | ||
`${f.type.replace("_", " ").toUpperCase()}${ | ||
f.value && | ||
`: ${f.value instanceof Array ? f.value.join(", ") : f.value}` | ||
}`, | ||
) | ||
.join("; ")} | ||
</Box> | ||
</Box> | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { createApi } from "@reduxjs/toolkit/query/react" | ||
import { fetchWithAuth } from "../app/auth" | ||
|
||
export type FilterEvent = { | ||
event_id: number | ||
event_vatcan: string | null | ||
} | ||
|
||
export type Filter = { | ||
type: | ||
| "ADEP" | ||
| "ADES" | ||
| "level_above" | ||
| "level_below" | ||
| "level" | ||
| "member_event" | ||
| "member_non_event" | ||
| "waypoint" | ||
value: (string | number | FilterEvent)[] | number | ||
} | ||
|
||
export type Measure = { | ||
type: | ||
| "prohibit" | ||
| "minimum_departure_interval" | ||
| "average_departure_interval" | ||
| "per_hour" | ||
| "miles_in_trail" | ||
| "max_ias" | ||
| "max_mach" | ||
| "ias_reduction" | ||
| "mach_reduction" | ||
| "ground_stop" | ||
| "mandatory_route" | ||
value: number | string[] | null | ||
} | ||
|
||
export type FlowMeasure = { | ||
ident: string | ||
event_id: number | null | ||
reason: string | ||
starttime: string | ||
endtime: string | ||
measure: Measure | ||
filters: Filter[] | ||
notified_firs: string[] | ||
withdrawn_at: string | null | ||
} | ||
|
||
export const ecfmpApi = createApi({ | ||
reducerPath: "ecfmp", | ||
baseQuery: fetchWithAuth, | ||
endpoints: (builder) => ({ | ||
getByFir: builder.query<FlowMeasure[], string>({ | ||
query: (fir) => ({ | ||
url: `ecfmp/${fir}`, | ||
}), | ||
}), | ||
}), | ||
}) | ||
|
||
export const usePollEcfmpByFir: typeof ecfmpApi.useGetByFirQuery = ( | ||
fir, | ||
options, | ||
) => ecfmpApi.useGetByFirQuery(fir, { pollingInterval: 60000, ...options }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters