Skip to content

Commit

Permalink
fix: enhance date picker initialization logic for improved usability
Browse files Browse the repository at this point in the history
- Simplified the date picker value setting to only trigger changes when the value is different, improving performance.
- Ensured the date picker becomes visible when necessary and triggers a change event if the chart is empty, enhancing user experience.
- Removed redundant comments and streamlined the code for better readability and maintainability.
  • Loading branch information
tphakala committed Jan 13, 2025
1 parent 545261d commit c759058
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions assets/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ function initializeDatePicker() {
return `${year}-${month}-${day}`;
}

const today = getIsoDateString(new Date()); // ensures consistent 'YYYY-MM-DD' format

// Set the value first
const today = getIsoDateString(new Date());
const newValue = hashDate || today;

// Only trigger change if the picker is invisible (first load)
// or if the value has actually changed
if (picker.classList.contains('invisible') || picker.value !== newValue) {
// Only trigger change if the value is actually different
if (picker.value !== newValue) {
picker.value = newValue;
picker.classList.remove('invisible'); // Make picker visible
picker.classList.remove('invisible');
htmx.trigger(picker, 'change');
} else if (!document.getElementById('topBirdsChart').children.length) {
// If the value hasn't changed but the chart is empty, trigger the change
htmx.trigger(picker, 'change');
} else {
picker.classList.remove('invisible'); // Make picker visible
}
}

Expand Down

0 comments on commit c759058

Please sign in to comment.