Add prompt marketplace interactions and profile prompt tabs
This commit is contained in:
1 parent
691bc72681
commit
c95319b1fe
20 files changed
+734
-146
No files matched your search
@@ -90,6 +90,9 @@
|
||||
<option value="date|true">Oldest</option>
|
||||
<option value="rating|false">Best Rating</option>
|
||||
<option value="rating|true">Lowest Rating</option>
|
||||
<option value="free|true">Free</option>
|
||||
<option value="price|true">Lowest Price</option>
|
||||
<option value="price|false">Highest Price</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -391,9 +394,36 @@
|
||||
return `<span class="prompt-rating"><span style="color:#f59e0b">${"★".repeat(stars)}${"☆".repeat(5 - stars)}</span> ${rating.toFixed(1)}</span>`;
|
||||
}
|
||||
|
||||
function tierPrice(level) {
|
||||
if (!level) return "Free";
|
||||
return `$${(level * 4.99).toFixed(2)}/mo`;
|
||||
function promptPrice(prompt) {
|
||||
if (prompt.price != null && Number(prompt.price) > 0) {
|
||||
return `$${Number(prompt.price).toFixed(2)}`;
|
||||
}
|
||||
if (prompt.tierLevel) return `$${(prompt.tierLevel * 4.99).toFixed(2)}/mo`;
|
||||
if (prompt.canAccess === false) return "Paid";
|
||||
return "Free";
|
||||
}
|
||||
|
||||
function getNumericPrice(prompt) {
|
||||
if (prompt.price != null && Number(prompt.price) > 0) {
|
||||
return Number(prompt.price);
|
||||
}
|
||||
if (prompt.tierLevel) return prompt.tierLevel * 4.99;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function applyMarketplaceSort(prompts, sortBy, ascending) {
|
||||
if (sortBy === "free") {
|
||||
return prompts.filter((prompt) => getNumericPrice(prompt) === 0);
|
||||
}
|
||||
|
||||
if (sortBy === "price") {
|
||||
const direction = ascending === "true" ? 1 : -1;
|
||||
return prompts
|
||||
.slice()
|
||||
.sort((a, b) => (getNumericPrice(a) - getNumericPrice(b)) * direction);
|
||||
}
|
||||
|
||||
return prompts;
|
||||
}
|
||||
|
||||
const MARKET_IMAGES = [
|
||||
@@ -407,7 +437,8 @@
|
||||
let cardIndex = 0;
|
||||
|
||||
function renderCard(p) {
|
||||
const locked = !p.canAccess && p.tierLevel != null;
|
||||
const paid = p.price != null && Number(p.price) > 0;
|
||||
const locked = p.canAccess === false || paid || p.tierLevel != null;
|
||||
const img = p.exampleImageUrl || p._img || MARKET_IMAGES[cardIndex++ % MARKET_IMAGES.length];
|
||||
return `
|
||||
<div class="prompt-card">
|
||||
@@ -419,16 +450,19 @@
|
||||
<span style="margin-left:auto;font-size:0.75rem;color:#94a3b8;">${timeAgo(p.timeStamp)}</span>
|
||||
</div>
|
||||
<h3 class="prompt-title">${p.title}</h3>
|
||||
${p.tierName ? `<span style="display:inline-block;background:#f1f5f9;color:#475569;border-radius:20px;padding:2px 10px;font-size:0.75rem;margin-bottom:8px;"><i class="bi bi-lock-fill"></i> ${p.tierName}</span>` : '<span style="display:inline-block;background:#dcfce7;color:#166534;border-radius:20px;padding:2px 10px;font-size:0.75rem;margin-bottom:8px;">Free</span>'}
|
||||
<div style="margin-bottom:12px;">${renderStars(p.averageRating)}</div>
|
||||
<div class="prompt-price">${tierPrice(p.tierLevel)}</div>
|
||||
<div class="prompt-price">${promptPrice(p)}</div>
|
||||
<div class="prompt-actions">
|
||||
${
|
||||
locked
|
||||
? `<button class="buy-btn" onclick='openPayment(${JSON.stringify(p)})'>Subscribe</button>`
|
||||
? `<button class="buy-btn" style="background:#ef4444;" onclick='openPayment(${JSON.stringify(p)})'><i class="bi bi-lock-fill"></i> Pay</button>`
|
||||
: `<button class="buy-btn" style="background:#10b981;" onclick="location.href='/post-detail?id=${p.id}'">Access <i class="bi bi-unlock-fill"></i></button>`
|
||||
}
|
||||
<button class="details-btn" onclick="location.href='/post-detail?id=${p.id}'">View Details</button>
|
||||
${
|
||||
locked
|
||||
? `<button class="details-btn" disabled style="opacity:.45;cursor:not-allowed;"><i class="bi bi-lock-fill"></i> Details</button>`
|
||||
: `<button class="details-btn" onclick="location.href='/post-detail?id=${p.id}'">View Details</button>`
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
@@ -447,74 +481,11 @@
|
||||
emptyEl.style.display = "none";
|
||||
errorEl.style.display = "none";
|
||||
cardIndex = 0;
|
||||
const DEMO_PROMPTS = [
|
||||
{
|
||||
id: "demo-1",
|
||||
title: "Creative Blog Post Generator",
|
||||
creatorName: "JaneDoe",
|
||||
timeStamp: new Date(Date.now() - 7200000).toISOString(),
|
||||
tierLevel: null,
|
||||
tierName: null,
|
||||
averageRating: 4.8,
|
||||
canAccess: true,
|
||||
},
|
||||
{
|
||||
id: "demo-2",
|
||||
title: "Python Code Assistant",
|
||||
creatorName: "AlexDev",
|
||||
timeStamp: new Date(Date.now() - 86400000).toISOString(),
|
||||
tierLevel: 1,
|
||||
tierName: "Basic",
|
||||
averageRating: 4.7,
|
||||
canAccess: false,
|
||||
},
|
||||
{
|
||||
id: "demo-3",
|
||||
title: "Digital Art Style Guide",
|
||||
creatorName: "MiaArt",
|
||||
timeStamp: new Date(Date.now() - 172800000).toISOString(),
|
||||
tierLevel: 2,
|
||||
tierName: "Pro",
|
||||
averageRating: 4.9,
|
||||
canAccess: false,
|
||||
},
|
||||
{
|
||||
id: "demo-4",
|
||||
title: "Marketing Copywriter",
|
||||
creatorName: "TomCopy",
|
||||
timeStamp: new Date(Date.now() - 259200000).toISOString(),
|
||||
tierLevel: null,
|
||||
tierName: null,
|
||||
averageRating: 4.6,
|
||||
canAccess: true,
|
||||
},
|
||||
{
|
||||
id: "demo-5",
|
||||
title: "Midjourney Image Prompts",
|
||||
creatorName: "SarahViz",
|
||||
timeStamp: new Date(Date.now() - 432000000).toISOString(),
|
||||
tierLevel: 1,
|
||||
tierName: "Basic",
|
||||
averageRating: 4.7,
|
||||
canAccess: false,
|
||||
},
|
||||
{
|
||||
id: "demo-6",
|
||||
title: "UI Design Assistant",
|
||||
creatorName: "LilyUI",
|
||||
timeStamp: new Date(Date.now() - 604800000).toISOString(),
|
||||
tierLevel: 3,
|
||||
tierName: "Premium",
|
||||
averageRating: 4.9,
|
||||
canAccess: false,
|
||||
_img: "/images/content/market6.png",
|
||||
},
|
||||
];
|
||||
// pre-assign images to demo prompts
|
||||
DEMO_PROMPTS.forEach((p, i) => (p._img = MARKET_IMAGES[i]));
|
||||
|
||||
try {
|
||||
let url = `/api/v1/prompts?sortBy=${sortBy}&ascending=${ascending}&limit=50`;
|
||||
const apiSortBy = sortBy === "price" || sortBy === "free" ? "date" : sortBy;
|
||||
const apiAscending = sortBy === "price" || sortBy === "free" ? "false" : ascending;
|
||||
let url = `/api/v1/prompts?sortBy=${apiSortBy}&ascending=${apiAscending}&limit=50`;
|
||||
if (activeCategory) url += `&category=${activeCategory}`;
|
||||
if (search) url += `&search=${encodeURIComponent(search)}`;
|
||||
|
||||
@@ -525,15 +496,7 @@
|
||||
}
|
||||
if (!res.ok) throw new Error(`Server error ${res.status}`);
|
||||
|
||||
let prompts = await res.json();
|
||||
|
||||
// If API is empty and no filters active, show demo content
|
||||
if (prompts.length === 0 && !activeCategory && !search) {
|
||||
grid.innerHTML =
|
||||
`<div style="grid-column:1/-1;text-align:center;padding:8px 0 20px;color:#94a3b8;font-size:0.85rem;"><i class="bi bi-info-circle"></i> Showing example prompts — no real prompts yet.</div>` +
|
||||
DEMO_PROMPTS.map(renderCard).join("");
|
||||
return;
|
||||
}
|
||||
let prompts = applyMarketplaceSort(await res.json(), sortBy, ascending);
|
||||
|
||||
if (prompts.length === 0) {
|
||||
emptyEl.style.display = "block";
|
||||
@@ -541,10 +504,9 @@
|
||||
}
|
||||
grid.innerHTML = prompts.map(renderCard).join("");
|
||||
} catch (e) {
|
||||
// On error, show demo content as fallback
|
||||
grid.innerHTML =
|
||||
`<div style="grid-column:1/-1;text-align:center;padding:8px 0 20px;color:#94a3b8;font-size:0.85rem;"><i class="bi bi-wifi-off"></i> Could not connect to server — showing demo content.</div>` +
|
||||
DEMO_PROMPTS.map(renderCard).join("");
|
||||
document.getElementById("market-error-msg").textContent =
|
||||
e.message || "Please check if the backend is running.";
|
||||
errorEl.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,7 +585,9 @@
|
||||
|
||||
function openPayment(prompt) {
|
||||
currentPrompt = prompt;
|
||||
const usd = prompt.tierLevel ? prompt.tierLevel * 4.99 : 0;
|
||||
const usd = prompt.price != null && Number(prompt.price) > 0
|
||||
? Number(prompt.price)
|
||||
: prompt.tierLevel ? prompt.tierLevel * 4.99 : 0;
|
||||
document.getElementById("pay-prompt-title").textContent = prompt.title;
|
||||
document.getElementById("price-btc").textContent =
|
||||
`≈ ${(usd / 67000).toFixed(6)} BTC`;
|
||||
|
||||
Reference in new issue
Block a user