Added base event checking

This commit is contained in:
Alexis
2024-04-01 19:19:24 +02:00
parent 1404e54d13
commit 7a7c27d780
7 changed files with 145 additions and 19 deletions

View File

@@ -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<LeimDate> = 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
}
})

View File

@@ -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' } }

View File

@@ -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
})
})