Skip to content

Commit

Permalink
Calendar is properly working with private dots
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsanchez2 committed Jun 17, 2024
1 parent 54ed9ce commit 2987f8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/views/calendar-components/calendar.tsx
Original file line number Diff line number Diff line change
@@ -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<Date>
isAddAppointmentModalOpen: Signal<boolean>
userName: string
users: Array<IUser>
}) => {
const date = useSignal(selectedDay.value)
const weeks = buildCalendar(date.value)
Expand Down Expand Up @@ -106,10 +111,17 @@ export const Calendar = component$(
<div class="grid grid-cols-7 h-fit mt-4 border">
{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 =
Expand Down Expand Up @@ -139,7 +151,7 @@ export const Calendar = component$(
{hasTask ? (
<p class="absolute w-2 h-2 top-1 right-0 sm:top-2 sm:right-2">
<svg
class='w-[6px] h-[6px] sm:w-2 sm:h-2'
class="w-[6px] h-[6px] sm:w-2 sm:h-2"
viewBox="0 0 9 9"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 2 additions & 0 deletions src/components/views/calendar-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const CalendarView = component$(
>
<div class="bg-grayBrandLight h-fit lg:h-[600px] p-6 md:p-12 md:pt-2 rounded-xl w-full lg:w-1/2">
<Calendar
users={users}
userName={userName}
appointments={appointments}
selectedDay={selectedDay}
isAddAppointmentModalOpen={isAddAppointmentModalOpen}
Expand Down

0 comments on commit 2987f8f

Please sign in to comment.