Fix datetile and weathertile display for 1x1 size

This commit is contained in:
ajnart
2023-01-08 13:55:51 +09:00
parent d49cfb0632
commit 9af2ee4882
3 changed files with 33 additions and 21 deletions

View File

@@ -42,7 +42,6 @@ const SidebarInner = ({ location }: DashboardSidebarInnerProps) => {
className="grid-stack grid-stack-sidebar" className="grid-stack grid-stack-sidebar"
style={{ transitionDuration: '0s', height: '100%' }} style={{ transitionDuration: '0s', height: '100%' }}
data-sidebar={location} data-sidebar={location}
// eslint-disable-next-line react/no-unknown-property
gs-min-row={minRow} gs-min-row={minRow}
> >
<WrapperContent apps={apps} refs={refs} widgets={widgets} /> <WrapperContent apps={apps} refs={refs} widgets={widgets} />

View File

@@ -1,4 +1,5 @@
import { Stack, Text, Title } from '@mantine/core'; import { Stack, Text, Title } from '@mantine/core';
import { useElementSize } from '@mantine/hooks';
import { IconClock } from '@tabler/icons'; import { IconClock } from '@tabler/icons';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
@@ -16,7 +17,7 @@ const definition = defineWidget({
}, },
}, },
gridstack: { gridstack: {
minWidth: 2, minWidth: 1,
minHeight: 1, minHeight: 1,
maxWidth: 12, maxWidth: 12,
maxHeight: 12, maxHeight: 12,
@@ -33,11 +34,12 @@ interface DateTileProps {
function DateTile({ widget }: DateTileProps) { function DateTile({ widget }: DateTileProps) {
const date = useDateState(); const date = useDateState();
const formatString = widget.properties.display24HourFormat ? 'HH:mm' : 'h:mm A'; const formatString = widget.properties.display24HourFormat ? 'HH:mm' : 'h:mm A';
const { width, height, ref } = useElementSize();
return ( return (
<Stack spacing="xs" justify="space-around" align="center" style={{ height: '100%' }}> <Stack ref={ref} spacing="xs" justify="space-around" align="center" style={{ height: '100%' }}>
<Title>{dayjs(date).format(formatString)}</Title> <Title>{dayjs(date).format(formatString)}</Title>
<Text size="lg">{dayjs(date).format('dddd, MMMM D')}</Text> {width > 200 && <Text size="lg">{dayjs(date).format('dddd, MMMM D')}</Text>}
</Stack> </Stack>
); );
} }

View File

@@ -1,4 +1,5 @@
import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core';
import { useElementSize } from '@mantine/hooks';
import { IconArrowDownRight, IconArrowUpRight, IconCloudRain } from '@tabler/icons'; import { IconArrowDownRight, IconArrowUpRight, IconCloudRain } from '@tabler/icons';
import { defineWidget } from '../helper'; import { defineWidget } from '../helper';
import { IWidget } from '../widgets'; import { IWidget } from '../widgets';
@@ -19,7 +20,7 @@ const definition = defineWidget({
}, },
}, },
gridstack: { gridstack: {
minWidth: 2, minWidth: 1,
minHeight: 1, minHeight: 1,
maxWidth: 12, maxWidth: 12,
maxHeight: 12, maxHeight: 12,
@@ -35,10 +36,17 @@ interface WeatherTileProps {
function WeatherTile({ widget }: WeatherTileProps) { function WeatherTile({ widget }: WeatherTileProps) {
const { data: weather, isLoading, isError } = useWeatherForCity(widget.properties.location); const { data: weather, isLoading, isError } = useWeatherForCity(widget.properties.location);
const { width, height, ref } = useElementSize();
if (isLoading) { if (isLoading) {
return ( return (
<> <Stack
ref={ref}
spacing="xs"
justify="space-around"
align="center"
style={{ height: '100%', width: '100%' }}
>
<Skeleton height={40} width={100} mb="xl" /> <Skeleton height={40} width={100} mb="xl" />
<Group noWrap> <Group noWrap>
<Skeleton height={50} circle /> <Skeleton height={50} circle />
@@ -47,7 +55,7 @@ function WeatherTile({ widget }: WeatherTileProps) {
<Skeleton height={25} width={70} /> <Skeleton height={25} width={70} />
</Group> </Group>
</Group> </Group>
</> </Stack>
); );
} }
@@ -62,32 +70,35 @@ function WeatherTile({ widget }: WeatherTileProps) {
// TODO: add widgetWrapper that is generic and uses the definition // TODO: add widgetWrapper that is generic and uses the definition
return ( return (
<Stack <Stack
ref={ref}
spacing="xs" spacing="xs"
justify="space-around" justify="space-around"
align="center" align="center"
style={{ height: '100%', width: '100%' }} style={{ height: '100%', width: '100%' }}
> >
<Group grow> <Group align={'center'} position="center" spacing="xs">
<WeatherIcon code={weather!.current_weather.weathercode} /> <WeatherIcon code={weather!.current_weather.weathercode} />
<Title order={2}> <Title>
{getPerferedUnit( {getPerferedUnit(
weather!.current_weather.temperature, weather!.current_weather.temperature,
widget.properties.displayInFahrenheit widget.properties.displayInFahrenheit
)} )}
</Title> </Title>
</Group> </Group>
<Group noWrap spacing="xs"> {width > 200 && (
<IconArrowUpRight /> <Group noWrap spacing="xs">
{getPerferedUnit( <IconArrowUpRight />
weather!.daily.temperature_2m_max[0], {getPerferedUnit(
widget.properties.displayInFahrenheit weather!.daily.temperature_2m_max[0],
)} widget.properties.displayInFahrenheit
<IconArrowDownRight /> )}
{getPerferedUnit( <IconArrowDownRight />
weather!.daily.temperature_2m_min[0], {getPerferedUnit(
widget.properties.displayInFahrenheit weather!.daily.temperature_2m_min[0],
)} widget.properties.displayInFahrenheit
</Group> )}
</Group>
)}
</Stack> </Stack>
); );
} }