From 2987f8fe0650a2b79d7ea6499fe5fdc3d9175cb2 Mon Sep 17 00:00:00 2001 From: manuelsanchez2 Date: Mon, 17 Jun 2024 10:03:35 +0200 Subject: [PATCH] Calendar is properly working with private dots --- .../views/calendar-components/calendar.tsx | 20 +++++++++++++++---- src/components/views/calendar-view.tsx | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/views/calendar-components/calendar.tsx b/src/components/views/calendar-components/calendar.tsx index 8b8f02f..8094a91 100644 --- a/src/components/views/calendar-components/calendar.tsx +++ b/src/components/views/calendar-components/calendar.tsx @@ -1,16 +1,21 @@ import { component$, $, useSignal, type Signal } from '@builder.io/qwik' -import type { IAppointment, CalendarDay } from '~/types/types' +import type { IAppointment, CalendarDay, IUser } from '~/types/types' import { buildCalendar, getMonthName } from './calendar-functions' +import { getAuthorByTaskId } from '~/utils/functions' export const Calendar = component$( ({ appointments, selectedDay, isAddAppointmentModalOpen, + userName, + users, }: { appointments: IAppointment[] selectedDay: Signal isAddAppointmentModalOpen: Signal + userName: string + users: Array }) => { const date = useSignal(selectedDay.value) const weeks = buildCalendar(date.value) @@ -106,10 +111,17 @@ export const Calendar = component$(
{weeks.flat().map((day, index) => { const id = `${day.year}-${day.month.toString().padStart(2, '0')}-${day.day.toString().padStart(2, '0')}` + const hasTask = appointments.some( (event) => - event.date === - `${day.year}-${(day.month + 1).toString().padStart(2, '0')}-${day.day.toString().padStart(2, '0')}` + (event.visibility === 'private' && + getAuthorByTaskId(event.created_by as number, users) === + userName && + event.date === + `${day.year}-${(day.month + 1).toString().padStart(2, '0')}-${day.day.toString().padStart(2, '0')}`) || + (event.visibility === 'public' && + event.date === + `${day.year}-${(day.month + 1).toString().padStart(2, '0')}-${day.day.toString().padStart(2, '0')}`) ) const selected = @@ -139,7 +151,7 @@ export const Calendar = component$( {hasTask ? (