Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions weather/src/components/Simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ interface WeatherProps {
const Simple = ({ weatherData, tempType }: WeatherProps) => {
const [time, setTime] = useState<null | string>(null);

const getWindDirection = (degrees: number): string => {
const directions = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
const index = Math.round(degrees / 22.5) % 16;
return directions[index];
};

useEffect(() => {
const removeTimeListener = DeskThing.on(
DEVICE_CLIENT.TIME,
Expand Down Expand Up @@ -47,12 +53,9 @@ const Simple = ({ weatherData, tempType }: WeatherProps) => {
weatherData.tempUnit.toUpperCase()}
</p>
<p className="text-2xl sm:text-6xl xl:text-8xl">{time}</p>
{/* --- UPDATED WIND READOUT WITH SAFETY CHECKS --- */}
{weatherData.current && (
<p className="text-xl sm:text-4xl xl:text-6xl opacity-80 mt-2">
{Math.round(weatherData.current.windSpeed10m || 0)} {weatherData.speedUnit || ''} {getWindDirection(weatherData.current.windDirection10m || 0)}
</p>
)}
<p className="text-xl sm:text-4xl xl:text-6xl opacity-80 mt-2">
{Math.round(weatherData.current.windSpeed10m)} {weatherData.speedUnit} {getWindDirection(weatherData.current.windDirection10m)}
</p>
<p className="fixed bottom-3 right-3 italic text-xs sm:text-base xl:text-3xl">
Last Updated{" "}
{new Date(weatherData.current.time)
Expand Down