Add subscription tiers and responsive navigation

This commit is contained in:
nachbaisabel committed 2026-06-13 18:14:56 +02:00
1 parent 289f7eebbe
commit de1d3d2d63
24 files changed
+1290 -602

No files matched your search

+125 -4
View File
@@ -58,11 +58,22 @@
class="login-button"
onclick="location.href = 'settings.html'"
>
<i class="bi bi-gear"></i>
Edit Profile
</button>
<button id="shareProfileButton" class="login-button">
<i class="bi bi-share"></i>
Share Profile
</button>
<a
id="manageTiersButton"
class="login-button"
href="subscription-tiers.html"
>
<i class="bi bi-gem"></i>
Manage Tiers
</a>
<div id="creatorTierList"></div>
</div>
</section>
@@ -145,6 +156,8 @@
"primaryProfileButton",
);
const shareProfileButton = document.getElementById("shareProfileButton");
const manageTiersButton = document.getElementById("manageTiersButton");
const creatorTierList = document.getElementById("creatorTierList");
const profileTabs = document.querySelector(".profile-tabs");
const params = new URLSearchParams(location.search);
const profileId = params.get("id");
@@ -156,6 +169,8 @@
let isOwnProfile = !profileId;
let profileLoaded = false;
let currentIsFollowing = false;
let currentSubscriptionTier = null;
let creatorSubscriptionTiers = [];
async function fetchJson(url) {
const response = await fetch(url, { credentials: "same-origin" });
@@ -332,17 +347,21 @@
function updateProfileMode() {
if (isOwnProfile) {
profileActions.style.display = "flex";
primaryProfileButton.textContent = "Edit Profile";
primaryProfileButton.innerHTML = '<i class="bi bi-gear"></i> Edit Profile';
primaryProfileButton.disabled = false;
primaryProfileButton.onclick = () =>
(location.href = "settings.html");
manageTiersButton.style.display = "flex";
profileTabs.style.display = "flex";
return;
}
profileActions.style.display = "flex";
manageTiersButton.style.display = "none";
primaryProfileButton.textContent = currentIsFollowing
? "Following"
? currentSubscriptionTier
? `Subscribed: ${currentSubscriptionTier.name}`
: "Following"
: "Follow";
primaryProfileButton.disabled = false;
primaryProfileButton.onclick = toggleProfileFollow;
@@ -350,6 +369,45 @@
savedTab.style.display = "none";
myPromptsTab.textContent = `Prompts (${profilePrompts.length})`;
renderPromptList(profilePrompts, "No prompts yet.");
renderCreatorTiers();
}
function renderCreatorTiers() {
if (isOwnProfile) {
creatorTierList.innerHTML = "";
return;
}
if (!creatorSubscriptionTiers.length) {
creatorTierList.innerHTML = "";
return;
}
creatorTierList.innerHTML = `
<div class="profile-tier-list">
<h3>Subscription Tiers</h3>
${creatorSubscriptionTiers
.map(
(tier) => `
<button type="button" class="profile-tier-option ${currentSubscriptionTier?.level === tier.level ? "active" : ""}" data-tier-level="${tier.level}">
<span>
<strong>${tier.name}</strong>
<small>Level ${tier.level}</small>
</span>
<b>$${Number(tier.monthlyPrice || 0).toFixed(2)}/mo</b>
</button>
`,
)
.join("")}
</div>`;
creatorTierList
.querySelectorAll("[data-tier-level]")
.forEach((button) => {
button.addEventListener("click", () =>
subscribeToTier(Number(button.dataset.tierLevel)),
);
});
}
async function loadFollowState() {
@@ -369,9 +427,33 @@
const subscription = response.ok ? await response.json() : null;
currentIsFollowing = subscription !== null;
currentSubscriptionTier = subscription?.currentTier || null;
updateProfileMode();
} catch {
currentIsFollowing = false;
currentSubscriptionTier = null;
}
}
async function loadCreatorTiers() {
if (isOwnProfile || !profileId) return;
try {
const response = await fetch(
`/api/v1/subscriptions/tiers/${encodeURIComponent(profileId)}`,
{
credentials: "same-origin",
},
);
if (response.status === 401) {
location.href = "/login";
return;
}
if (!response.ok) return;
creatorSubscriptionTiers = await response.json();
renderCreatorTiers();
} catch {
creatorSubscriptionTiers = [];
}
}
@@ -397,6 +479,7 @@
profileSubscribers.textContent || 0,
);
currentIsFollowing = !currentIsFollowing;
if (!currentIsFollowing) currentSubscriptionTier = null;
profileSubscribers.textContent = Math.max(
0,
currentSubscribers + (currentIsFollowing ? 1 : -1),
@@ -407,6 +490,43 @@
}
}
async function subscribeToTier(level) {
if (!profileId) return;
creatorTierList
.querySelectorAll("button")
.forEach((button) => (button.disabled = true));
const response = await fetch(
`/api/v1/subscriptions/${encodeURIComponent(profileId)}/${level}`,
{
method: "PUT",
credentials: "same-origin",
},
);
if (response.status === 401) {
location.href = "/login";
return;
}
creatorTierList
.querySelectorAll("button")
.forEach((button) => (button.disabled = false));
if (!response.ok) return;
const wasFollowing = currentIsFollowing;
currentIsFollowing = true;
currentSubscriptionTier =
creatorSubscriptionTiers.find((tier) => tier.level === level) || null;
if (!wasFollowing) {
profileSubscribers.textContent =
Number(profileSubscribers.textContent || 0) + 1;
}
updateProfileMode();
}
shareProfileButton.addEventListener("click", async () => {
const url = isOwnProfile
? `${location.origin}/profile.html`
@@ -414,9 +534,9 @@
try {
await navigator.clipboard.writeText(url);
shareProfileButton.textContent = "Copied";
shareProfileButton.innerHTML = '<i class="bi bi-check2"></i> Copied';
setTimeout(
() => (shareProfileButton.textContent = "Share Profile"),
() => (shareProfileButton.innerHTML = '<i class="bi bi-share"></i> Share Profile'),
1200,
);
} catch {
@@ -475,6 +595,7 @@
await loadProfile();
await loadCreatorCardFallback();
await loadFollowState();
await loadCreatorTiers();
updateProfileMode();
if (isOwnProfile) {
loadOwnPrompts();