diff --git a/assets/css/src/generic.css b/assets/css/src/generic.css index 2110e83..9ae6597 100644 --- a/assets/css/src/generic.css +++ b/assets/css/src/generic.css @@ -12,7 +12,7 @@ } } -.calendar-strip__days.progress { +/* .calendar-strip__days.progress { cursor: progress !important; } .calendar-strip__days.progress > li { @@ -20,7 +20,7 @@ } .calendar-strip__days.progress button { cursor: progress !important; -} +} */ .grid { --column-gap: calc(var(--space-m) * 1.1); diff --git a/assets/js/calendar.js b/assets/js/calendar.js index a413743..4098ac3 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -149,18 +149,14 @@ function getId(eventData) { function createEmptyCalendar() { const calendar = {}; - for (let month = 9; month < 19; month++) { + for (let month = 9; month < 21; month++) { const normalizedMonth = ((month - 1) % 12) + 1; const daysInMonth = dayjs() .month(normalizedMonth - 1) .daysInMonth(); - calendar[normalizedMonth] = { - name: dayjs() - .month(normalizedMonth - 1) - .format("MMMM"), - }; + calendar[normalizedMonth] = {}; for (let day = 1; day <= daysInMonth; day++) { calendar[normalizedMonth][day] = null; @@ -170,7 +166,7 @@ function createEmptyCalendar() { return calendar; } -async function getMergedDates(monthNumb, dates) { +async function getCurrentSeasonCalendar(monthNumb, dates) { const calendar = createEmptyCalendar(); const requestParams = { @@ -187,7 +183,6 @@ async function getMergedDates(monthNumb, dates) { requestOptions ); const json = await response.json(); - console.log("calendar", json); return json; } diff --git a/site/config/routes/get-current-season-calendar.php b/site/config/routes/get-current-season-calendar.php index 546ec91..200e51e 100644 --- a/site/config/routes/get-current-season-calendar.php +++ b/site/config/routes/get-current-season-calendar.php @@ -95,6 +95,13 @@ return [ } } - return json_encode($calendar); + $jsonCalendar = json_encode($calendar); + + $seasonDirPath = __DIR__ . '/../../../content/' . $currentSeason->diruri() . '/data.json'; + $dataFile = fopen($seasonDirPath, "w"); + fwrite($dataFile, $jsonCalendar); + fclose($dataFile); + + return $jsonCalendar; } ]; diff --git a/site/snippets/calendar-strip.php b/site/snippets/calendar-strip.php index 31d3b5c..9588930 100644 --- a/site/snippets/calendar-strip.php +++ b/site/snippets/calendar-strip.php @@ -2,114 +2,90 @@ class="calendar-strip" @mouseleave="open = false" x-data="{ - monthNumb: dayjs().month(), - weekIndex: (() => { - dayjs.extend(window.dayjs_plugin_weekOfYear); - - const date = dayjs(); - - const firstDayOfMonth = dayjs(date).startOf('month'); + calendar: createEmptyCalendar(), + monthNumb: dayjs().month() + 1, + token: '= $site->mapadoToken() ?>', + contractId: '= $site->mapadoContractId() ?>', + targetSessions: [], + open: false, + today: dayjs().format('DD-MM-YYYY'), - const currentWeek = date.week(); - const firstWeekOfMonth = firstDayOfMonth.week(); - - const weekIndex = currentWeek - firstWeekOfMonth - 1; + get monthName() { + return dayjs().month(this.monthNumb - 1).format('MMMM'); + }, - console.log(`currentWeek: ${currentWeek}, firstWeekOfMonth: ${firstWeekOfMonth}, weekIndex: ${weekIndex}`); - - // Retourner l'index de la semaine - return weekIndex; - })(), - token: '= $site->mapadoToken() ?>', - contractId: '= $site->mapadoContractId() ?>', - dates: [], - targetSessions: [], - open: false, - today: dayjs().format('DD-MM-YYYY'), + get currentMonth() { + return this.calendar[this.monthNumb] + }, - get monthName() { - return dayjs().month(this.monthNumb).format('MMMM'); - }, + async updateDates() { - get currentWeek() { - const dates = JSON.parse(JSON.stringify(this.dates)); - const start = this.weekIndex * 7; - const end = start + 7; + fetch('/= page('programme')->children()->first()->uri() ?>/data.json') + .then(res => res.json()) + .then(json => { + console.log('Saved calendar : ', json) + this.calendar = json + }) + .catch(error => console.log('No saved calendar.')) - const allKeys = Object.keys(dates); + const daysNode = document.querySelector('.calendar-strip__days'); + daysNode.classList.toggle('progress'); + + this.calendar = await getCurrentSeasonCalendar(); + + console.log('Updated calendar for current season :', this.calendar); + daysNode.classList.toggle('progress'); + }, - const slicedKeys = allKeys.slice(start, end); - - const slicedObject = slicedKeys.reduce((obj, key) => { - obj[key] = dates[key]; - return obj; - }, {}); - return slicedObject; - }, - - async updateDates(resetWeek = false) { - const daysNode = document.querySelector('.calendar-strip__days'); - daysNode.classList.toggle('progress'); - - this.dates = getDatesInMonth(this.monthNumb); - this.dates = await getMergedDates(this.monthNumb, this.dates); - - console.log('Merged dates', this.dates); - daysNode.classList.toggle('progress'); - if (resetWeek) { - this.weekIndex = 0 - } - }, - - handleDayHover() { - if (this.date.sessions.length > 0) { - this.targetSessions = this.date.sessions; - this.open = true; - } else { - setTimeout(() => { + handleDayHover() { + if (!this.date) return + if (this.date.sessions.length > 0) { this.targetSessions = this.date.sessions; - }, 100); - this.open = false; - } - }, + this.open = true; + } else { + setTimeout(() => { + this.targetSessions = this.date.sessions; + }, 100); + this.open = false; + } + }, - nextWeek() { - if (this.weekIndex < Math.floor(this.dates.length / 7)) { - this.weekIndex++; - } else { - this.monthNumb++; - this.updateDates(); + nextMonth() { + if (this.monthNumb == 12) { + this.monthNumb = 1 + } else { + this.monthNumb++ + } + }, + prevMonth() { + if (this.monthNumb == 1) { + this.monthNumb = 12 + } else { + this.monthNumb-- + } } - }, - - prevWeek() { - if (this.weekIndex > 0) { - this.weekIndex--; - } else { - this.monthNumb--; - this.updateDates(); - } - } -}" + }" x-init="updateDates()" >