Skip to content

Commit

Permalink
202 fikse styling satellite page borders (#251)
Browse files Browse the repository at this point in the history
* emoji

* feat(frontend): commit for merge

* feat(frontend): ✨ Refactor satellite page and add SatelliteStatsTableRow component

* refactor(frontend): 🎨 Refactor SVG component and update table layout

* build(ci/cd): 🚀 Add country-emoji package to frontend dependencies
  • Loading branch information
Mads Hermansen authored and GitHub committed Apr 10, 2024
1 parent b95948d commit 1aa55dd
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 43 deletions.
6 changes: 6 additions & 0 deletions frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "0.2.0",
"country-emoji": "^1.5.6",
"framer-motion": "^11.0.24",
"globe.gl": "^2.32.2",
"gsap": "^3.12.5",
Expand Down
70 changes: 30 additions & 40 deletions frontend/src/app/satellites/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { gql } from "@/__generated__/gql";
import SatelliteStatsTableRow from "@/components/satelliteData/SatelliteStatsTableRow";
import { getClient } from "@/lib/ApolloClient";
import SatelliteCard from "@/components/ui/satelliteCard";
import {
PageHeader,
PageHeaderAndSubtitle,
PageSubtitle,
} from "@/components/PageHeader";

const STRAPI_URL = process.env.STRAPI_URL;
const GET_SATELLITES = gql(`
query GET_SATELLITES {
satellites {
Expand Down Expand Up @@ -38,38 +31,35 @@ export default async function Satellites() {
});

return (
<div>
<PageHeaderAndSubtitle>
<PageHeader>Satellites</PageHeader>
<PageSubtitle>
Theese are all the satellites we have worked on.
</PageSubtitle>
</PageHeaderAndSubtitle>
<div className="flex flex-wrap justify-center gap-4 md:justify-start">
{graphqlData?.data?.satellites?.data?.map(
(satellite: any) => {
let previewImage =
satellite?.attributes?.previewImage?.data
?.attributes?.url;
if (STRAPI_URL && previewImage != undefined) {
previewImage = STRAPI_URL + previewImage;
}
let satelliteName =
satellite?.attributes?.name ?? "";
let missionStatus =
satellite?.attributes?.missionStatus ?? "";
return (
// eslint-disable-next-line react/jsx-key
<SatelliteCard
satelliteName={satelliteName}
missionStatus={missionStatus}
previewImage={previewImage}
satelliteId={satellite.id}
></SatelliteCard>
);
},
)}
</div>
<div className="flex w-full flex-col items-center justify-center">
<h1 className="my-10 text-4xl font-extrabold text-white">
Satellites
</h1>
<table className="w-4/5 table-auto border-collapse rounded-md border-b border-white shadow">
<thead>
<tr className="border-y border-white px-3 py-2 text-left text-white">
<th className="px-6">Satellite</th>
<th className="px-6">Speed</th>
<th className="px-6">Altitude</th>
<th className="px-6">Latitude</th>
<th className="px-6">Longitude</th>
</tr>
</thead>
<tbody>
{graphqlData?.data?.satellites?.data?.map(
(satellite: any) => {
let satelliteName =
satellite?.attributes?.name ?? "";
return (
<SatelliteStatsTableRow
key={satellite.id}
satName={satelliteName}
/>
);
},
)}
</tbody>
</table>
</div>
);
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/satelliteData/SatelliteDataHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useState, useEffect } from "react";
import { convertSatrec, SatelliteInfo } from "@/lib/convertSatrec";
import { useSatelliteStore } from "@/lib/store";
import { flag } from "country-emoji";

const updateInterval = 50;

Expand Down Expand Up @@ -82,11 +83,9 @@ export default function SatelliteDataHome() {
{satelliteInfo
? "Above " + satelliteInfo.country
: "Loading..."}
{satelliteInfo && " " + flag(satelliteInfo.country)}
</p>
</div>
<div>
<p className="text-gray-400">Flag Icon</p>
</div>
</div>
</div>
);
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/components/satelliteData/SatelliteStatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,22 @@ export default function SatelliteStatsTable({
</Table>
);
}

import type { SVGProps } from "react";

export function MaterialSymbolsSpeedOutline(props: SVGProps<SVGSVGElement>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={192}
height={192}
viewBox="0 0 24 24"
{...props}
>
<path
fill="currentColor"
d="M10.45 15.5q.6.6 1.55.588t1.4-.688L19 7l-8.4 5.6q-.675.45-.712 1.375t.562 1.525M12 4q1.475 0 2.838.412T17.4 5.65l-1.9 1.2q-.825-.425-1.712-.637T12 6Q8.675 6 6.337 8.338T4 14q0 1.05.288 2.075T5.1 18h13.8q.575-.95.838-1.975T20 13.9q0-.9-.213-1.75t-.637-1.65l1.2-1.9q.75 1.175 1.188 2.5T22 13.85t-.325 2.725t-1.025 2.475q-.275.45-.75.7t-1 .25H5.1q-.525 0-1-.25t-.75-.7q-.65-1.125-1-2.387T2 14q0-2.075.788-3.887t2.15-3.175t3.187-2.15T12 4m.175 7.825"
></path>
</svg>
);
}
80 changes: 80 additions & 0 deletions frontend/src/components/satelliteData/SatelliteStatsTableRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use client";
import { useState, useEffect } from "react";
import { convertSatrec, SatelliteInfo } from "@/lib/convertSatrec";
import { useSatelliteStore } from "@/lib/store";
import Link from "next/link";

const updateInterval = 10;

export default function SatelliteStatsTableRow({
satName,
}: {
satName: string;
}) {
const { satelliteData, fetchAndSetSatelliteData } = useSatelliteStore();
const [satelliteInfo, setSatelliteInfo] = useState<SatelliteInfo | null>(
null,
);

// Fetch satellite data on component mount
useEffect(() => {
fetchAndSetSatelliteData(satName);
}, [fetchAndSetSatelliteData, satName]);

// Update satellite info every `updateInterval` ms
useEffect(() => {
const intervalId = setInterval(() => {
// Access satellite data by name
const satData = satelliteData[satName];
if (satData) {
const updatedInfo = convertSatrec(satData.satrec, satData.name);
setSatelliteInfo(updatedInfo);
}
}, updateInterval);

// Clear interval on component unmount
return () => clearInterval(intervalId);
}, [satelliteData, satName]);

// Display loading message if satellite info is not available
if (!satelliteInfo) {
return (
<tr>
<td className="px-6 py-4">Loading...</td>
<td className="px-6 py-4">Loading...</td>
<td className="px-6 py-4">Loading...</td>
<td className="px-6 py-4">Loading...</td>
<td className="px-6 py-4">Loading...</td>
</tr>
);
}
return (
<tr className="duration-150 hover:bg-white hover:text-black">
<td className="px-6 py-4">
<Link href={`/satellites/${satName}`} className="w-full">
{satName}
</Link>
</td>
<td className="px-6 py-4">
<Link href={`/satellites/${satName}`} className="w-full">
{satelliteInfo.velocity + " km/s"}
</Link>
</td>
<td className="px-6 py-4">
<Link href={`/satellites/${satName}`} className="w-full">
{satelliteInfo.altitude + " km"}
</Link>
</td>
<td className="px-6 py-4">
<Link href={`/satellites/${satName}`} className="w-full">
{satelliteInfo.latitudeDeg + "° N"}
</Link>
</td>
<td className="px-6 py-4">
<Link href={`/satellites/${satName}`} className="w-full">
{satelliteInfo.longitudeDeg + "° E"}
</Link>
</td>
</tr>
);
}

0 comments on commit 1aa55dd

Please sign in to comment.