cleanup, improve date formatting, move date filtering to client side, make statuses more 'airport-y'
This commit is contained in:
45
src/App.js
45
src/App.js
@@ -1,44 +1,32 @@
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import { format, formatDistanceToNow, startOfDay } from 'date-fns';
|
||||
import { formatInTimeZone } from 'date-fns-tz';
|
||||
|
||||
import './App.css';
|
||||
import '@fontsource/roboto-mono';
|
||||
|
||||
import Schedule from './components/schedule/Schedule';
|
||||
import Radar from './components/Radar';
|
||||
import { format, formatDistanceToNow } from 'date-fns';
|
||||
import Metar from './components/metar/Metar';
|
||||
|
||||
const statuses = {
|
||||
OPEN: 'ON TIME',
|
||||
COMPLETED: 'LANDED',
|
||||
'IN PROGRESS': 'ENROUTE',
|
||||
};
|
||||
const days = [
|
||||
'Sunday',
|
||||
'Monday',
|
||||
'Tuesday',
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday',
|
||||
];
|
||||
const pad = n => String(n).padStart(2, '0');
|
||||
|
||||
function formatUtcDate(date) {
|
||||
return (
|
||||
`${days[date.getUTCDay()]} ${pad(date.getUTCDate())}/${pad(date.getUTCMonth() + 1)}/${date.getUTCFullYear()} ` +
|
||||
`${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())}Z`
|
||||
);
|
||||
}
|
||||
|
||||
const normaliseData = data => {
|
||||
return data.map(d => {
|
||||
const date = format(d.start, 'dd/MM');
|
||||
const start = format(d.start, 'HH:mm');
|
||||
const end = format(d.end, 'HH:mm');
|
||||
const status = statuses[d.status] ?? d.status;
|
||||
const startTime = format(d.start, 'HH:mm');
|
||||
const endTime = format(d.end, 'HH:mm');
|
||||
const status = statuses[d.status.toUpperCase()] ?? d.status;
|
||||
|
||||
return {
|
||||
...d,
|
||||
date,
|
||||
start,
|
||||
end,
|
||||
startTime,
|
||||
endTime,
|
||||
status,
|
||||
};
|
||||
});
|
||||
@@ -58,10 +46,17 @@ function App() {
|
||||
}, []);
|
||||
|
||||
const fetchData = async () => {
|
||||
const today = startOfDay(new Date());
|
||||
|
||||
try {
|
||||
const res = await fetch('https://mattfidd.rocks/veroDashboard.json');
|
||||
const json = await res.json();
|
||||
setData(normaliseData(json.slice(1)));
|
||||
|
||||
const normalisedData = normaliseData(json.slice(1)).filter(
|
||||
d => new Date(d.end) >= today,
|
||||
);
|
||||
|
||||
setData(normalisedData);
|
||||
setDataUpdated(json[0].updatedAt);
|
||||
} catch (err) {
|
||||
console.error('Error fetching data:', err);
|
||||
@@ -79,7 +74,7 @@ function App() {
|
||||
}, []);
|
||||
|
||||
const formattedTime = useMemo(() => {
|
||||
return formatUtcDate(time);
|
||||
return formatInTimeZone(time, 'UTC', 'EEEE dd/MM HH:mm:ss') + 'Z';
|
||||
}, [time]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,6 +4,11 @@ import ScheduleRow from './ScheduleRow';
|
||||
import ScheduleCell from './ScheduleCell';
|
||||
|
||||
const widths = [85, 85, 85, 85, 400, 150];
|
||||
const colours = {
|
||||
LANDED: '#6FB165',
|
||||
ENROUTE: '#3197E5',
|
||||
CANCELLED: '#E54331',
|
||||
};
|
||||
|
||||
const Schedule = ({ data }) => {
|
||||
return (
|
||||
@@ -56,8 +61,8 @@ const Schedule = ({ data }) => {
|
||||
<ScheduleRow bg={i % 2 === 1} key={row.id}>
|
||||
<ScheduleCell width={widths[0]}>{row.name}</ScheduleCell>
|
||||
<ScheduleCell width={widths[1]}>{row.date}</ScheduleCell>
|
||||
<ScheduleCell width={widths[2]}>{row.start}</ScheduleCell>
|
||||
<ScheduleCell width={widths[3]}>{row.end}</ScheduleCell>
|
||||
<ScheduleCell width={widths[2]}>{row.startTime}</ScheduleCell>
|
||||
<ScheduleCell width={widths[3]}>{row.endTime}</ScheduleCell>
|
||||
<ScheduleCell width={widths[4]}>
|
||||
{row.description?.length
|
||||
? row.description
|
||||
@@ -69,15 +74,7 @@ const Schedule = ({ data }) => {
|
||||
<ScheduleCell width={widths[5]}>{row.location}</ScheduleCell>
|
||||
<ScheduleCell
|
||||
end="true"
|
||||
color={
|
||||
row.status.toUpperCase() === 'COMPLETED'
|
||||
? '#6FB165'
|
||||
: row.status.toUpperCase() === 'IN PROGRESS'
|
||||
? '#3197E5'
|
||||
: row.status.toUpperCase() === 'CANCELLED'
|
||||
? '#E54331'
|
||||
: undefined
|
||||
}
|
||||
color={colours[row.status.toUpperCase()]}
|
||||
>
|
||||
{row.status}
|
||||
</ScheduleCell>
|
||||
|
||||
Reference in New Issue
Block a user