fixed issue with sidebar not loading profile info on view switch and updated sidebar styling

This commit is contained in:
Keep Creating Online
2025-02-05 22:29:28 -05:00
parent 22ab53d338
commit 6f05fd8ca3
7 changed files with 144 additions and 93 deletions

View File

@@ -54,7 +54,7 @@
<div class="flex items-center space-x-4"> <div class="flex items-center space-x-4">
<img <img
id="profileModalAvatar" id="profileModalAvatar"
src="assets/jpg/default-profile.jpg" src="assets/svg/default-profile.svg"
alt="Profile" alt="Profile"
class="w-16 h-16 object-cover rounded-full" class="w-16 h-16 object-cover rounded-full"
/> />

View File

@@ -3,11 +3,13 @@
class="bg-gray-900 text-white transition-transform duration-300 ease-in-out fixed top-0 left-0 w-64 h-full -translate-x-full hidden md:translate-x-0 md:block" class="bg-gray-900 text-white transition-transform duration-300 ease-in-out fixed top-0 left-0 w-64 h-full -translate-x-full hidden md:translate-x-0 md:block"
> >
<div class="flex flex-col h-full"> <div class="flex flex-col h-full">
<div class="flex-1 overflow-y-auto"> <!-- Top Navigation Links -->
<nav class="mt-4"> <div class="flex-1 overflow-y-auto px-4">
<div class="bg-gray-800 rounded-lg shadow-md mt-4 p-4">
<nav class="flex flex-col space-y-2">
<a <a
href="#view=most-recent-videos" href="#view=most-recent-videos"
class="flex items-center py-2 px-4 hover:bg-gray-800" class="flex items-center py-2 px-4 hover:bg-gray-700 rounded font-semibold"
> >
<img <img
src="assets/svg/home-icon.svg" src="assets/svg/home-icon.svg"
@@ -18,7 +20,7 @@
</a> </a>
<a <a
href="#view=explore" href="#view=explore"
class="flex items-center py-2 px-4 hover:bg-gray-800" class="flex items-center py-2 px-4 hover:bg-gray-700 rounded font-semibold"
> >
<img <img
src="assets/svg/explore-icon.svg" src="assets/svg/explore-icon.svg"
@@ -29,7 +31,7 @@
</a> </a>
<a <a
href="#view=subscriptions" href="#view=subscriptions"
class="flex items-center py-2 px-4 hover:bg-gray-800" class="flex items-center py-2 px-4 hover:bg-gray-700 rounded font-semibold"
> >
<img <img
src="assets/svg/subscriptions-icon.svg" src="assets/svg/subscriptions-icon.svg"
@@ -40,17 +42,19 @@
</a> </a>
</nav> </nav>
</div> </div>
</div>
<!-- Footer Links -->
<div class="mt-auto"> <div class="mt-auto">
<hr class="border-gray-700" /> <hr class="border-gray-700" />
<div class="p-4"> <div class="p-4">
<nav class="space-y-2"> <nav class="space-y-2 text-sm opacity-70">
<a <a
href="about.html" href="about.html"
class="flex items-center hover:bg-gray-800 px-4 py-2 rounded" class="flex items-center hover:bg-gray-800 px-4 py-2 rounded"
> >
<img <img
src="assets/svg/about-icon.svg" src="assets/svg/about-icon.svg"
target="_blank"
alt="About" alt="About"
class="w-5 h-5 mr-3" class="w-5 h-5 mr-3"
/> />
@@ -62,7 +66,6 @@
> >
<img <img
src="assets/svg/guidelines-icon.svg" src="assets/svg/guidelines-icon.svg"
target="_blank"
alt="Guidelines" alt="Guidelines"
class="w-5 h-5 mr-3" class="w-5 h-5 mr-3"
/> />
@@ -74,7 +77,6 @@
> >
<img <img
src="assets/svg/getting-started-icon.svg" src="assets/svg/getting-started-icon.svg"
target="_blank"
alt="Getting Started" alt="Getting Started"
class="w-5 h-5 mr-3" class="w-5 h-5 mr-3"
/> />
@@ -114,7 +116,6 @@
> >
<img <img
src="assets/svg/roadmap-icon.svg" src="assets/svg/roadmap-icon.svg"
target="_blank"
alt="Roadmap" alt="Roadmap"
class="w-5 h-5 mr-3" class="w-5 h-5 mr-3"
/> />

View File

