Fixed events not appearing correctly
This commit is contained in:
@@ -632,30 +632,13 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const baseEvents = ref<CalendarEvent[]>([])
|
const baseEvents = ref<CalendarEvent[]>([])
|
||||||
|
|
||||||
async function fetchCalendarEvents(calendarId: number) {
|
|
||||||
try {
|
|
||||||
const res = await $fetch('/api/calendars/events/query', { query: { calendarId } })
|
|
||||||
|
|
||||||
const eventData = res.data as CalendarEvent[]
|
|
||||||
|
|
||||||
if (!eventData.length) return
|
|
||||||
|
|
||||||
baseEvents.value = eventData
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const categories = ref<Category[]>([])
|
const categories = ref<Category[]>([])
|
||||||
|
|
||||||
// Order base events by dates
|
// Order base events by dates
|
||||||
const allEvents = computed(() => baseEvents.value.sort((a, b) => {
|
const allEvents = computed(() => [...baseEvents.value].sort((a, b) => compareDates(a.startDate, b.startDate, 'desc')))
|
||||||
return compareDates(a.startDate, b.startDate, 'desc')
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Gets all current event in its default state
|
// Gets all current event in its default state
|
||||||
const currentEvents: Ref<CalendarEvent[]> = ref([])
|
const currentEvents = ref<CalendarEvent[]>([])
|
||||||
|
|
||||||
// Watch for currentDate or events' list changes
|
// Watch for currentDate or events' list changes
|
||||||
// This is deep because we're watching an array, and changes need to trigger and mutations like .push and .splice
|
// This is deep because we're watching an array, and changes need to trigger and mutations like .push and .splice
|
||||||
@@ -673,15 +656,17 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
*/
|
*/
|
||||||
function shouldEventBeDisplayed(event: CalendarEvent): boolean {
|
function shouldEventBeDisplayed(event: CalendarEvent): boolean {
|
||||||
const isEventOnCurrentScreen =
|
const isEventOnCurrentScreen =
|
||||||
(event.startDate.year === currentRPGDate.value.day &&
|
(event.startDate.year === currentRPGDate.value.year &&
|
||||||
event.startDate.month === currentRPGDate.value.month) ||
|
event.startDate.month === currentRPGDate.value.month) ||
|
||||||
(event.endDate &&
|
(event.endDate &&
|
||||||
event.endDate.year === currentRPGDate.value.year &&
|
event.endDate.year === currentRPGDate.value.year &&
|
||||||
event.endDate.month === currentRPGDate.value.month)
|
event.endDate.month === currentRPGDate.value.month)
|
||||||
|
|
||||||
|
console.log(event.startDate, isEventOnCurrentScreen, currentRPGDate.value)
|
||||||
|
|
||||||
switch (currentConfig.value.viewType) {
|
switch (currentConfig.value.viewType) {
|
||||||
case 'month':
|
case 'month':
|
||||||
return isEventOnCurrentScreen!
|
return !!isEventOnCurrentScreen
|
||||||
|
|
||||||
case 'year':
|
case 'year':
|
||||||
return event.startDate.year === currentRPGDate.value.year
|
return event.startDate.year === currentRPGDate.value.year
|
||||||
@@ -940,7 +925,6 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
getRelativeString,
|
getRelativeString,
|
||||||
baseEvents,
|
baseEvents,
|
||||||
allEvents,
|
allEvents,
|
||||||
fetchCalendarEvents,
|
|
||||||
categories,
|
categories,
|
||||||
currentEvents,
|
currentEvents,
|
||||||
getRelativeEventFromDate,
|
getRelativeEventFromDate,
|
||||||
|
|||||||
Reference in New Issue
Block a user