]> littlesong.place Git - littlesongplace.git/commitdiff
Fix browser URLs when loading ajax pages
authorChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Feb 2025 12:26:09 +0000 (07:26 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Feb 2025 12:26:09 +0000 (07:26 -0500)
templates/base.html
templates/base.json [new file with mode: 0644]
todo.txt

index 387d8a22f2441fcde8e2272f78bcb7bb9d18a3e6..26390c1bc362b0d1699aa008621cc6d4bca1f940 100644 (file)
                 }
                 event.preventDefault();
 
-                // Update URL in browser window
-                //window.history.pushState({}, "", event.target.href);
-
-                // Make AJAX request
+                // Add AJAX type specifier to URL params
                 var url = new URL(event.target.href);
                 url.searchParams.set("request-type", "ajax")
 
             });
             async function getPageAjax(url) {
                 fetch(url, {redirect: "follow"}).then(async (response) => {
-                    console.log(response);
-                    window.history.pushState({}, "", response.url);
+                    // Update URL in browser window, minus request-type field
+                    var url = new URL(response.url);
+                    url.searchParams.delete("request-type");
+                    window.history.pushState({}, "", url);
+
+                    // Get page content from JSON response
                     var data = await response.json();
                     console.log(data);
                     document.getElementById("main").innerHTML = data.body;
                     document.title = data.title;
+
+                    // Trigger event to signal new page has loaded
                     var event = new Event("DOMContentLoaded");
                     document.dispatchEvent(event);
                 });
diff --git a/templates/base.json b/templates/base.json
new file mode 100644 (file)
index 0000000..03cdf69
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "title": {{ dumps(self.title()) | safe }},
+    "body": {{ dumps(self.body()) | safe }}
+}
index c61f7bf420420b53b08945cb7874be39e2729f78..3606dc459e35bd0fb1aee8cdaa8d4361f708bb58 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -5,6 +5,8 @@ NOW
     - Back (history stack)
     - Other on-site links (songs, profiles, tags, etc.)
     - Update page colors
+    - PFP on profile when missing PFP
+    - Signout doesn't refresh navbar (should show sign in link)
 - Break up main.py, test_offline.py
 - Pinned profile playlists