Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 25x 25x 25x 175x 175x 175x 175x 175x 175x 175x 175x 175x 25x 25x 25x 1x 25x 25x 25x 25x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 11x 25x 14x 14x 1x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 70x 70x 70x | <template>
<div data-testid="calendar-view" class="bg-white rounded-lg shadow-sm border border-secondary-200 overflow-hidden">
<!-- Header with Navigation -->
<div class="px-4 py-3 border-b border-secondary-200 bg-secondary-50">
<div class="flex items-center justify-between">
<h2 class="text-lg font-semibold text-secondary-900">{{ $t('calendar.weekView') }}</h2>
<!-- Navigation Controls -->
<div class="flex items-center gap-2">
<!-- Previous Week -->
<button
type="button"
class="p-2 rounded-lg text-secondary-600 hover:text-secondary-900 hover:bg-secondary-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1 transition-colors"
:aria-label="$t('calendar.previousWeek')"
@click="navigatePreviousWeek"
@keydown.enter="navigatePreviousWeek"
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</button>
<!-- Today Button -->
<button
type="button"
class="px-3 py-1.5 text-sm font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1"
:class="isCurrentWeek
? 'bg-primary-600 text-white cursor-default'
: 'text-secondary-700 hover:text-secondary-900 hover:bg-secondary-100'"
:disabled="isCurrentWeek"
@click="navigateToToday"
@keydown.enter="navigateToToday"
>
{{ $t('calendar.today') }}
</button>
<!-- Next Week -->
<button
type="button"
class="p-2 rounded-lg text-secondary-600 hover:text-secondary-900 hover:bg-secondary-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1 transition-colors"
:aria-label="$t('calendar.nextWeek')"
@click="navigateNextWeek"
@keydown.enter="navigateNextWeek"
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
</svg>
</button>
</div>
</div>
<!-- Date Range Indicator -->
<p class="text-sm text-secondary-500 mt-1">
{{ formatDateRange }}
</p>
</div>
<!-- Calendar Grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-7 divide-x divide-secondary-200">
<div
v-for="day in weekDays"
:key="day.date"
class="min-h-[200px] p-2"
:class="{ 'bg-primary-50': day.isToday }"
>
<!-- Day Header -->
<div class="text-center mb-2">
<p
class="text-xs font-medium"
:class="day.isToday ? 'text-primary-600' : 'text-secondary-500'"
>
{{ day.dayName }}
</p>
<p
class="text-lg font-semibold"
:class="day.isToday ? 'text-primary-700' : 'text-secondary-900'"
>
{{ day.dayNumber }}
</p>
</div>
<!-- Events for this day -->
<div class="space-y-2">
<EventCard
v-for="event in getEventsForDay(day.date)"
:key="event.id"
:event="event"
:attendance-count="event.attendanceCount"
class="text-xs"
/>
</div>
<!-- Empty state -->
<p
v-if="getEventsForDay(day.date).length === 0"
class="text-xs text-secondary-400 text-center mt-4"
>
{{ $t('calendar.noEvents') }}
</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
/**
* CalendarView
* @description Week view calendar displaying events grouped by day
* Shows 7 days with navigation controls to move between weeks
*/
import type { Event } from '~/types'
interface Props {
/** Array of events to display in the calendar */
events: Event[]
/** Starting date for the week view (defaults to today) */
startDate?: Date
}
const props = withDefaults(defineProps<Props>(), {
startDate: () => new Date()
})
const emit = defineEmits<{
/** Emitted when navigation changes the start date */
'update:startDate': [date: Date]
}>()
/**
* Get current locale for date formatting
*/
const { locale } = useI18n()
/**
* Internal start date state (can be controlled via prop or internal)
*/
const internalStartDate = ref(new Date(props.startDate))
/**
* Watch for external startDate changes
*/
watch(() => props.startDate, (newDate) => {
internalStartDate.value = new Date(newDate)
})
interface WeekDay {
date: string // ISO date string (YYYY-MM-DD)
dayName: string // Short day name (Mon, Tue, etc.)
dayNumber: number // Day of month (1-31)
isToday: boolean // Whether this day is today
}
/**
* Generate week days starting from internalStartDate
*/
const weekDays = computed((): WeekDay[] => {
const start = new Date(internalStartDate.value)
const today = new Date()
const todayStr = today.toISOString().split('T')[0]
const days: WeekDay[] = []
for (let i = 0; i < 7; i++) {
const date = new Date(start)
date.setDate(start.getDate() + i)
const dateStr = date.toISOString().split('T')[0]!
days.push({
date: dateStr,
dayName: date.toLocaleDateString(locale.value, { weekday: 'short' }),
dayNumber: date.getDate(),
isToday: dateStr === todayStr
})
}
return days
})
/**
* Check if currently viewing the week containing today
*/
const isCurrentWeek = computed((): boolean => {
const today = new Date()
const todayStr = today.toISOString().split('T')[0]
return weekDays.value.some(day => day.date === todayStr)
})
/**
* Format the date range for display (e.g., "Nov 25 - Dec 1, 2025")
*/
const formatDateRange = computed((): string => {
const firstDay = weekDays.value[0]
const lastDay = weekDays.value[weekDays.value.length - 1]
if (!firstDay || !lastDay) return ''
const startDate = new Date(firstDay.date)
const endDate = new Date(lastDay.date)
const startMonth = startDate.toLocaleDateString(locale.value, { month: 'short' })
const endMonth = endDate.toLocaleDateString(locale.value, { month: 'short' })
const year = endDate.getFullYear()
if (startMonth === endMonth) {
return `${startMonth} ${startDate.getDate()} - ${endDate.getDate()}, ${year}`
}
return `${startMonth} ${startDate.getDate()} - ${endMonth} ${endDate.getDate()}, ${year}`
})
/**
* Navigate to previous week
*/
const navigatePreviousWeek = (): void => {
const newDate = new Date(internalStartDate.value)
newDate.setDate(newDate.getDate() - 7)
internalStartDate.value = newDate
emit('update:startDate', newDate)
}
/**
* Navigate to next week
*/
const navigateNextWeek = (): void => {
const newDate = new Date(internalStartDate.value)
newDate.setDate(newDate.getDate() + 7)
internalStartDate.value = newDate
emit('update:startDate', newDate)
}
/**
* Navigate to today (current week)
*/
const navigateToToday = (): void => {
const today = new Date()
internalStartDate.value = today
emit('update:startDate', today)
}
/**
* Get events for a specific day
*/
const getEventsForDay = (dateStr: string): Event[] => {
return props.events.filter(event => {
const eventDate = new Date(event.dateTime).toISOString().split('T')[0]
return eventDate === dateStr
})
}
</script>
|