From: Chris Fulljames Date: Sat, 22 Feb 2025 20:00:31 +0000 (-0500) Subject: Handle navigation errors and missing colors X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6386637ef8d85cde3f027c1634fb066dab61e9f;p=littlesongplace.git Handle navigation errors and missing colors --- diff --git a/main.py b/main.py index 5ff19ff..c146379 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,10 @@ DB_VERSION = 3 DATA_DIR = Path(os.environ["DATA_DIR"]) if "DATA_DIR" in os.environ else Path(".") SCRIPT_DIR = Path(__file__).parent +BGCOLOR = "#e8e6b5" +FGCOLOR = "#695c73" +ACCOLOR = "#9373a9" + ################################################################################ # Logging ################################################################################ @@ -173,9 +177,9 @@ def users_profile(profile_username): name=profile_username, userid=profile_userid, bio=profile_bio, - fgcolor=profile_data["fgcolor"], - bgcolor=profile_data["bgcolor"], - accolor=profile_data["accolor"], + bgcolor=profile_data["bgcolor"] or BGCOLOR, + fgcolor=profile_data["fgcolor"] or FGCOLOR, + accolor=profile_data["accolor"] or ACCOLOR, playlists=plist_data, songs=songs, user_has_pfp=(get_user_images_path(profile_userid)/"pfp.jpg").exists(), @@ -519,9 +523,9 @@ def song(userid, songid): "song.html", songs=[song], song=song, - bgcolor=user_data["bgcolor"], - fgcolor=user_data["fgcolor"], - accolor=user_data["accolor"]) + bgcolor=user_data["bgcolor"] or BGCOLOR, + fgcolor=user_data["fgcolor"] or FGCOLOR, + accolor=user_data["accolor"] or ACCOLOR) except ValueError: abort(404) else: @@ -866,9 +870,9 @@ def playlists(playlistid): private=plist_data["private"], userid=plist_data["userid"], username=plist_data["username"], - bgcolor=plist_data["bgcolor"], - fgcolor=plist_data["fgcolor"], - accolor=plist_data["accolor"], + bgcolor=plist_data["bgcolor"] or BGCOLOR, + fgcolor=plist_data["fgcolor"] or FGCOLOR, + accolor=plist_data["accolor"] or ACCOLOR, songs=songs) def flash_and_log(msg, category=None): diff --git a/static/nav.js b/static/nav.js index 4787f5d..8771546 100644 --- a/static/nav.js +++ b/static/nav.js @@ -28,6 +28,7 @@ document.addEventListener("DOMContentLoaded", (e) => { document.querySelectorAll(".nav-logged-out").forEach((e) => {e.hidden = loggedIn;}); if (loggedIn) { document.getElementById("logged-in-status").innerText = `Signed in as ${username}`; + document.getElementById("my-profile").href = `/users/${username}`; } // Update activity indicator status @@ -39,7 +40,7 @@ function onLinkClick(event) { if (urlIsOnSameSite(targetUrl)) { event.preventDefault(); event.stopPropagation(); - fetch(targetUrl, {redirect: "follow"}).then(handleAjaxResponse); + fetch(targetUrl, {redirect: "follow"}).then(handleAjaxResponse).catch((err) => console.log(err)); } } @@ -50,7 +51,8 @@ function onFormSubmit(event) { event.stopPropagation(); var formData = new FormData(event.target); fetch(targetUrl, {redirect: "follow", body: formData, method: event.target.method}) - .then(handleAjaxResponse); + .then(handleAjaxResponse) + .catch((err) => window.location.reload()); // Failed to submit form; just reload page (should never happen) } } @@ -60,6 +62,9 @@ function urlIsOnSameSite(targetUrl) { } async function handleAjaxResponse(response) { + if (response.status != 200) { + window.location.href = response.url; + } // Update URL in browser window, minus request-type field var url = new URL(response.url); url.searchParams.delete("request-type"); @@ -78,7 +83,7 @@ function updatePageState(data) { // Replace the contents of the current page with those from data if (!data) { - fetch(window.location.href, {redirect: "follow"}).then(handleAjaxResponse); + fetch(window.location.href, {redirect: "follow"}).then(handleAjaxResponse).catch((err) => window.location.reload()); return; } var parser = new DOMParser(); diff --git a/templates/base.html b/templates/base.html index 93fb69a..2189ea0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -29,7 +29,7 @@ Home News - + Activity diff --git a/todo.txt b/todo.txt index f3b6167..4001122 100644 --- a/todo.txt +++ b/todo.txt @@ -1,11 +1,8 @@ NOW -- AJAX pages so songs can play during navigation - - Use correct content type header for response - - HTTP Error handling -- Break up main.py, test_offline.py -- Pinned profile playlists SOON +- Break up main.py, test_offline.py +- Pinned profile playlists - Image support in comments, descriptions, bios, etc. - Player minimize button - Shuffle all page