Skip to content

Commit

Permalink
🐛 Fix calendar sizing (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored Apr 24, 2023
1 parent 2494ee6 commit f4df411
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/widgets/calendar/CalendarDay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Indicator, IndicatorProps, Popover } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { isToday } from '../../tools/shared/time/date.tool';
import { MediaList } from './MediaList';
import { getBgColorByDateAndTheme } from './bg-calculator';
import { MediasType } from './type';

interface CalendarDayProps {
Expand Down Expand Up @@ -34,12 +34,9 @@ export const CalendarDay = ({ date, medias }: CalendarDayProps) => {
onClick={open}
sx={(theme) => ({
margin: 5,
backgroundColor: isToday(date)
? theme.colorScheme === 'dark'
? theme.colors.dark[5]
: theme.colors.gray[0]
: undefined,
backgroundColor: getBgColorByDateAndTheme(theme.colorScheme, date),
})}
w="100%"
>
<DayIndicator color="red" position="bottom-start" medias={medias.books}>
<DayIndicator color="yellow" position="top-start" medias={medias.movies}>
Expand Down
7 changes: 6 additions & 1 deletion src/widgets/calendar/CalendarTile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Group } from '@mantine/core';
import { useMantineTheme } from '@mantine/core';
import { Calendar } from '@mantine/dates';
import { IconCalendarTime } from '@tabler/icons';
import { useQuery } from '@tanstack/react-query';
Expand All @@ -8,6 +8,7 @@ import { useConfigContext } from '../../config/provider';
import { defineWidget } from '../helper';
import { IWidget } from '../widgets';
import { CalendarDay } from './CalendarDay';
import { getBgColorByDateAndTheme } from './bg-calculator';
import { MediasType } from './type';

const definition = defineWidget({
Expand Down Expand Up @@ -48,6 +49,7 @@ interface CalendarTileProps {
}

function CalendarTile({ widget }: CalendarTileProps) {
const { colorScheme } = useMantineTheme();
const { name: configName } = useConfigContext();
const [month, setMonth] = useState(new Date());

Expand Down Expand Up @@ -100,6 +102,9 @@ function CalendarTile({ widget }: CalendarTileProps) {
flex: 1,
},
}}
getDayProps={(date) => ({
bg: getBgColorByDateAndTheme(colorScheme, date),
})}
renderDay={(date) => (
<CalendarDay date={date} medias={getReleasedMediasForDate(medias, date, widget)} />
)}
Expand Down
16 changes: 16 additions & 0 deletions src/widgets/calendar/bg-calculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ColorScheme, useMantineTheme } from '@mantine/core';
import { isToday } from '../../tools/shared/time/date.tool';

export const getBgColorByDateAndTheme = (colorScheme: ColorScheme, date: Date) => {
if (!isToday(date)) {
return undefined;
}

const { colors } = useMantineTheme();

if (colorScheme === 'dark') {
return colors.dark[5];
}

return colors.gray[2];
};

0 comments on commit f4df411

Please sign in to comment.