From 2bf2ad2492e9c59128b0f447df674fa4a87ab500 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 31 Mar 2024 19:37:02 +0200 Subject: [PATCH] Added sample data for characters --- src/models/Date.ts | 8 ++++++++ src/stores/calendar.ts | 9 ++++----- src/stores/characters.ts | 18 ++++++++++++++++++ src/stores/events.ts | 30 ++++++++++++++++++++++++++++++ src/views/HomeView.vue | 7 +++++++ 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 src/models/Date.ts create mode 100644 src/stores/characters.ts create mode 100644 src/stores/events.ts diff --git a/src/models/Date.ts b/src/models/Date.ts new file mode 100644 index 0000000..37872e8 --- /dev/null +++ b/src/models/Date.ts @@ -0,0 +1,8 @@ +export type LeimDate = { + day: number + month: number + year: number + period: LeimPeriod +} + +export type LeimPeriod = 'ante' | 'nante' diff --git a/src/stores/calendar.ts b/src/stores/calendar.ts index 2bb7af3..3e6cda7 100644 --- a/src/stores/calendar.ts +++ b/src/stores/calendar.ts @@ -1,8 +1,7 @@ -import { computed, ref, type Ref, type ComputedRef } from 'vue' +import { computed, type Ref, type ComputedRef } from 'vue' import { defineStore } from 'pinia' import { useUrlSearchParams } from '@vueuse/core' - -type CalendarPeriod = 'ante' | 'nante' +import type { LeimPeriod } from '@/models/Date' type CalendarStaticConfig = { months: string[] @@ -13,7 +12,7 @@ type CalendarStaticConfig = { } type CalendarCurrentConfig = { - currentPeriod: Ref + currentPeriod: Ref currentYear: ComputedRef currentMonth: ComputedRef currentDay: ComputedRef @@ -80,7 +79,7 @@ export const useCalendar = defineStore('calendar', () => { const currentYear = computed(() => params.year) // Get period from currentYear - const currentPeriod: ComputedRef = computed(() => { + const currentPeriod: ComputedRef = computed(() => { const year = Number(currentYear.value) return year >= 0 ? 'nante' : 'ante' }) diff --git a/src/stores/characters.ts b/src/stores/characters.ts new file mode 100644 index 0000000..5cca8c6 --- /dev/null +++ b/src/stores/characters.ts @@ -0,0 +1,18 @@ +import { defineStore } from 'pinia' +import type { LeimDate } from '@/models/Date' + +type Character = { + name: string + birth?: LeimDate + death?: LeimDate +} + +export const useCharacters = defineStore('characters', () => { + const characters: Character[] = [ + { 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' } } + ] + + return { characters } +}) diff --git a/src/stores/events.ts b/src/stores/events.ts new file mode 100644 index 0000000..591ea5a --- /dev/null +++ b/src/stores/events.ts @@ -0,0 +1,30 @@ +import { defineStore } from 'pinia' +import { computed } from 'vue' +import { useCharacters } from './characters' + +import type { LeimDate } from '@/models/Date' + +type CalendarEvent = { + title: string + date: LeimDate +} + +export const useCalendarEvents = defineStore('calendar-events', () => { + const { characters } = useCharacters() + + const characterBirthEvents = computed(() => { + const charactersWithBirthData = characters.filter((character) => character.birth) + return charactersWithBirthData.map((character) => { + return { title: `Naissance de ${character.name}`, date: character.birth } as CalendarEvent + }) + }) + + const characterDeathEvents = computed(() => { + const charactersWithDeathData = characters.filter((character) => character.death) + return charactersWithDeathData.map((character) => { + return { title: `Décès de ${character.name}`, date: character.death } as CalendarEvent + }) + }) + + return { characterBirthEvents, characterDeathEvents } +}) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 724c8b6..e722a57 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,10 +1,13 @@ @@ -45,5 +48,9 @@ const monthTarget = ref(0) + +
+      {{ characterDeathEvents }}
+