From 7a7c27d7807012bfa372e293fc9c6d1cfb8bb232 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Mon, 1 Apr 2024 19:19:24 +0200 Subject: [PATCH] Added base event checking --- src/components/calendar/CalendarEvent.vue | 15 ++++++ src/components/calendar/CalendarMenu.vue | 57 +++++++++++++++++++++-- src/components/calendar/CalendarTile.vue | 32 ++++++++++++- src/components/calendar/state/Monthly.vue | 9 +--- src/stores/calendar.ts | 35 +++++++++++++- src/stores/characters.ts | 1 + src/stores/events.ts | 15 ++++-- 7 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 src/components/calendar/CalendarEvent.vue diff --git a/src/components/calendar/CalendarEvent.vue b/src/components/calendar/CalendarEvent.vue new file mode 100644 index 0000000..be4b5ad --- /dev/null +++ b/src/components/calendar/CalendarEvent.vue @@ -0,0 +1,15 @@ + + + diff --git a/src/components/calendar/CalendarMenu.vue b/src/components/calendar/CalendarMenu.vue index 57498b7..2a5cc44 100644 --- a/src/components/calendar/CalendarMenu.vue +++ b/src/components/calendar/CalendarMenu.vue @@ -8,18 +8,65 @@ import { SelectValue } from '@/components/ui/select' import { useCalendar } from '@/stores/calendar' +import Button from '../ui/button/Button.vue' -const { currentConfig, currentDate, viewTypeOptions } = useCalendar() +const { + currentConfig, + currentDate, + viewTypeOptions, + decrementMonth, + incrementMonth, + jumpToDefaultDate +} = useCalendar() diff --git a/src/stores/calendar.ts b/src/stores/calendar.ts index 9f7b09b..6de1dfd 100644 --- a/src/stores/calendar.ts +++ b/src/stores/calendar.ts @@ -1,7 +1,7 @@ import { computed, type Ref, type ComputedRef, ref } from 'vue' import { defineStore } from 'pinia' import { useUrlSearchParams } from '@vueuse/core' -import type { LeimPeriod, LeimPeriodShort } from '@/models/Date' +import type { LeimDate, LeimPeriod, LeimPeriodShort } from '@/models/Date' type CalendarViewType = 'month' | 'year' | 'decade' | 'century' @@ -80,6 +80,14 @@ export const useCalendar = defineStore('calendar', () => { const defaultDay = String(12) const defaultMonth = String(7) const defaultYear = String(3209) + const defaultDate: ComputedRef = computed(() => { + return { + day: Number(defaultDay), + month: Number(defaultMonth), + year: Number(defaultYear), + period: 'nante' + } + }) // Assign default values if no params exist in URL if (!params.day) { @@ -142,6 +150,13 @@ export const useCalendar = defineStore('calendar', () => { currentDateTitle } + const currentLeimDate: LeimDate = { + day: Number(currentDay.value), + month: Number(currentMonth.value), + year: Number(currentYear.value), + period: currentPeriod.value + } + /** * Moves the current date forward one month */ @@ -223,17 +238,33 @@ export const useCalendar = defineStore('calendar', () => { } } + function compareTwoDates(date1: LeimDate, date2: LeimDate) { + // To refacto to be more precise + return JSON.stringify({ ...date1 }) === JSON.stringify({ ...date2 }) + } + + function jumpToDefaultDate() { + params.day = defaultDay + params.month = defaultMonth + params.year = defaultYear + currentConfig.value.viewType = 'month' + } + return { staticConfig, viewTypeOptions, currentConfig, currentDate, + defaultDate, + currentLeimDate, params, getPeriodOfYear, incrementMonth, decrementMonth, setMonth, incrementYear, - decrementYear + decrementYear, + jumpToDefaultDate, + compareTwoDates } }) diff --git a/src/stores/characters.ts b/src/stores/characters.ts index e124ac8..8709eb0 100644 --- a/src/stores/characters.ts +++ b/src/stores/characters.ts @@ -9,6 +9,7 @@ export type Character = { export const useCharacters = defineStore('characters', () => { const characters: Character[] = [ + { name: 'Quacille Lévios', birth: { day: 3, month: 6, year: 3162, period: 'nante' } }, { name: 'Quacille Lévios', birth: { day: 3, month: 6, year: 3162, period: 'nante' } }, { name: 'Lazarus Tymos', birth: { day: 29, month: 9, year: 3145, period: 'nante' } }, { name: 'Ernestin Pomel', birth: { day: 11, month: 2, year: 3179, period: 'nante' } } diff --git a/src/stores/events.ts b/src/stores/events.ts index 9ca812c..18e68f8 100644 --- a/src/stores/events.ts +++ b/src/stores/events.ts @@ -5,9 +5,10 @@ import { useCharacters, type Character } from './characters' import type { LeimDate } from '@/models/Date' import { useCalendar } from './calendar' -type CalendarEvent = { +export type CalendarEvent = { title: string date: LeimDate + category: 'birth' | 'death' } export const useCalendarEvents = defineStore('calendar-events', () => { @@ -20,7 +21,11 @@ export const useCalendarEvents = defineStore('calendar-events', () => { ) const characterBirthEvents = computed(() => { return charactersWithBirthData.value.map((character) => { - return { title: `Naissance de ${character.name}`, date: character.birth } as CalendarEvent + return { + title: `${character.name}`, + date: character.birth, + category: 'birth' + } as CalendarEvent }) }) @@ -30,7 +35,11 @@ export const useCalendarEvents = defineStore('calendar-events', () => { ) const characterDeathEvents = computed(() => { return charactersWithDeathData.value.map((character) => { - return { title: `Décès de ${character.name}`, date: character.death } as CalendarEvent + return { + title: `${character.name}`, + date: character.death, + category: 'death' + } as CalendarEvent }) })