Add subscription tiers and responsive navigation
This commit is contained in:
1 parent
289f7eebbe
commit
de1d3d2d63
24 files changed
+1290
-602
No files matched your search
@@ -238,10 +238,11 @@
|
||||
|
||||
// Tier badge
|
||||
const badge = document.getElementById("tier-badge");
|
||||
if (p.price != null && Number(p.price) > 0) {
|
||||
badge.innerHTML = `<span class="tier-badge-paid">$${Number(p.price).toFixed(2)}</span>`;
|
||||
} else if (p.tierName) {
|
||||
badge.innerHTML = `<span class="tier-badge-tier"><i class="bi bi-lock-fill"></i> ${p.tierName}</span>`;
|
||||
if (p.tierName) {
|
||||
const price = p.tierMonthlyPrice == null
|
||||
? ""
|
||||
: ` - $${Number(p.tierMonthlyPrice).toFixed(2)}/mo`;
|
||||
badge.innerHTML = `<span class="tier-badge-tier"><i class="bi bi-lock-fill"></i> ${p.tierName}${price}</span>`;
|
||||
} else {
|
||||
badge.innerHTML = `<span class="tier-badge-free">Free</span>`;
|
||||
}
|
||||
@@ -275,6 +276,7 @@
|
||||
document.getElementById("locked-tier-name").textContent = p.tierName
|
||||
? `— ${p.tierName}`
|
||||
: "";
|
||||
setupLockedSubscription(p);
|
||||
}
|
||||
|
||||
document.getElementById("detail-loading").style.display = "none";
|
||||
@@ -282,6 +284,38 @@
|
||||
scrollToHashSection();
|
||||
}
|
||||
|
||||
function setupLockedSubscription(prompt) {
|
||||
const button = document.getElementById("locked-subscribe-btn");
|
||||
if (!button) return;
|
||||
|
||||
button.disabled = prompt.tierLevel == null;
|
||||
button.onclick = async () => {
|
||||
if (prompt.tierLevel == null) return;
|
||||
|
||||
button.disabled = true;
|
||||
button.textContent = "Subscribing...";
|
||||
const response = await fetch(
|
||||
`/api/v1/subscriptions/${encodeURIComponent(prompt.creatorId)}/${prompt.tierLevel}`,
|
||||
{
|
||||
method: "PUT",
|
||||
credentials: "same-origin",
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status === 401) {
|
||||
location.href = "/login";
|
||||
return;
|
||||
}
|
||||
if (!response.ok) {
|
||||
button.disabled = false;
|
||||
button.textContent = await response.text();
|
||||
return;
|
||||
}
|
||||
|
||||
location.reload();
|
||||
};
|
||||
}
|
||||
|
||||
function scrollToHashSection() {
|
||||
if (!location.hash) return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user