From b0ff67e2e48b11e41fdeccfc9e77ba7e5bb6d70f Mon Sep 17 00:00:00 2001 From: quadbyte Date: Sun, 10 Aug 2025 13:24:11 -0400 Subject: [PATCH] Removed holidays on the calendar --- Helpers/Holidays.js | 81 ------------------------------------------- Widgets/NCalendar.qml | 72 ++------------------------------------ 2 files changed, 2 insertions(+), 151 deletions(-) delete mode 100644 Helpers/Holidays.js diff --git a/Helpers/Holidays.js b/Helpers/Holidays.js deleted file mode 100644 index 1b67774..0000000 --- a/Helpers/Holidays.js +++ /dev/null @@ -1,81 +0,0 @@ -var _countryCode = null; -var _regionCode = null; -var _regionName = null; -var _holidaysCache = {}; - -function getCountryCode(callback) { - if (_countryCode) { - callback(_countryCode); - return; - } - var xhr = new XMLHttpRequest(); - xhr.open("GET", "https://nominatim.openstreetmap.org/search?city="+ Settings.data.location.name+"&country=&format=json&addressdetails=1&extratags=1", true); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { - var response = JSON.parse(xhr.responseText); - _countryCode = response?.[0]?.address?.country_code ?? "US"; - _regionCode = response?.[0]?.address?.["ISO3166-2-lvl4"] ?? ""; - _regionName = response?.[0]?.address?.state ?? ""; - callback(_countryCode); - } - } - xhr.send(); -} - -function getHolidays(year, countryCode, callback) { - var cacheKey = year + "-" + countryCode; - if (_holidaysCache[cacheKey]) { - callback(_holidaysCache[cacheKey]); - return; - } - var url = "https://date.nager.at/api/v3/PublicHolidays/" + year + "/" + countryCode; - var xhr = new XMLHttpRequest(); - xhr.open("GET", url, true); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { - var holidays = JSON.parse(xhr.responseText); - var augmentedHolidays = filterHolidaysByRegion(holidays); - _holidaysCache[cacheKey] = augmentedHolidays; - callback(augmentedHolidays); - } - } - xhr.send(); -} - -function filterHolidaysByRegion(holidays) { - if (!_regionCode) { - return holidays; - } - const retHolidays = []; - holidays.forEach(function(holiday) { - if (holiday.counties?.length > 0) { - let found = false; - holiday.counties.forEach(function(county) { - if (county.toLowerCase() === _regionCode.toLowerCase()) { - found = true; - } - }); - if (found) { - var regionText = " (" + _regionName + ")"; - holiday.name = holiday.name + regionText; - holiday.localName = holiday.localName + regionText; - retHolidays.push(holiday); - } - } else { - retHolidays.push(holiday); - } - }); - return retHolidays; -} - -function getHolidaysForMonth(year, month, callback) { - getCountryCode(function(countryCode) { - getHolidays(year, countryCode, function(holidays) { - var filtered = holidays.filter(function(h) { - var date = new Date(h.date); - return date.getFullYear() === year && date.getMonth() === month; - }); - callback(filtered); - }); - }); -} \ No newline at end of file diff --git a/Widgets/NCalendar.qml b/Widgets/NCalendar.qml index d1518e8..c3ffda8 100644 --- a/Widgets/NCalendar.qml +++ b/Widgets/NCalendar.qml @@ -5,8 +5,6 @@ import Quickshell import Quickshell.Wayland import qs.Services -import "../Helpers/Holidays.js" as Holidays - NPanel { id: root @@ -88,25 +86,12 @@ NPanel { MonthGrid { id: calendar - property var holidays: [] - - // Fetch holidays when calendar is opened or month/year changes - function updateHolidays() { - Holidays.getHolidaysForMonth(calendar.year, calendar.month, - function (holidays) { - calendar.holidays = holidays - }) - } - Layout.fillWidth: true Layout.leftMargin: Style.marginSmall * scaling Layout.rightMargin: Style.marginSmall * scaling spacing: 0 month: Time.date.getMonth() year: Time.date.getFullYear() - onMonthChanged: updateHolidays() - onYearChanged: updateHolidays() - Component.onCompleted: updateHolidays() // Optionally, update when the panel becomes visible Connections { @@ -114,7 +99,6 @@ NPanel { if (root.visible) { calendar.month = Time.date.getMonth() calendar.year = Time.date.getFullYear() - calendar.updateHolidays() } } @@ -122,72 +106,20 @@ NPanel { } delegate: Rectangle { - property var holidayInfo: calendar.holidays.filter(function (h) { - var d = new Date(h.date) - return d.getDate() === model.day && d.getMonth() === model.month - && d.getFullYear() === model.year - }) - property bool isHoliday: holidayInfo.length > 0 - width: Style.baseWidgetSize * scaling height: Style.baseWidgetSize * scaling radius: Style.radiusSmall * scaling - color: { - if (model.today) - return Colors.accentPrimary - - if (mouseArea2.containsMouse) - return Colors.backgroundTertiary - - return "transparent" - } - - // Holiday dot indicator - Rectangle { - visible: isHoliday - width: Style.baseWidgetSize / 8 * scaling - height: Style.baseWidgetSize / 8 * scaling - radius: Style.radiusSmall * scaling - color: Colors.accentTertiary - anchors.top: parent.top - anchors.right: parent.right - anchors.topMargin: Style.marginTiny * scaling - anchors.rightMargin: Style.marginTiny * scaling - z: 2 - } + color: model.today ? Colors.accentPrimary : "transparent" NText { anchors.centerIn: parent text: model.day color: model.today ? Colors.onAccent : Colors.textPrimary - opacity: model.month === calendar.month ? (mouseArea2.containsMouse ? Style.opacityFull : Style.opacityHeavy) : Style.opacityLight + opacity: model.month === calendar.month ? Style.opacityHeavy : Style.opacityLight font.pointSize: Style.fontSizeMedium * scaling font.bold: model.today ? true : false } - MouseArea { - id: mouseArea2 - - anchors.fill: parent - hoverEnabled: true - onEntered: { - if (isHoliday) { - holidayTooltip.text = holidayInfo.map(function (h) { - return h.localName + (h.name !== h.localName ? " (" + h.name + ")" : "") - + (h.global ? " [Global]" : "") - }).join(", ") - holidayTooltip.target = parent - holidayTooltip.show() - } - } - onExited: holidayTooltip.hide() - } - - NTooltip { - id: holidayTooltip - text: "" - } - Behavior on color { ColorAnimation { duration: 150