]> littlesong.place Git - littlesongplace.git/commitdiff
Initial work on ajaxification
authorChris Fulljames <christianfulljames@gmail.com>
Mon, 17 Feb 2025 01:18:45 +0000 (20:18 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Mon, 17 Feb 2025 01:18:45 +0000 (20:18 -0500)
main.py
templates/base.html
templates/index.html
todo.txt

diff --git a/main.py b/main.py
index ada6574e4462f1b5604817650b10d5c832a67f96..3e16b752f2c22156df40331d29b715d3d4290cf6 100644 (file)
--- a/main.py
+++ b/main.py
@@ -929,7 +929,8 @@ def get_current_user_playlists():
 
 @app.context_processor
 def inject_global_vars():
-    return dict(gif_data=get_gif_data(), current_user_playlists=get_current_user_playlists())
+    use_json = request.args.get("request-type", None) == "ajax"
+    return dict(gif_data=get_gif_data(), current_user_playlists=get_current_user_playlists(), use_json=use_json, dumps=json.dumps)
 
 
 ################################################################################
index 693afd35127d61016645ea0d0152cbe65675081b..91759b747c0535362e5a4c5af62964b52d360058 100644 (file)
@@ -9,6 +9,29 @@
         <!-- Page-specific head fields -->
         {% block head %}
         {% endblock %}
+        <script>
+            document.addEventListener("click", (event) => {
+                // TODO - what links do we actually want to match?  Use URL?
+                if (!event.target.matches(".navbar a")) {
+                    return;
+                }
+                event.preventDefault();
+
+                // Update URL in browser window
+                window.history.pushState({}, "", event.target.href);
+
+                // Make AJAX request
+                var url = new URL(event.target.href);
+                url.searchParams.set("request-type", "ajax")
+
+                // Update HTML
+                getPageAjax(url);
+            });
+            async function getPageAjax(url) {
+                var data = await fetch(url).then((response) => response.json());
+                console.log(data);
+            }
+        </script>
     </head>
     <body>
 
index f04887acec58b51746ab149985e7b6ae7c9e5bef..64e53c9b4ff9910b9f3c61911fe762bc64a99374 100644 (file)
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% if use_json %}{% extends "base.json" %}{% else %}{% extends "base.html" %}{% endif %}
 
 {% block title %}Little Song Place{% endblock %}
 
index 646d236f7436f9ca73de12b616bb2750da60854f..8f64c6b6389fadd4eeebdb321db47da195a21ddc 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,10 +1,13 @@
 NOW
-
-SOON
-- Break up main.py, test_offline.py
 - AJAX pages so songs can play during navigation
+    - Nav bar
+    - Forms
+    - Back (history stack)
+    - Other on-site links (songs, profiles, tags, etc.)
+- Break up main.py, test_offline.py
 - Pinned profile playlists
 
+SOON
 - Image support in comments, descriptions, bios, etc.
 - Player minimize button
 - Shuffle all page