Added sample data for characters
This commit is contained in:
8
src/models/Date.ts
Normal file
8
src/models/Date.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export type LeimDate = {
|
||||||
|
day: number
|
||||||
|
month: number
|
||||||
|
year: number
|
||||||
|
period: LeimPeriod
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LeimPeriod = 'ante' | 'nante'
|
||||||
@@ -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 { defineStore } from 'pinia'
|
||||||
import { useUrlSearchParams } from '@vueuse/core'
|
import { useUrlSearchParams } from '@vueuse/core'
|
||||||
|
import type { LeimPeriod } from '@/models/Date'
|
||||||
type CalendarPeriod = 'ante' | 'nante'
|
|
||||||
|
|
||||||
type CalendarStaticConfig = {
|
type CalendarStaticConfig = {
|
||||||
months: string[]
|
months: string[]
|
||||||
@@ -13,7 +12,7 @@ type CalendarStaticConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CalendarCurrentConfig = {
|
type CalendarCurrentConfig = {
|
||||||
currentPeriod: Ref<CalendarPeriod>
|
currentPeriod: Ref<LeimPeriod>
|
||||||
currentYear: ComputedRef<string | string[]>
|
currentYear: ComputedRef<string | string[]>
|
||||||
currentMonth: ComputedRef<string | string[]>
|
currentMonth: ComputedRef<string | string[]>
|
||||||
currentDay: ComputedRef<string | string[]>
|
currentDay: ComputedRef<string | string[]>
|
||||||
@@ -80,7 +79,7 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
const currentYear = computed(() => params.year)
|
const currentYear = computed(() => params.year)
|
||||||
|
|
||||||
// Get period from currentYear
|
// Get period from currentYear
|
||||||
const currentPeriod: ComputedRef<CalendarPeriod> = computed(() => {
|
const currentPeriod: ComputedRef<LeimPeriod> = computed(() => {
|
||||||
const year = Number(currentYear.value)
|
const year = Number(currentYear.value)
|
||||||
return year >= 0 ? 'nante' : 'ante'
|
return year >= 0 ? 'nante' : 'ante'
|
||||||
})
|
})
|
||||||
|
|||||||
18
src/stores/characters.ts
Normal file
18
src/stores/characters.ts
Normal file
@@ -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 }
|
||||||
|
})
|
||||||
30
src/stores/events.ts
Normal file
30
src/stores/events.ts
Normal file
@@ -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 }
|
||||||
|
})
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useCalendar } from '@/stores/calendar'
|
import { useCalendar } from '@/stores/calendar'
|
||||||
|
import { useCalendarEvents } from '@/stores/events'
|
||||||
|
|
||||||
const { config, incrementMonth, decrementMonth, setMonth, incrementYear, decrementYear } =
|
const { config, incrementMonth, decrementMonth, setMonth, incrementYear, decrementYear } =
|
||||||
useCalendar()
|
useCalendar()
|
||||||
|
|
||||||
|
const { characterBirthEvents, characterDeathEvents } = useCalendarEvents()
|
||||||
|
|
||||||
const monthTarget = ref(0)
|
const monthTarget = ref(0)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -45,5 +48,9 @@ const monthTarget = ref(0)
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
{{ characterDeathEvents }}
|
||||||
|
</pre>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user