From 259ad59755b81834694da339b306cb625947d57a Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 17 Apr 2024 17:17:58 -0600 Subject: [PATCH] Fix bug with solved puzzle tracking --- CHANGELOG.md | 4 ++++ theme/common.mjs | 25 ++++++++++++++++--------- theme/index.html | 2 +- theme/index.mjs | 6 ++++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a41131d..7f414e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v4.6.1] - 2024-04-17 +### Changed +- Fixed bug with solved puzzle tracking when config.json cannot be loaded. + ## [v4.6.0] - 2024-04-17 ### Changed - Mothd now correctly handles using the current directory for a path. diff --git a/theme/common.mjs b/theme/common.mjs index 69e752e..e699da2 100644 --- a/theme/common.mjs +++ b/theme/common.mjs @@ -48,7 +48,7 @@ function WhenDOMLoaded(cb) { * @param {String} s * @returns {Boolean} */ -function Truthy(s) { +function StringTruthy(s) { switch (s.toLowerCase()) { case "disabled": case "no": @@ -66,13 +66,20 @@ function Truthy(s) { * @returns {Promise.} */ async function Config() { - let resp = await fetch( - new URL("config.json", BaseURL), - { - cache: "no-cache" - }, - ) - return resp.json() + let obj = {} + try { + let resp = await fetch( + new URL("configg.json", BaseURL), + { + cache: "no-cache" + }, + ) + obj = await resp.json() + } + catch(err) { + obj = {} + } + return obj } export { @@ -83,6 +90,6 @@ export { BaseURL, Toast, WhenDOMLoaded, - Truthy, + StringTruthy, Config, } diff --git a/theme/index.html b/theme/index.html index cf325e3..7749e41 100644 --- a/theme/index.html +++ b/theme/index.html @@ -29,7 +29,7 @@ Solved puzzle tracking: disabled.

- Your team's Incident Coordinator can help coordinate team activity. + To avoid duplication of work, your team should coordinate.

diff --git a/theme/index.mjs b/theme/index.mjs index d409547..d3e386f 100644 --- a/theme/index.mjs +++ b/theme/index.mjs @@ -92,8 +92,10 @@ class App { // Update elements with data-track-solved for (let e of document.querySelectorAll("[data-track-solved]")) { - // Only display if data-track-solved is the same as config.trackSolved - e.classList.toggle("hidden", common.Truthy(e.dataset.trackSolved) != this.config.PuzzleList?.TrackSolved) + // Only hide if data-track-solved is different than config.PuzzleList.TrackSolved + let tracking = this.config.PuzzleList?.TrackSolved || false + let displayIf = common.StringTruthy(e.dataset.trackSolved) + e.classList.toggle("hidden", tracking != displayIf) } for (let e of document.querySelectorAll(".login")) {