import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; import { IconArrowDownRight, IconArrowUpRight } from '@tabler/icons'; import { HomarrCardWrapper } from '../../components/Dashboard/Tiles/HomarrCardWrapper'; import { WidgetsMenu } from '../../components/Dashboard/Tiles/Widgets/WidgetsMenu'; import { BaseTileProps } from '../../components/Dashboard/Tiles/type'; import { WeatherIntegrationType } from '../../types/integration'; import { useWeatherForCity } from './useWeatherForCity'; import { WeatherIcon } from './WeatherIcon'; interface WeatherTileProps extends BaseTileProps { module: WeatherIntegrationType; // TODO: change to new type defined through widgetDefinition } export const WeatherTile = ({ className, module }: WeatherTileProps) => { const { data: weather, isLoading, isError, } = useWeatherForCity(module?.properties.location ?? 'Paris'); if (isLoading) { return ( ); } if (isError) { return ( An error occured ); } // TODO: add widgetWrapper that is generic and uses the definition return ( {getPerferedUnit( weather!.current_weather.temperature, module?.properties.isFahrenheit )} {getPerferedUnit( weather!.daily.temperature_2m_max[0], module?.properties.isFahrenheit )} {getPerferedUnit( weather!.daily.temperature_2m_min[0], module?.properties.isFahrenheit )} ); }; const getPerferedUnit = (value: number, isFahrenheit = false): string => isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`;