mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #162 from PR0M3TH3AN/codex/extend-profile-switching-functionality
Add profile switching flow to saved profile cards
This commit is contained in:
1 file changed
+90
@@ -3755,6 +3755,37 @@ class bitvidApp {
|
||||
: `Switch to ${cardDisplayName}`;
|
||||
button.setAttribute("aria-label", ariaLabel);
|
||||
|
||||
const activateProfile = async (event) => {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
if (button.dataset.loading === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
button.dataset.loading = "true";
|
||||
button.setAttribute("aria-busy", "true");
|
||||
|
||||
try {
|
||||
await this.switchProfile(entry.pubkey);
|
||||
} catch (error) {
|
||||
console.error("Failed to switch profile:", error);
|
||||
} finally {
|
||||
button.dataset.loading = "false";
|
||||
button.setAttribute("aria-busy", "false");
|
||||
}
|
||||
};
|
||||
|
||||
button.addEventListener("click", activateProfile);
|
||||
button.addEventListener("keydown", (event) => {
|
||||
const key = event?.key;
|
||||
if (key === "Enter" || key === " " || key === "Spacebar") {
|
||||
activateProfile(event);
|
||||
}
|
||||
});
|
||||
|
||||
listEl.appendChild(button);
|
||||
});
|
||||
}
|
||||
@@ -5912,6 +5943,65 @@ class bitvidApp {
|
||||
this.renderSavedProfiles();
|
||||
}
|
||||
|
||||
async switchProfile(pubkey) {
|
||||
const normalizedTarget = this.normalizeHexPubkey(pubkey);
|
||||
if (!normalizedTarget) {
|
||||
this.showError("Unable to switch profiles: invalid account.");
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedActive = this.normalizeHexPubkey(this.activeProfilePubkey);
|
||||
if (normalizedActive && normalizedActive === normalizedTarget) {
|
||||
this.hideProfileModal();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await nostrClient.login({
|
||||
allowAccountSelection: true,
|
||||
expectPubkey: normalizedTarget,
|
||||
});
|
||||
} catch (error) {
|
||||
const message =
|
||||
error && typeof error.message === "string" && error.message.trim()
|
||||
? error.message.trim()
|
||||
: "Profile switch was cancelled.";
|
||||
this.showError(message);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.login(normalizedTarget, { persistActive: true });
|
||||
} catch (error) {
|
||||
console.error("Failed to finalize profile switch:", error);
|
||||
const message =
|
||||
error && typeof error.message === "string" && error.message.trim()
|
||||
? error.message.trim()
|
||||
: "Failed to switch profiles. Please try again.";
|
||||
this.showError(message);
|
||||
return;
|
||||
}
|
||||
|
||||
this.profileSwitcherSelectionPubkey = null;
|
||||
|
||||
let reordered = false;
|
||||
const currentIndex = this.savedProfiles.findIndex(
|
||||
(entry) => this.normalizeHexPubkey(entry.pubkey) === normalizedTarget
|
||||
);
|
||||
if (currentIndex > 0) {
|
||||
const [moved] = this.savedProfiles.splice(currentIndex, 1);
|
||||
this.savedProfiles.unshift(moved);
|
||||
reordered = true;
|
||||
}
|
||||
|
||||
if (reordered) {
|
||||
this.persistSavedProfiles({ persistActive: true });
|
||||
}
|
||||
|
||||
this.renderSavedProfiles();
|
||||
this.hideProfileModal();
|
||||
}
|
||||
|
||||
async applyPostLoginState() {
|
||||
await this.refreshAdminPaneState();
|
||||
|
||||
|
||||
Reference in new issue
Block a user