@@ -84,10 +84,14 @@
<!-- Login Button --> <!-- Login Button -->
<button <button
id="loginButton" id="loginButton"
style="background-color: #fe0032" style="background-color: #1e293b"
class="inline-flex items-center justify-center w-12 h-12 rounded-full text-white text-sm font-bold leading-none hover:bg-[#e6002c] focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2" class="inline-flex items-center justify-center w-12 h-12 rounded-full text-white text-sm font-bold leading-none hover:bg-[#e6002c] focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2"
> >
login <img
src="assets/svg/default-profile.svg"
alt="Profile Icon"
class="w-9 h-9"
/>
</button> </button>
<!-- Upload Button (hidden by default) --> <!-- Upload Button (hidden by default) -->
@@ -107,7 +111,7 @@
<div class="w-10 h-10 rounded-full overflow-hidden"> <div class="w-10 h-10 rounded-full overflow-hidden">
<img <img
id="profileAvatar" id="profileAvatar"
src="assets/jpg/default-profile.jpg" src="assets/svg/default-profile.svg"
alt="Profile" alt="Profile"
class="w-full h-full object-cover" class="w-full h-full object-cover"
/> />

View File

@@ -511,12 +511,12 @@ class bitvidApp {
{ kinds: [0], authors: [pubkey], limit: 1 }, { kinds: [0], authors: [pubkey], limit: 1 },
]); ]);
let displayName = "User"; let displayName = "User";
let picture = "assets/jpg/default-profile.jpg"; let picture = "assets/svg/default-profile.svg";
if (events.length && events[0].content) { if (events.length && events[0].content) {
const data = JSON.parse(events[0].content); const data = JSON.parse(events[0].content);
displayName = data.name || data.display_name || "User"; displayName = data.name || data.display_name || "User";
picture = data.picture || "assets/jpg/default-profile.jpg"; picture = data.picture || "assets/svg/default-profile.svg";
} }
// If you have a top-bar avatar (profileAvatar) // If you have a top-bar avatar (profileAvatar)
@@ -707,7 +707,14 @@ class bitvidApp {
this.activeIntervals = []; this.activeIntervals = [];
} }
// 2) Cleanup resources (this stops the torrent, etc.) // *** EXPLICITLY CANCEL THE SERVICE WORKER STREAM ***
try {
await fetch("/webtorrent/cancel/", { mode: "no-cors" });
} catch (err) {
// Silently ignore if offline or the request fails
}
// 2) Cleanup resources (stops WebTorrent, etc.)
await this.cleanup(); await this.cleanup();
// 3) Hide the modal // 3) Hide the modal
@@ -945,7 +952,7 @@ class bitvidApp {
<img <img
class="author-pic" class="author-pic"
data-pubkey="${video.pubkey}" data-pubkey="${video.pubkey}"
src="assets/jpg/default-profile.jpg" src="assets/svg/default-profile.svg"
alt="Placeholder" alt="Placeholder"
/> />
</div> </div>
@@ -1011,7 +1018,7 @@ class bitvidApp {
const data = JSON.parse(userEvents[0].content); const data = JSON.parse(userEvents[0].content);
const profile = { const profile = {
name: data.name || data.display_name || "Unknown", name: data.name || data.display_name || "Unknown",
picture: data.picture || "assets/jpg/default-profile.jpg", picture: data.picture || "assets/svg/default-profile.svg",
}; };
// Store into the cache with a timestamp // Store into the cache with a timestamp
@@ -1401,7 +1408,7 @@ class bitvidApp {
video.alreadyDecrypted = true; video.alreadyDecrypted = true;
} }
// 5) Show the modal // 5) Show the modal and set the "please stand by" poster
this.currentVideo = video; this.currentVideo = video;
this.currentMagnetUri = video.magnet; this.currentMagnetUri = video.magnet;
this.showModalWithPoster(); this.showModalWithPoster();
@@ -1464,13 +1471,49 @@ class bitvidApp {
const cacheBustedMagnet = video.magnet + "&ts=" + Date.now(); const cacheBustedMagnet = video.magnet + "&ts=" + Date.now();
this.log("Starting video stream with:", cacheBustedMagnet); this.log("Starting video stream with:", cacheBustedMagnet);
// 11) Set autoplay preferences:
// Read user preference from localStorage (if not set, default to muted)
const storedUnmuted = localStorage.getItem("unmutedAutoplay");
const userWantsUnmuted = storedUnmuted === "true";
this.modalVideo.muted = !userWantsUnmuted;
this.log(
"Autoplay preference - unmuted:",
userWantsUnmuted,
"=> muted:",
this.modalVideo.muted
);
// Attach a volumechange listener to update the stored preference
this.modalVideo.addEventListener("volumechange", () => {
localStorage.setItem(
"unmutedAutoplay",
(!this.modalVideo.muted).toString()
);
this.log(
"Volume changed, new unmuted preference:",
!this.modalVideo.muted
);
});
// 12) Start torrent streaming
const realTorrent = await torrentClient.streamVideo( const realTorrent = await torrentClient.streamVideo(
cacheBustedMagnet, cacheBustedMagnet,
this.modalVideo this.modalVideo
); );
// 11) Start intervals to update stats // 13) Attempt to autoplay; if unmuted autoplay fails, fall back to muted
// *** Slower stats update => 3 seconds this.modalVideo.play().catch((err) => {
this.log("Autoplay failed:", err);
if (!this.modalVideo.muted) {
this.log("Falling back to muted autoplay.");
this.modalVideo.muted = true;
this.modalVideo.play().catch((err2) => {
this.log("Muted autoplay also failed:", err2);
});
}
});
// 14) Start intervals to update torrent stats (every 3 seconds)
const updateInterval = setInterval(() => { const updateInterval = setInterval(() => {
if (!document.body.contains(this.modalVideo)) { if (!document.body.contains(this.modalVideo)) {
clearInterval(updateInterval); clearInterval(updateInterval);
@@ -1480,7 +1523,7 @@ class bitvidApp {
}, 3000); }, 3000);
this.activeIntervals.push(updateInterval); this.activeIntervals.push(updateInterval);
// (Optional) Mirror small inline stats into the modal // 15) (Optional) Mirror small inline stats into the modal
const mirrorInterval = setInterval(() => { const mirrorInterval = setInterval(() => {
if (!document.body.contains(this.modalVideo)) { if (!document.body.contains(this.modalVideo)) {
clearInterval(mirrorInterval); clearInterval(mirrorInterval);

View File

@@ -1,46 +1,29 @@
import { loadView } from "./viewManager.js"; import { loadView } from "./viewManager.js";
import { viewInitRegistry } from "./viewManager.js";
/**
* Wire up the sidebar links.
* Home => loads the "most-recent-videos" partial and re-renders videos
* Explore => loads explore.html with a "Coming Soon" message
* Subscriptions => loads subscriptions.html with a "Coming Soon" message
*/
export function setupSidebarNavigation() { export function setupSidebarNavigation() {
// 1) Home // Grab all primary nav links that use the "#view=..." pattern
const homeLink = document.querySelector('a[href="#view=most-recent-videos"]'); const sidebarLinks = document.querySelectorAll('#sidebar a[href^="#view="]');
if (homeLink) { sidebarLinks.forEach((link) => {
homeLink.addEventListener("click", (e) => { link.addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
loadView("views/most-recent-videos.html").then(() => { // For a link like "#view=most-recent-videos", parse out "most-recent-videos"
// Once the partial is loaded, reassign #videoList + call loadVideos const href = link.getAttribute("href") || "";
if (window.app && window.app.loadVideos) { const viewMatch = href.match(/#view=(.+)/);
window.app.videoList = document.getElementById("videoList"); if (!viewMatch || !viewMatch[1]) {
window.app.loadVideos(); return;
}
});
});
} }
const viewName = viewMatch[1]; // e.g. "most-recent-videos"
const viewUrl = `views/${viewName}.html`;
// 2) Explore // Load the partial view
const exploreLink = document.querySelector('a[href="#view=explore"]'); loadView(viewUrl).then(() => {
if (exploreLink) { // If there's a post-load function for this view, call it
exploreLink.addEventListener("click", (e) => { const initFn = viewInitRegistry[viewName];
e.preventDefault(); if (typeof initFn === "function") {
loadView("views/explore.html"); initFn();
// We just show the partial. No dynamic videos needed yet. }
});
});
}); });
} }
// 3) Subscriptions
const subscriptionsLink = document.querySelector(
'a[href="#view=subscriptions"]'
);
if (subscriptionsLink) {
subscriptionsLink.addEventListener("click", (e) => {
e.preventDefault();
loadView("views/subscriptions.html");
// Also "Coming Soon" in that partial for now.
});
}
}

View File

@@ -15,3 +15,23 @@ export async function loadView(viewUrl) {
"<p class='text-center text-red-500'>Failed to load content.</p>"; "<p class='text-center text-red-500'>Failed to load content.</p>";
} }
} }
export const viewInitRegistry = {
"most-recent-videos": () => {
if (window.app && window.app.loadVideos) {
window.app.videoList = document.getElementById("videoList");
window.app.loadVideos();
}
// Force the profiles to update after the new view is in place.
if (window.app && window.app.forceRefreshAllProfiles) {
window.app.forceRefreshAllProfiles();
}
},
explore: () => {
console.log("Explore view loaded.");
},
subscriptions: () => {
console.log("Subscriptions view loaded.");
},
// Add additional view-specific functions here as needed.
};

View File

@@ -176,7 +176,7 @@ export class TorrentClient {
return reject(new Error("No compatible video file found in torrent")); return reject(new Error("No compatible video file found in torrent"));
} }
videoElement.muted = false; videoElement.muted = true;
videoElement.crossOrigin = "anonymous"; videoElement.crossOrigin = "anonymous";
videoElement.addEventListener("error", (e) => { videoElement.addEventListener("error", (e) => {