updated the calendar and settings pages, added a new calendar page, and made some minor styling changes to the app.
This commit is contained in:
+124
-15
@@ -9,7 +9,9 @@
|
||||
longitude: -0.1278,
|
||||
timeFormat: "minutes",
|
||||
birthDate: "",
|
||||
tarotDeck: "ceremonial-magick"
|
||||
tarotDeck: "ceremonial-magick",
|
||||
stellariumBackgroundEnabled: false,
|
||||
hasExplicitLocation: false
|
||||
},
|
||||
onSettingsApplied: null,
|
||||
onSyncSkyBackground: null,
|
||||
@@ -31,12 +33,57 @@
|
||||
timeFormatEl: document.getElementById("time-format"),
|
||||
birthDateEl: document.getElementById("birth-date"),
|
||||
tarotDeckEl: document.getElementById("tarot-deck"),
|
||||
stellariumBackgroundEl: document.getElementById("stellarium-background"),
|
||||
stellariumBackgroundHintEl: document.getElementById("stellarium-background-hint"),
|
||||
apiBaseUrlEl: document.getElementById("api-base-url"),
|
||||
apiKeyEl: document.getElementById("api-key"),
|
||||
saveSettingsEl: document.getElementById("save-settings"),
|
||||
useLocationEl: document.getElementById("use-location")
|
||||
};
|
||||
}
|
||||
|
||||
function setLocationEntryState(isExplicit) {
|
||||
const { latEl, lngEl } = getElements();
|
||||
const normalizedValue = isExplicit ? "true" : "false";
|
||||
|
||||
if (latEl) {
|
||||
latEl.dataset.explicitLocation = normalizedValue;
|
||||
}
|
||||
|
||||
if (lngEl) {
|
||||
lngEl.dataset.explicitLocation = normalizedValue;
|
||||
}
|
||||
}
|
||||
|
||||
function hasExplicitLocationEntry() {
|
||||
const { latEl } = getElements();
|
||||
return latEl?.dataset.explicitLocation === "true";
|
||||
}
|
||||
|
||||
function syncStellariumBackgroundAvailability() {
|
||||
const { stellariumBackgroundEl, stellariumBackgroundHintEl } = getElements();
|
||||
if (!stellariumBackgroundEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasExplicitLocation = hasExplicitLocationEntry();
|
||||
stellariumBackgroundEl.disabled = !hasExplicitLocation;
|
||||
|
||||
if (!hasExplicitLocation) {
|
||||
stellariumBackgroundEl.checked = false;
|
||||
}
|
||||
|
||||
if (stellariumBackgroundHintEl) {
|
||||
stellariumBackgroundHintEl.textContent = hasExplicitLocation
|
||||
? "Uses your saved location to load the live sky background."
|
||||
: "Enter a location or use My Location before enabling the live sky background.";
|
||||
}
|
||||
}
|
||||
|
||||
function markLocationAsExplicit() {
|
||||
setLocationEntryState(true);
|
||||
syncStellariumBackgroundAvailability();
|
||||
}
|
||||
function getConnectionSettings() {
|
||||
return window.TarotAppConfig?.getConnectionSettings?.() || {
|
||||
apiBaseUrl: String(window.TarotAppConfig?.apiBaseUrl || "").trim(),
|
||||
@@ -75,9 +122,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
function syncSky(geo, force) {
|
||||
function syncSky(geo, options) {
|
||||
if (typeof config.onSyncSkyBackground === "function") {
|
||||
config.onSyncSkyBackground(geo, force);
|
||||
config.onSyncSkyBackground(geo, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,13 +199,35 @@
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
}
|
||||
|
||||
function parseStoredBoolean(value, fallback = false) {
|
||||
return typeof value === "boolean" ? value : fallback;
|
||||
}
|
||||
|
||||
function hasLegacyExplicitLocation(settings, normalizedLatitude, normalizedLongitude) {
|
||||
const hasStoredCoordinates = Number.isFinite(Number(settings?.latitude)) && Number.isFinite(Number(settings?.longitude));
|
||||
if (!hasStoredCoordinates) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Math.abs(normalizedLatitude - Number(config.defaultSettings.latitude)) > 0.00005
|
||||
|| Math.abs(normalizedLongitude - Number(config.defaultSettings.longitude)) > 0.00005;
|
||||
}
|
||||
|
||||
function normalizeSettings(settings) {
|
||||
const latitude = parseStoredNumber(settings?.latitude, config.defaultSettings.latitude);
|
||||
const longitude = parseStoredNumber(settings?.longitude, config.defaultSettings.longitude);
|
||||
const hasExplicitLocation = typeof settings?.hasExplicitLocation === "boolean"
|
||||
? settings.hasExplicitLocation
|
||||
: hasLegacyExplicitLocation(settings, latitude, longitude);
|
||||
|
||||
return {
|
||||
latitude: parseStoredNumber(settings?.latitude, config.defaultSettings.latitude),
|
||||
longitude: parseStoredNumber(settings?.longitude, config.defaultSettings.longitude),
|
||||
latitude,
|
||||
longitude,
|
||||
timeFormat: normalizeTimeFormat(settings?.timeFormat),
|
||||
birthDate: normalizeBirthDate(settings?.birthDate),
|
||||
tarotDeck: normalizeTarotDeck(settings?.tarotDeck)
|
||||
tarotDeck: normalizeTarotDeck(settings?.tarotDeck),
|
||||
stellariumBackgroundEnabled: parseStoredBoolean(settings?.stellariumBackgroundEnabled, false) && hasExplicitLocation,
|
||||
hasExplicitLocation
|
||||
};
|
||||
}
|
||||
|
||||
@@ -285,7 +354,7 @@
|
||||
}
|
||||
|
||||
function applySettingsToInputs(settings) {
|
||||
const { latEl, lngEl, timeFormatEl, birthDateEl, tarotDeckEl } = getElements();
|
||||
const { latEl, lngEl, timeFormatEl, birthDateEl, tarotDeckEl, stellariumBackgroundEl } = getElements();
|
||||
syncTarotDeckInputOptions();
|
||||
syncConnectionInputs();
|
||||
const normalized = normalizeSettings(settings);
|
||||
@@ -296,6 +365,11 @@
|
||||
if (tarotDeckEl) {
|
||||
tarotDeckEl.value = normalized.tarotDeck;
|
||||
}
|
||||
setLocationEntryState(normalized.hasExplicitLocation);
|
||||
if (stellariumBackgroundEl) {
|
||||
stellariumBackgroundEl.checked = normalized.stellariumBackgroundEnabled;
|
||||
}
|
||||
syncStellariumBackgroundAvailability();
|
||||
if (window.TarotCardImages?.setActiveDeck) {
|
||||
window.TarotCardImages.setActiveDeck(normalized.tarotDeck);
|
||||
}
|
||||
@@ -304,9 +378,16 @@
|
||||
}
|
||||
|
||||
function getSettingsFromInputs() {
|
||||
const { latEl, lngEl, timeFormatEl, birthDateEl, tarotDeckEl } = getElements();
|
||||
const latitude = Number(latEl.value);
|
||||
const longitude = Number(lngEl.value);
|
||||
const { latEl, lngEl, timeFormatEl, birthDateEl, tarotDeckEl, stellariumBackgroundEl } = getElements();
|
||||
const latitudeText = String(latEl?.value || "").trim();
|
||||
const longitudeText = String(lngEl?.value || "").trim();
|
||||
|
||||
if (!latitudeText || !longitudeText) {
|
||||
throw new Error("Latitude/Longitude must be entered before saving settings.");
|
||||
}
|
||||
|
||||
const latitude = Number(latitudeText);
|
||||
const longitude = Number(longitudeText);
|
||||
|
||||
if (Number.isNaN(latitude) || Number.isNaN(longitude)) {
|
||||
throw new Error("Latitude/Longitude must be valid numbers.");
|
||||
@@ -317,7 +398,9 @@
|
||||
longitude,
|
||||
timeFormat: normalizeTimeFormat(timeFormatEl.value),
|
||||
birthDate: normalizeBirthDate(birthDateEl.value),
|
||||
tarotDeck: normalizeTarotDeck(tarotDeckEl?.value)
|
||||
tarotDeck: normalizeTarotDeck(tarotDeckEl?.value),
|
||||
stellariumBackgroundEnabled: Boolean(stellariumBackgroundEl?.checked),
|
||||
hasExplicitLocation: hasExplicitLocationEntry()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -363,7 +446,14 @@
|
||||
const connectionChanged = hasConnectionChanged(previousConnectionSettings, connectionSettings);
|
||||
const connectionResult = window.TarotAppConfig?.updateConnectionSettings?.(connectionSettings) || { didPersist: true };
|
||||
const normalized = applySettingsToInputs(settings);
|
||||
syncSky({ latitude: normalized.latitude, longitude: normalized.longitude }, true);
|
||||
syncSky(
|
||||
{ latitude: normalized.latitude, longitude: normalized.longitude },
|
||||
{
|
||||
force: true,
|
||||
backgroundEnabled: normalized.stellariumBackgroundEnabled,
|
||||
hasExplicitLocation: normalized.hasExplicitLocation
|
||||
}
|
||||
);
|
||||
const didPersist = saveSettings(normalized);
|
||||
emitSettingsUpdated(normalized);
|
||||
if (typeof config.getActiveSection === "function" && config.getActiveSection() !== "home") {
|
||||
@@ -396,8 +486,16 @@
|
||||
({ coords }) => {
|
||||
latEl.value = coords.latitude.toFixed(4);
|
||||
lngEl.value = coords.longitude.toFixed(4);
|
||||
syncSky({ latitude: coords.latitude, longitude: coords.longitude }, true);
|
||||
setStatus("Location set from browser. Click Save Settings to refresh.");
|
||||
markLocationAsExplicit();
|
||||
syncSky(
|
||||
{ latitude: coords.latitude, longitude: coords.longitude },
|
||||
{
|
||||
force: true,
|
||||
backgroundEnabled: Boolean(getElements().stellariumBackgroundEl?.checked),
|
||||
hasExplicitLocation: true
|
||||
}
|
||||
);
|
||||
setStatus("Location set from browser. Save Settings to use it across the app.");
|
||||
},
|
||||
(err) => {
|
||||
const detail = err?.message || `code ${err?.code ?? "unknown"}`;
|
||||
@@ -414,7 +512,9 @@
|
||||
openSettingsEl,
|
||||
closeSettingsEl,
|
||||
settingsPopupEl,
|
||||
settingsPopupCardEl
|
||||
settingsPopupCardEl,
|
||||
latEl,
|
||||
lngEl
|
||||
} = getElements();
|
||||
|
||||
if (saveSettingsEl) {
|
||||
@@ -427,6 +527,15 @@
|
||||
useLocationEl.addEventListener("click", requestGeoLocation);
|
||||
}
|
||||
|
||||
[latEl, lngEl].forEach((inputEl) => {
|
||||
if (!inputEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
inputEl.addEventListener("input", markLocationAsExplicit);
|
||||
inputEl.addEventListener("change", markLocationAsExplicit);
|
||||
});
|
||||
|
||||
if (openSettingsEl) {
|
||||
openSettingsEl.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user