mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-28 00:12:25 +00:00
Merge pull request #674 from PR0M3TH3AN/codex/add-notification-for-unauthenticated-users-uxlfqu
Ensure zap controls notify logged-out users to log in
This commit is contained in:
4 files changed
+51
-24
No files matched your search
@@ -7351,6 +7351,29 @@ class Application {
|
||||
return;
|
||||
}
|
||||
|
||||
const { autoHideMs, showSpinner } =
|
||||
options && typeof options === "object" ? options : Object.create(null);
|
||||
|
||||
const shouldShowSpinner = showSpinner !== false;
|
||||
const existingSpinner = container.querySelector(".status-spinner");
|
||||
|
||||
if (shouldShowSpinner) {
|
||||
if (!(existingSpinner instanceof HTMLElementCtor)) {
|
||||
const spinner = ownerDocument?.createElement?.("span") || null;
|
||||
if (spinner) {
|
||||
spinner.className = "status-spinner";
|
||||
spinner.setAttribute("aria-hidden", "true");
|
||||
if (messageTarget && container.contains(messageTarget)) {
|
||||
container.insertBefore(spinner, messageTarget);
|
||||
} else {
|
||||
container.insertBefore(spinner, container.firstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (existingSpinner instanceof HTMLElementCtor) {
|
||||
existingSpinner.remove();
|
||||
}
|
||||
|
||||
if (!msg) {
|
||||
if (messageTarget && messageTarget instanceof HTMLElementCtor) {
|
||||
messageTarget.textContent = "";
|
||||
@@ -7360,9 +7383,6 @@ class Application {
|
||||
return;
|
||||
}
|
||||
|
||||
const { autoHideMs } =
|
||||
options && typeof options === "object" ? options : Object.create(null);
|
||||
|
||||
if (messageTarget && messageTarget instanceof HTMLElementCtor) {
|
||||
messageTarget.textContent = msg;
|
||||
} else {
|
||||
|
||||
@@ -506,10 +506,7 @@ function setChannelZapVisibility(visible) {
|
||||
typeof app?.isUserLoggedIn === "function"
|
||||
? app.isUserLoggedIn()
|
||||
: Boolean(app?.normalizeHexPubkey?.(app?.pubkey));
|
||||
const sessionActorPubkey = getSessionActorPubkey();
|
||||
const hasSessionActor = sessionActorPubkey.length > 0;
|
||||
const sessionOnly = !isLoggedIn && hasSessionActor;
|
||||
const shouldShow = !!visible && (isLoggedIn || sessionOnly);
|
||||
const shouldShow = !!visible;
|
||||
const requiresLogin = shouldShow && !isLoggedIn;
|
||||
|
||||
if (
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { getApplication } from "../applicationContext.js";
|
||||
import { LOGIN_TO_ZAP_MESSAGE } from "./zapMessages.js";
|
||||
|
||||
const LOGIN_NOTIFICATION_AUTO_HIDE_MS = 5000;
|
||||
const LOGIN_NOTIFICATION_AUTO_HIDE_MS = 3000;
|
||||
|
||||
function getOwnerDocument(node) {
|
||||
return node?.ownerDocument || null;
|
||||
@@ -38,12 +38,12 @@ function isNotificationBannerActive({
|
||||
return text === expectedText;
|
||||
}
|
||||
|
||||
function attemptStatusBanner(app, { autoHideMs, expectedText }) {
|
||||
function attemptStatusBanner(app, { autoHideMs, expectedText, showSpinner }) {
|
||||
if (!app || typeof app.showStatus !== "function") {
|
||||
return false;
|
||||
}
|
||||
|
||||
app.showStatus(expectedText, { autoHideMs });
|
||||
app.showStatus(expectedText, { autoHideMs, showSpinner });
|
||||
|
||||
return isNotificationBannerActive({
|
||||
container: app.statusContainer,
|
||||
@@ -108,7 +108,12 @@ function ensureNotificationPortal({ doc, HTMLElementCtor }) {
|
||||
return portal instanceof HTMLElementCtor ? portal : null;
|
||||
}
|
||||
|
||||
function ensureStatusContainer({ doc, portal, HTMLElementCtor }) {
|
||||
function ensureStatusContainer({
|
||||
doc,
|
||||
portal,
|
||||
HTMLElementCtor,
|
||||
includeSpinner = true,
|
||||
}) {
|
||||
if (!doc || !HTMLElementCtor) {
|
||||
return { container: null, messageTarget: null };
|
||||
}
|
||||
@@ -123,10 +128,12 @@ function ensureStatusContainer({ doc, portal, HTMLElementCtor }) {
|
||||
statusContainer.setAttribute("role", "status");
|
||||
statusContainer.setAttribute("aria-live", "polite");
|
||||
|
||||
const spinner = doc.createElement("span");
|
||||
spinner.className = "status-spinner";
|
||||
spinner.setAttribute("aria-hidden", "true");
|
||||
statusContainer.appendChild(spinner);
|
||||
if (includeSpinner) {
|
||||
const spinner = doc.createElement("span");
|
||||
spinner.className = "status-spinner";
|
||||
spinner.setAttribute("aria-hidden", "true");
|
||||
statusContainer.appendChild(spinner);
|
||||
}
|
||||
|
||||
const message = doc.createElement("span");
|
||||
message.className = "status-message";
|
||||
@@ -134,11 +141,15 @@ function ensureStatusContainer({ doc, portal, HTMLElementCtor }) {
|
||||
statusContainer.appendChild(message);
|
||||
} else {
|
||||
const existingSpinner = statusContainer.querySelector(".status-spinner");
|
||||
if (!(existingSpinner instanceof HTMLElementCtor)) {
|
||||
const spinner = doc.createElement("span");
|
||||
spinner.className = "status-spinner";
|
||||
spinner.setAttribute("aria-hidden", "true");
|
||||
statusContainer.insertBefore(spinner, statusContainer.firstChild);
|
||||
if (includeSpinner) {
|
||||
if (!(existingSpinner instanceof HTMLElementCtor)) {
|
||||
const spinner = doc.createElement("span");
|
||||
spinner.className = "status-spinner";
|
||||
spinner.setAttribute("aria-hidden", "true");
|
||||
statusContainer.insertBefore(spinner, statusContainer.firstChild);
|
||||
}
|
||||
} else if (existingSpinner instanceof HTMLElementCtor) {
|
||||
existingSpinner.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +286,7 @@ export function showLoginRequiredToZapNotification({
|
||||
getOwnerDocument(app?.statusContainer) ||
|
||||
getOwnerDocument(app?.errorContainer);
|
||||
|
||||
if (attemptStatusBanner(app, { autoHideMs, expectedText })) {
|
||||
if (attemptStatusBanner(app, { autoHideMs, expectedText, showSpinner: false })) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -299,6 +310,7 @@ export function showLoginRequiredToZapNotification({
|
||||
doc,
|
||||
portal,
|
||||
HTMLElementCtor,
|
||||
includeSpinner: false,
|
||||
});
|
||||
|
||||
if (statusContainer instanceof HTMLElementCtor) {
|
||||
|
||||
@@ -97,9 +97,7 @@ export default class ZapController {
|
||||
setVisibility(visible) {
|
||||
const lightningVisible = !!visible;
|
||||
const loggedIn = this.isUserLoggedIn();
|
||||
const sessionActorAvailable = this.hasSessionActor();
|
||||
const shouldShow =
|
||||
lightningVisible && (loggedIn || sessionActorAvailable);
|
||||
const shouldShow = lightningVisible;
|
||||
const requiresLogin = shouldShow && !loggedIn;
|
||||
const hasWallet = this.hasActiveWalletConnection();
|
||||
if (this.videoModal) {
|
||||
|
||||
Reference in new issue
Block a user