Fix profile page and Now Playing in frameset mode

Profile page fixes:
- Use session:field with string 'user-id' instead of symbol
- Use find-user-by-id to get user object
- Use dm:field to access user data (username, role)
- Add missing template parameters (top-artist-4, top-artist-5)
- Add error handling with detailed logging

Player-content fixes:
- Remove broken player.js that was causing ReferenceError
- Add simple inline Now Playing updater script
- Fetches /api/asteroid/partial/now-playing every 10 seconds
- Updates after 200ms initial delay

All fixes tested and working in frameset mode:
- Profile page loads correctly with user data
- Now Playing panel updates on player page
- Stream continues playing during navigation
- Spectrum analyzer MUTED indicator working
- Login/logout without halting stream

Known issue:
- ParenScript player.lisp has compilation issue (extra paren on line 242)
- Only 15/36 functions compile
- Non-frameset mode still halts stream on navigation (expected)
This commit is contained in:
Glenn Thompson 2025-12-07 10:17:44 +03:00
parent b54af08eeb
commit d39b155df3
2 changed files with 73 additions and 30 deletions

View File

@ -577,35 +577,53 @@
(define-page profile-content #@"/profile-content" ()
"User profile content (displayed in content frame)"
(require-authentication)
(clip:process-to-string
(load-template "profile-content")
:title "🎧 admin - Profile | Asteroid Radio"
:username "admin"
:user-role "admin"
:join-date "Unknown"
:last-active "Unknown"
:total-listen-time "0h 0m"
:tracks-played "0"
:session-count "0"
:favorite-genre "Unknown"
:recent-track-1-title ""
:recent-track-1-artist ""
:recent-track-1-duration ""
:recent-track-1-played-at ""
:recent-track-2-title ""
:recent-track-2-artist ""
:recent-track-2-duration ""
:recent-track-2-played-at ""
:recent-track-3-title ""
:recent-track-3-artist ""
:recent-track-3-duration ""
:recent-track-3-played-at ""
:top-artist-1 ""
:top-artist-1-plays ""
:top-artist-2 ""
:top-artist-2-plays ""
:top-artist-3 ""
:top-artist-3-plays ""))
(handler-case
(let* ((user-id (session:field "user-id"))
(current-user (when user-id (find-user-by-id user-id)))
(username (if current-user
(let ((uname (dm:field current-user "username")))
(format nil "~a" (or uname "Unknown")))
"Unknown"))
(user-role (if current-user
(let ((role (dm:field current-user "role")))
(format nil "~a" (or role "user")))
"user")))
(clip:process-to-string
(load-template "profile-content")
:title (format nil "🎧 ~a - Profile | Asteroid Radio" username)
:username username
:user-role user-role
:join-date "Unknown"
:last-active "Unknown"
:total-listen-time "0h 0m"
:tracks-played "0"
:session-count "0"
:favorite-genre "Unknown"
:recent-track-1-title ""
:recent-track-1-artist ""
:recent-track-1-duration ""
:recent-track-1-played-at ""
:recent-track-2-title ""
:recent-track-2-artist ""
:recent-track-2-duration ""
:recent-track-2-played-at ""
:recent-track-3-title ""
:recent-track-3-artist ""
:recent-track-3-duration ""
:recent-track-3-played-at ""
:top-artist-1 ""
:top-artist-1-plays ""
:top-artist-2 ""
:top-artist-2-plays ""
:top-artist-3 ""
:top-artist-3-plays ""
:top-artist-4 ""
:top-artist-4-plays ""
:top-artist-5 ""
:top-artist-5-plays ""))
(error (e)
(format t "ERROR in profile-content: ~a~%" e)
(format nil "<html><body><h1>Error loading profile</h1><pre>~a</pre></body></html>" e))))
;; Status content frame (for frameset mode)
(define-page status-content #@"/status-content" ()

View File

@ -6,8 +6,33 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/asteroid/static/asteroid.css">
<script src="/asteroid/static/js/auth-ui.js"></script>
<script src="/asteroid/static/js/player.js"></script>
<script src="/api/asteroid/spectrum-analyzer.js"></script>
<script>
// Simple Now Playing updater
function updateNowPlaying() {
fetch('/api/asteroid/partial/now-playing')
.then(response => {
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('text/html')) {
return response.text();
}
return '';
})
.then(data => {
const nowPlayingDiv = document.getElementById('now-playing');
if (nowPlayingDiv) {
nowPlayingDiv.innerHTML = data;
}
})
.catch(error => console.log('Could not fetch now playing:', error));
}
// Update on load and every 10 seconds
document.addEventListener('DOMContentLoaded', function() {
setTimeout(updateNowPlaying, 200);
setInterval(updateNowPlaying, 10000);
});
</script>
<script>
// Handle logout without navigation
function handleLogout() {