Removed holidays on the calendar
This commit is contained in:
parent
975cb6018f
commit
b0ff67e2e4
2 changed files with 2 additions and 151 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue