Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed duplicate moons #158

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/components/calendar/TheCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -668,26 +668,47 @@ export default {
this.fullCalendarApi.refetchEvents()
},

// Display moon phase icons in the calendar
dayRender (dayRenderInfo) {
// Check if the current view is week view
if (this.fullCalendarApi?.view?.type === 'timeGridWeek') {
this.addUTCTimeColumn()
}

try { // ignore errors from the timezone not being loaded yet.
try {
const date = moment(dayRenderInfo.date).tz(this.fc_timeZone)
const moon_phase = getMoonPhaseDays(
date.year(),
date.month(),
date.date())

if (moon_phase) {
dayRenderInfo.el.innerHTML = `<i class="moon-icon mdi \
mdi-moon-${moon_phase.name}" aria-hidden="true"></i>`
const headerCell = document.querySelector(`.fc-day[data-date="${date.format('YYYY-MM-DD')}"]`)

if (headerCell) {
// Create a unique data attribute for the moon icon based on the date
const moonIconDataAttr = `moon-icon-${date.format('YYYY-MM-DD')}`

// Check if the moon icon has already been added to this specific header cell
if (!headerCell.querySelector(`[data-moon-icon="${moonIconDataAttr}"]`)) {
// Remove any existing moon icons in this cell
const existingMoonIcons = headerCell.querySelectorAll('.moon-icon')
existingMoonIcons.forEach(icon => icon.remove())

// Add new moon icon
const moonIcon = document.createElement('i')
moonIcon.className = `moon-icon mdi mdi-moon-${moon_phase.name}`
moonIcon.setAttribute('aria-hidden', 'true')
moonIcon.setAttribute('data-moon-icon', moonIconDataAttr)

// Append the moon icon to the header cell content
headerCell.appendChild(moonIcon)

// Adjust the style to place it below the date
moonIcon.style.display = 'block'
moonIcon.style.marginTop = '5px'
}
}
}
} catch {
console.warn('dayRender waiting for valid timezone.')
} catch (error) {
console.warn('dayRender waiting for valid timezone.', error)
}
},

Expand Down
Loading