Skip to content

Commit

Permalink
Update TideTablePage.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbithell committed Jun 8, 2024
1 parent a9ae32f commit 76b1416
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/components/templates/TideTablePage.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
import * as React from "react"
import type { HeadFC, PageProps } from "gatsby"
import { Card, Center, Container, Group, Image, Text } from "@mantine/core"
import { Card, Center, Container, Group, Image, Table, Text } from "@mantine/core"
import TidalData from "../../../data/tides.json";
import { SEO } from "../../components/SEO";
import Layout from "../navigation/Layout";
import { DateTime } from "luxon";
import { TidesJson_PDFObject, TidesJson_ScheduleObject } from "../../types";


const Page: React.FC<PageProps> = ({ pageContext }: { pageContext: { pdf: TidesJson_PDFObject } }) => {
const firstDayOfMonth = pageContext.pdf.date;
const Page: React.FC<PageProps> = ({ pageContext }) => {
const { pdf } = pageContext as { pdf: TidesJson_PDFObject };
const firstDayOfMonth = pdf.date;
const monthMatch = firstDayOfMonth.split("-")[0] + firstDayOfMonth.split("-")[1];
const tides = TidalData.schedule.filter((element: TidesJson_ScheduleObject) => {
return element.date.startsWith(monthMatch)
});
console.log(tides)
return (
<Layout>
{tides.map((element: TidesJson_ScheduleObject, index: React.Key) => (
<Card shadow="xs" key={index}>

<Text size="xl" fw={500}>{DateTime.fromSQL(element.date).toLocaleString({ weekday: "long", day: "2-digit", month: "long" })}</Text>
{element.groups.map(tide => (
<Group justify="start" mt="md" mb="xs">
<Text size="lg" fw={500} >{DateTime.fromSQL(element.date + " " + tide.time).toLocaleString(DateTime.TIME_SIMPLE)}</Text>
<Text size="lg" fw={200}>{tide.height}m</Text>
</Group>
<Table>
<Table.Thead>
<Table.Tr>
<Table.Th>Date</Table.Th>
<Table.Th>Sunrise</Table.Th>
<Table.Th>Time</Table.Th>
<Table.Th>Height</Table.Th>
<Table.Th>Time</Table.Th>
<Table.Th>Height</Table.Th>
<Table.Th>Sunset</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{tides.map((element: TidesJson_ScheduleObject, index: React.Key) => (
element.groups.map(tide => (
<Table.Tr key={index}>
<Table.Td>{DateTime.fromSQL(element.date).toLocaleString({ weekday: "long", day: "2-digit" })}</Table.Td>
{element.groups.map(tide => (
<>
<Table.Td>{DateTime.fromSQL(element.date + " " + tide.time).toLocaleString(DateTime.TIME_SIMPLE)}</Table.Td>
<Table.Td>{tide.height}</Table.Td>
</>
))}
{element.groups.length === 1 ? <Table.Td colSpan={2}></Table.Td> : null}
</Table.Tr>
))
))}
</Card>
))}
</Table.Tbody>
</Table>
</Layout>
)
}
Expand Down

0 comments on commit 76b1416

Please sign in to comment.