{time}
-
-
+ |
+
|
@@ -137,3 +143,16 @@ function timeFormatString(timeFormat: TimeFormat): string {
return "HHmm";
}
}
+
+function getDefaultIcon(skyCover: number, isDay: boolean): IconProp {
+ switch (true) {
+ case skyCover < 20:
+ return isDay ? faSun : faMoon;
+ case skyCover < 60:
+ return isDay ? faCloudSun : faCloudMoon;
+ case skyCover < 80:
+ return isDay ? faCloudsSun : faCloudsMoon;
+ default:
+ return faClouds;
+ }
+}
diff --git a/src/features/outlook/OutlookTable.tsx b/src/features/outlook/OutlookTable.tsx
index 5a27d38..6d65bad 100644
--- a/src/features/outlook/OutlookTable.tsx
+++ b/src/features/outlook/OutlookTable.tsx
@@ -57,11 +57,15 @@ function NWSOutlookRows({ weather }: { weather: NWSWeather }) {
hour,
weather.properties.temperature,
)?.value;
+ const observations = findValue(hour, weather.properties.weather)?.value;
+ const skyCover = findValue(hour, weather.properties.skyCover)?.value;
if (windDirection == null) return;
if (windSpeed == null) return;
if (windGust == null) return;
if (temperature == null) return;
+ if (observations == null) return;
+ if (skyCover == null) return;
return (
);
}),
@@ -97,6 +103,8 @@ function OpenMeteoOutlookRows({ weather }: { weather: OpenMeteoWeather }) {
windSpeed={data.windSpeed}
windGust={data.windGust}
temperature={data.temperature}
+ observations={data.weather}
+ skyCover={data.cloudCover}
/>
);
}),
diff --git a/src/features/weather/header/NWSWeather.tsx b/src/features/weather/header/NWSWeather.tsx
index 37c4e3f..d3afc32 100644
--- a/src/features/weather/header/NWSWeather.tsx
+++ b/src/features/weather/header/NWSWeather.tsx
@@ -24,16 +24,24 @@ const Flex = styled.div`
interface NWSWeatherProps {
observations: NWSWeatherObservation[];
+ defaultIcon?: IconProp;
+ className?: string;
}
-export default function NWSWeather({ observations }: NWSWeatherProps) {
+export default function NWSWeather({
+ observations,
+ defaultIcon,
+ ...rest
+}: NWSWeatherProps) {
const observation: NWSWeatherObservation | undefined =
observations.find(({ weather }) => weather === "thunderstorms") ||
observations[0];
- if (!observation) return <>>;
+ if (!observation) return renderWithIcon(defaultIcon);
function renderTooltip() {
+ if (observations.every(({ weather }) => !weather)) return;
+
return capitalize(
observations
.map((observation) =>
@@ -45,21 +53,29 @@ export default function NWSWeather({ observations }: NWSWeatherProps) {
const icon = findIconFor(observation);
- if (!icon) return <>>;
+ if (!icon) return renderWithIcon(defaultIcon);
+
+ return renderWithIcon(icon);
+
+ function renderWithIcon(icon: IconProp | undefined) {
+ if (!icon) return <>>;
- return (
-
-
-
-
-
- );
+ return (
+
+
+
+
+
+ );
+ }
}
function findIconFor(observation: NWSWeatherObservation): IconProp | undefined {
diff --git a/src/features/weather/header/WMOWeather.tsx b/src/features/weather/header/WMOWeather.tsx
index 1a50241..31447aa 100644
--- a/src/features/weather/header/WMOWeather.tsx
+++ b/src/features/weather/header/WMOWeather.tsx
@@ -8,6 +8,7 @@ import {
import { faSnowflake } from "@fortawesome/pro-light-svg-icons";
import { convertTitleCaseToSpaces } from "../../../helpers/string";
import Tooltip from "../../../shared/Tooltip";
+import { IconProp } from "@fortawesome/fontawesome-svg-core";
const Flex = styled.div`
display: flex;
@@ -47,9 +48,15 @@ enum WMOWeatherCode {
interface WMOWeatherCodeProps {
wmoCode: WMOWeatherCode;
+ defaultIcon?: IconProp;
+ className?: string;
}
-export default function WMOWeather({ wmoCode }: WMOWeatherCodeProps) {
+export default function WMOWeather({
+ wmoCode,
+ defaultIcon,
+ ...rest
+}: WMOWeatherCodeProps) {
const icon = (() => {
switch (wmoCode) {
case WMOWeatherCode.LightRainShowers:
@@ -82,13 +89,21 @@ export default function WMOWeather({ wmoCode }: WMOWeatherCodeProps) {
}
})();
- if (!icon) return <>>;
+ if (!icon) return renderWithIcon(defaultIcon);
- return (
- convertTitleCaseToSpaces(WMOWeatherCode[wmoCode])}>
-
-
-
-
- );
+ return renderWithIcon(icon);
+
+ function renderWithIcon(icon: IconProp | undefined) {
+ if (!icon) return <>>;
+
+ return (
+ convertTitleCaseToSpaces(WMOWeatherCode[wmoCode])}
+ >
+
+
+
+
+ );
+ }
}
diff --git a/src/features/weather/header/Weather.tsx b/src/features/weather/header/Weather.tsx
index 7686187..a14dd32 100644
--- a/src/features/weather/header/Weather.tsx
+++ b/src/features/weather/header/Weather.tsx
@@ -4,12 +4,13 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useMemo } from "react";
import { outputP3ColorFromRGB } from "../../../helpers/colors";
-import { findValue } from "../../../services/nwsWeather";
+import { findValue, NWSWeatherObservation } from "../../../services/nwsWeather";
import { WeatherResult } from "../weatherSlice";
import { keyframes } from "@emotion/css";
import { css } from "@emotion/react";
import NWSWeather from "./NWSWeather";
import WMOWeather from "./WMOWeather";
+import { IconProp } from "@fortawesome/fontawesome-svg-core";
const thunderAnimate = keyframes`
0% {
@@ -103,8 +104,17 @@ export default function Weather({ date, weather }: WeatherProps) {
if (!observations) return <>>;
- if (Array.isArray(observations))
- return ;
+ return ;
+}
+
+interface ObservationsProps {
+ data: number | NWSWeatherObservation[];
+ defaultIcon?: IconProp | undefined;
+ className?: string;
+}
+
+export function Observations({ data, ...rest }: ObservationsProps) {
+ if (Array.isArray(data)) return ;
- return ;
+ return ;
}
diff --git a/src/shared/Tooltip.tsx b/src/shared/Tooltip.tsx
index c3dbcfc..297c853 100644
--- a/src/shared/Tooltip.tsx
+++ b/src/shared/Tooltip.tsx
@@ -52,7 +52,7 @@ export const TooltipContainer = styled.div<{ interactive: boolean }>`
interface TooltipProps {
children?: React.ReactNode;
- contents: () => React.ReactNode;
+ contents: () => React.ReactNode | undefined;
mouseOnly?: boolean;
interactive?: boolean;
offset?: number;
@@ -110,6 +110,10 @@ export default function Tooltip({
});
}, [isMounted]);
+ const renderedContent = contents();
+
+ if (!renderedContent) return children;
+
return (
<>
to determine if tooltip is open */
interactive={interactive ?? false}
>
- {contents()}
+ {renderedContent}
From 14c6efb32af97e7c62c9ae056006f353de46421b Mon Sep 17 00:00:00 2001
From: Alexander Harding <2166114+aeharding@users.noreply.github.com>
Date: Sun, 6 Oct 2024 21:30:09 -0500
Subject: [PATCH 8/8] do not export
---
src/features/rap/cells/WindSpeed.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/features/rap/cells/WindSpeed.tsx b/src/features/rap/cells/WindSpeed.tsx
index 3071d2c..b0870ac 100644
--- a/src/features/rap/cells/WindSpeed.tsx
+++ b/src/features/rap/cells/WindSpeed.tsx
@@ -8,7 +8,7 @@ import { useMemo } from "react";
import { useAppSelector } from "../../../hooks";
import { SpeedUnit } from "../extra/settings/settingEnums";
-export const windColorScale = chroma
+const colorScale = chroma
.scale([
"#00FF00",
"#00FF00",
@@ -27,7 +27,7 @@ export const windColorScale = chroma
const WindSpeedContainer = styled.div<{ speed: number; shear: boolean }>`
position: relative;
- ${({ speed }) => outputP3ColorFromLab(windColorScale(speed).lab())};
+ ${({ speed }) => outputP3ColorFromLab(colorScale(speed).lab())};
${({ shear }) =>
shear &&
|