import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; import { IconArrowDownRight, IconArrowUpRight, IconCloudRain } from '@tabler/icons'; import { HomarrCardWrapper } from '../../components/Dashboard/Tiles/HomarrCardWrapper'; import { BaseTileProps } from '../../components/Dashboard/Tiles/type'; import { WidgetsMenu } from '../../components/Dashboard/Tiles/Widgets/WidgetsMenu'; import { defineWidget } from '../helper'; import { IWidget } from '../widgets'; import { useWeatherForCity } from './useWeatherForCity'; import { WeatherIcon } from './WeatherIcon'; const definition = defineWidget({ id: 'weather', icon: IconCloudRain, options: { displayInFahrenheit: { type: 'switch', defaultValue: false, }, location: { type: 'text', defaultValue: 'Paris', }, }, component: WeatherTile, }); export type IWeatherWidget = IWidget; interface WeatherTileProps extends BaseTileProps { module: IWeatherWidget; } function WeatherTile({ className, module }: WeatherTileProps) { const { data: weather, isLoading, isError } = useWeatherForCity(module.properties.location); 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.displayInFahrenheit )}
{getPerferedUnit( weather!.daily.temperature_2m_max[0], module.properties.displayInFahrenheit )}
{getPerferedUnit( weather!.daily.temperature_2m_min[0], module.properties.displayInFahrenheit )}
); } const getPerferedUnit = (value: number, isFahrenheit = false): string => isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`; export default definition;