diff --git a/src/components/calendar/CalendarMenu.vue b/src/components/calendar/CalendarMenu.vue index 6c60034..0c5dde1 100644 --- a/src/components/calendar/CalendarMenu.vue +++ b/src/components/calendar/CalendarMenu.vue @@ -4,13 +4,23 @@ import CalendarMenuToday from './CalendarMenuToday.vue' import CalendarMenuNav from './CalendarMenuNav.vue' import CalendarSwitch from './CalendarSwitch.vue' import CalendarSearch from './search/CalendarSearch.vue' +import { substractToDate } from '@/models/Date' +import { computed } from 'vue' +import { storeToRefs } from 'pinia' +import { PhMapPin } from '@phosphor-icons/vue' -const { currentDate } = useCalendar() +const { defaultDate, getFormattedDateTitle, currentDate } = useCalendar() +const { currentLeimDate, selectedDate } = storeToRefs(useCalendar()) + +const mainDateTitle = computed(() => getFormattedDateTitle(selectedDate.value, true)) + +const dateDifference = computed(() => substractToDate(defaultDate, currentLeimDate.value)) +const formattedDateDifference = computed(() => getFormattedDateTitle(dateDifference.value, true)) diff --git a/src/components/calendar/CalendarTile.vue b/src/components/calendar/CalendarTile.vue index 96f90c7..4d7e993 100644 --- a/src/components/calendar/CalendarTile.vue +++ b/src/components/calendar/CalendarTile.vue @@ -11,7 +11,8 @@ const props = defineProps<{ faded?: boolean }>() -const { defaultDate } = useCalendar() +const { defaultDate, selectDate } = useCalendar() +const { selectedDate } = storeToRefs(useCalendar()) const { currentEvents } = storeToRefs(useCalendarEvents()) const eventsForTheDay = computed(() => { @@ -23,6 +24,10 @@ const eventsForTheDay = computed(() => { const isDefaultDate = computed(() => { return areDatesIdentical(props.date, defaultDate) }) + +const isSelectedDate = computed(() => { + return areDatesIdentical(props.date, selectedDate.value) +}) diff --git a/src/models/Date.ts b/src/models/Date.ts index 52584b3..f727f74 100644 --- a/src/models/Date.ts +++ b/src/models/Date.ts @@ -9,6 +9,11 @@ export type LeimPeriod = 'ante' | 'nante' export type LeimPeriodShort = 'A.R' | 'N.R' export type LeimDateOrder = 'asc' | 'desc' +export const monthsPerYear = 10 +export const daysPerYear = 320 +export const daysPerMonth = 32 +export const daysPerWeek = 6 + /** * Check whether two dates are identical * @@ -17,8 +22,7 @@ export type LeimDateOrder = 'asc' | 'desc' * @returns True if the dates are identical */ export function areDatesIdentical(date1: LeimDate, date2: LeimDate) { - // To refacto to be more precise - return JSON.stringify({ ...date1 }) === JSON.stringify({ ...date2 }) + return convertDateToDays({ ...date1 }) === convertDateToDays({ ...date2 }) } /** @@ -46,3 +50,33 @@ export function compareDates(a: LeimDate, b: LeimDate, order: LeimDateOrder = 'd return 0 } + +export function convertDateToDays(dateToConvert: LeimDate) { + let numberOfDays: number = dateToConvert.day + + numberOfDays = numberOfDays + dateToConvert.month * daysPerMonth + numberOfDays = numberOfDays + dateToConvert.year * daysPerYear + + return numberOfDays +} + +export function substractToDate(baseDate: LeimDate, substractionDate: LeimDate) { + let newDay: number + let newMonth: number + let newYear: number + let newPeriod: LeimPeriod + + // console.log(baseDate, substractionDate) + // console.log(convertDateToDays(baseDate), convertDateToDays(substractionDate)) + + return baseDate + + // return { + // day: newDay, + // month: newMonth, + // year: newYear, + // period: newPeriod + // } +} + +export function addToDate(firstDate: LeimDate, secondDate: LeimDate) {} diff --git a/src/stores/calendar.ts b/src/stores/calendar.ts index 68b8259..0b7c61f 100644 --- a/src/stores/calendar.ts +++ b/src/stores/calendar.ts @@ -1,4 +1,12 @@ -import type { LeimDate, LeimPeriod, LeimPeriodShort } from '@/models/Date' +import { + monthsPerYear, + daysPerWeek, + daysPerMonth, + daysPerYear, + type LeimDate, + type LeimPeriod, + type LeimPeriodShort +} from '@/models/Date' import { isDigit, isInt, isSignedInt } from '@/utils/Regex' import { useUrlSearchParams } from '@vueuse/core' import { defineStore } from 'pinia' @@ -48,17 +56,13 @@ export const useCalendar = defineStore('calendar', () => { 'Farene', 'Dalvene' ] - const monthsPerYear = computed(() => months.length) - const daysPerYear = 320 - const daysPerMonth = computed(() => daysPerYear / monthsPerYear.value) - const daysPerWeek = 6 // Assign the static config const staticConfig: CalendarStaticConfig = { months, - monthsPerYear: monthsPerYear.value, + monthsPerYear, daysPerYear, - daysPerMonth: daysPerMonth.value, + daysPerMonth, daysPerWeek } @@ -116,10 +120,8 @@ export const useCalendar = defineStore('calendar', () => { }) // Get period from currentYear - const currentPeriod: ComputedRef = computed( - () => getPeriodOfYear(currentYear.value).long - ) - const currentPeriodAbbr: ComputedRef = computed( + const currentPeriod = computed(() => getPeriodOfYear(currentYear.value).long) + const currentPeriodAbbr = computed( () => getPeriodOfYear(currentYear.value).short ) @@ -158,6 +160,17 @@ export const useCalendar = defineStore('calendar', () => { currentDateTitle } + const currentLeimDate = computed(() => { + return { + day: currentDate.currentDay.value, + month: currentDate.currentMonth.value, + year: currentDate.currentYear.value, + period: currentDate.currentPeriod.value + } + }) + + const selectedDate = ref(currentLeimDate.value) + /** * Check whether the current viewType is active */ @@ -325,6 +338,7 @@ export const useCalendar = defineStore('calendar', () => { params.day = date.day.toString() params.month = date.month.toString() params.year = date.year.toString() + selectDate(date) } /** @@ -335,12 +349,22 @@ export const useCalendar = defineStore('calendar', () => { currentConfig.value.viewType = 'month' } + /** + * Jump the calendar to the default date + */ + function selectDate(date: LeimDate) { + selectedDate.value = date + } + return { staticConfig, viewTypeOptions, currentConfig, currentDate, + currentLeimDate, defaultDate, + selectedDate, + selectDate, params, getPeriodOfYear, incrementMonth,