BeatFridge / dashboard.html
Onttraders's picture
🐳 14/04 - 17:11 - Increase creator uploads.Add onboarding flow:When a creator signs up:- Show:   “Upload your first beat and start earning today”Add incentives:- “Top creators this week”- “Earn your
de20df8 verified
Raw History Blame Contribute Delete
52.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Creator Dashboard - BeatFridge</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="responsive.css">
<style>
* { font-family: 'Inter', sans-serif; }
body { background-color: #0a0a0a; color: #ffffff; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #2d2d2d; border-radius: 4px; }
.glass { background: rgba(20,20,20,0.6); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.08); }
.glass-panel { background: rgba(30,30,30,0.4); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,0.05); }
.neon-text { background: linear-gradient(135deg, #00d4ff 0%, #7c3aed 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.glow-cyan { box-shadow: 0 0 20px rgba(0,212,255,0.3); }
.glow-green { box-shadow: 0 0 20px rgba(34,197,94,0.25); }
.sticky-player { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; }
.avatar-ring { box-shadow: 0 0 0 4px #0a0a0a, 0 0 0 6px rgba(0,212,255,0.5); }
.stat-card { background: linear-gradient(135deg, rgba(20,20,20,0.8) 0%, rgba(30,30,30,0.6) 100%); }
.chart-bar-wrap { display: flex; align-items: flex-end; gap: 6px; height: 160px; }
.chart-bar { flex: 1; border-radius: 4px 4px 0 0; min-width: 24px; transition: height 0.6s cubic-bezier(0.4,0,0.2,1); position: relative; cursor: pointer; }
.chart-bar:hover { filter: brightness(1.2); }
.chart-bar .tooltip { position: absolute; top: -28px; left: 50%; transform: translateX(-50%); background: #1a1a1a; border: 1px solid rgba(255,255,255,0.1); padding: 3px 8px; border-radius: 6px; font-size: 11px; white-space: nowrap; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.chart-bar:hover .tooltip { opacity: 1; }
.track-row { transition: background 0.15s; }
.track-row:hover { background: rgba(255,255,255,0.03); }
.action-icon { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; cursor: pointer; border: none; }
.action-icon:hover { transform: scale(1.1); }
.action-icon.edit { background: rgba(0,212,255,0.1); color: #00d4ff; }
.action-icon.edit:hover { background: rgba(0,212,255,0.2); }
.action-icon.delete { background: rgba(239,68,68,0.1); color: #ef4444; }
.action-icon.delete:hover { background: rgba(239,68,68,0.2); }
.action-icon.perf { background: rgba(168,85,247,0.1); color: #a855f7; }
.action-icon.perf:hover { background: rgba(168,85,247,0.2); }
.bf-input { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem; color: white; outline: none; transition: border-color 0.2s; }
.bf-input:focus { border-color: rgba(0,212,255,0.5); }
.bf-input::placeholder { color: #4b5563; }
.bf-select { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem; color: white; outline: none; transition: border-color 0.2s; -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; }
.bf-select:focus { border-color: rgba(0,212,255,0.5); }
.bf-select option { background: #1a1a1a; color: white; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(8px); z-index: 70; }
.modal-card { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 71; width: calc(100% - 2rem); max-width: 520px; max-height: 85vh; overflow-y: auto; background: #111; border: 1px solid rgba(255,255,255,0.1); border-radius: 1rem; padding: 1.5rem; }
.perf-bar { height: 8px; border-radius: 4px; transition: width 0.5s cubic-bezier(0.4,0,0.2,1); }
.mini-chart-bar { border-radius: 3px 3px 0 0; transition: height 0.4s ease; }
.trend-up { color: #22c55e; }
.trend-down { color: #ef4444; }
.toggle-track { transition: background 0.2s ease; }
.toggle-thumb { transition: transform 0.2s ease; }
</style>
</head>
<body class="bg-black text-white overflow-x-hidden pb-24">
<!-- Navigation -->
<nav class="fixed top-0 left-0 right-0 z-40 glass border-b border-white/5">
<div class="max-w-[1600px] mx-auto px-4 sm:px-6 h-14 flex items-center justify-between">
<div class="flex items-center gap-6">
<a href="index.html" class="flex items-center gap-2">
<div class="w-8 h-8 rounded-lg flex items-center justify-center bg-white/10 border border-white/20">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-5 h-5 text-white"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="4" y1="9" x2="20" y2="9"/><line x1="15" y1="5" x2="15" y2="7"/><line x1="15" y1="12" x2="15" y2="18"/></svg>
</div>
<span class="text-lg font-bold tracking-tight hidden sm:inline">BeatFridge</span>
</a>
<div class="hidden md:flex items-center gap-5 text-sm font-medium text-gray-400">
<a href="index.html" class="hover:text-cyan-400 transition">Home</a>
<a href="dashboard.html" class="text-cyan-400 flex items-center gap-1"><i data-lucide="layout-dashboard" class="w-4 h-4"></i>Dashboard</a>
<a href="upload.html" class="hover:text-cyan-400 transition flex items-center gap-1"><i data-lucide="upload-cloud" class="w-4 h-4"></i>Upload</a>
<a href="library.html" class="hover:text-cyan-400 transition">Library</a>
<a href="analytics.html" class="hover:text-cyan-400 transition flex items-center gap-1"><i data-lucide="bar-chart-2" class="w-4 h-4"></i>Analytics</a>
</div>
</div>
<div class="flex items-center gap-3">
<button id="mobileMenuBtn" class="md:hidden w-9 h-9 rounded-full bg-white/5 border border-white/10 flex items-center justify-center hover:bg-white/10 transition" onclick="toggleMobileMenu()">
<i data-lucide="menu" class="w-4 h-4 text-gray-300"></i>
</button>
<div class="w-9 h-9 rounded-full bg-gradient-to-br from-cyan-400 to-purple-600 cursor-pointer hover:scale-105 transition avatar-ring overflow-hidden" onclick="BF.isLoggedIn() ? window.location.href='profile.html' : BF.showSignInModal()">
<img id="topNavAvatar" src="http://static.photos/people/200x200/42" alt="Profile" class="w-full h-full rounded-full object-cover">
</div>
</div>
</div>
</nav>
<!-- Mobile Nav Overlay -->
<div id="mobileNavOverlay" class="mobile-nav-overlay" onclick="closeMobileMenu()"></div>
<div id="mobileNavPanel" class="mobile-nav-panel">
<div class="flex items-center justify-between mb-8">
<a href="index.html" class="flex items-center gap-2 hover:opacity-80 transition">
<div class="w-8 h-8 rounded-lg flex items-center justify-center bg-white/10 border border-white/20">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-5 h-5 text-white"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="4" y1="9" x2="20" y2="9"/><line x1="15" y1="5" x2="15" y2="7"/><line x1="15" y1="12" x2="15" y2="18"/></svg>
</div>
<span class="text-xl font-bold">BeatFridge</span>
</a>
<button onclick="closeMobileMenu()" class="w-10 h-10 rounded-full bg-white/5 border border-white/10 flex items-center justify-center hover:bg-white/10 transition"><i data-lucide="x" class="w-5 h-5"></i></button>
</div>
<nav class="space-y-1">
<a href="index.html" class="flex items-center gap-3 px-4 py-3 rounded-xl hover:bg-white/5 transition text-gray-300 hover:text-white"><i data-lucide="home" class="w-5 h-5"></i> Home</a>
<a href="dashboard.html" class="flex items-center gap-3 px-4 py-3 rounded-xl bg-white/5 text-cyan-400 font-medium"><i data-lucide="layout-dashboard" class="w-5 h-5"></i> Dashboard</a>
<a href="upload.html" class="flex items-center gap-3 px-4 py-3 rounded-xl hover:bg-white/5 transition text-gray-300 hover:text-white"><i data-lucide="upload-cloud" class="w-5 h-5"></i> Upload</a>
<a href="library.html" class="flex items-center gap-3 px-4 py-3 rounded-xl hover:bg-white/5 transition text-gray-300 hover:text-white"><i data-lucide="library" class="w-5 h-5"></i> Library</a>
<a href="analytics.html" class="flex items-center gap-3 px-4 py-3 rounded-xl hover:bg-white/5 transition text-gray-300 hover:text-white"><i data-lucide="bar-chart-2" class="w-5 h-5"></i> Analytics</a>
</nav>
</div>
<!-- Not Logged In / Fan Block -->
<div id="accessBlock" class="hidden">
<div class="max-w-xl mx-auto text-center py-20 px-4 pt-28">
<div class="w-20 h-20 rounded-full bg-white/5 flex items-center justify-center mx-auto mb-6">
<i data-lucide="lock" class="w-10 h-10 text-gray-500"></i>
</div>
<h2 class="text-2xl font-bold text-white mb-3">Creator Dashboard</h2>
<p class="text-gray-400 mb-6 max-w-md mx-auto" id="accessMsg">Sign in as a Producer to access your dashboard, track earnings, and manage your music.</p>
<button id="accessCta" onclick="BF.showSignInModal()" class="px-6 py-3 bg-cyan-500 hover:bg-cyan-400 text-black font-semibold rounded-full transition glow-cyan">Sign In</button>
</div>
</div>
<!-- Main Dashboard -->
<main id="dashboardMain" class="hidden max-w-[1400px] mx-auto pt-20 pb-12 px-4 sm:px-6 min-h-screen">
<!-- Header -->
<div class="flex flex-col sm:flex-row sm:items-end justify-between gap-4 mb-8">
<div>
<h1 class="text-2xl sm:text-3xl font-bold flex items-center gap-3">
<div class="w-10 h-10 rounded-xl bg-gradient-to-br from-green-500/20 to-cyan-500/20 flex items-center justify-center border border-green-500/20">
<i data-lucide="layout-dashboard" class="w-5 h-5 text-green-400"></i>
</div>
Creator Dashboard
</h1>
<p class="text-gray-500 text-sm mt-1">Welcome back, <span id="dashUsername" class="text-white font-medium">@username</span></p>
</div>
<div class="flex items-center gap-3">
<select id="dashRange" class="bg-white/5 border border-white/10 rounded-xl px-4 py-2 text-sm text-white focus:outline-none focus:border-cyan-500/50" onchange="refreshDashboard()">
<option value="7">Last 7 days</option>
<option value="30" selected>Last 30 days</option>
<option value="90">Last 90 days</option>
<option value="all">All time</option>
</select>
<a href="upload.html" class="px-4 py-2 bg-cyan-500 hover:bg-cyan-400 text-black font-semibold rounded-xl text-sm transition glow-cyan flex items-center gap-2">
<i data-lucide="plus" class="w-4 h-4"></i>
<span class="hidden sm:inline">New Track</span>
</a>
</div>
</div>
<!-- Stat Cards -->
<div class="grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4 mb-8">
<div class="stat-card glass-panel rounded-2xl p-4 sm:p-5 border border-green-500/10">
<div class="flex items-center gap-2 mb-3">
<div class="w-8 h-8 rounded-lg bg-green-500/15 flex items-center justify-center"><i data-lucide="dollar-sign" class="w-4 h-4 text-green-400"></i></div>
<span class="text-xs text-gray-500 uppercase tracking-wider font-medium">Total Earnings</span>
</div>
<p class="text-2xl sm:text-3xl font-bold text-white" id="statEarnings">$0.00</p>
<p class="text-xs mt-1 trend-up flex items-center gap-1" id="statEarningsTrend"><i data-lucide="trending-up" class="w-3 h-3"></i>+0%</p>
</div>
<div class="stat-card glass-panel rounded-2xl p-4 sm:p-5 border border-cyan-500/10">
<div class="flex items-center gap-2 mb-3">
<div class="w-8 h-8 rounded-lg bg-cyan-500/15 flex items-center justify-center"><i data-lucide="download" class="w-4 h-4 text-cyan-400"></i></div>
<span class="text-xs text-gray-500 uppercase tracking-wider font-medium">Downloads</span>
</div>
<p class="text-2xl sm:text-3xl font-bold text-white" id="statDownloads">0</p>
<p class="text-xs mt-1 text-gray-500" id="statDownloadsSub">0 unlock conversions</p>
</div>
<div class="stat-card glass-panel rounded-2xl p-4 sm:p-5 border border-purple-500/10">
<div class="flex items-center gap-2 mb-3">
<div class="w-8 h-8 rounded-lg bg-purple-500/15 flex items-center justify-center"><i data-lucide="play-circle" class="w-4 h-4 text-purple-400"></i></div>
<span class="text-xs text-gray-500 uppercase tracking-wider font-medium">Total Plays</span>
</div>
<p class="text-2xl sm:text-3xl font-bold text-white" id="statPlays">0</p>
<p class="text-xs mt-1 text-gray-500" id="statPlaysSub">Across all tracks</p>
</div>
<div class="stat-card glass-panel rounded-2xl p-4 sm:p-5 border border-orange-500/10">
<div class="flex items-center gap-2 mb-3">
<div class="w-8 h-8 rounded-lg bg-orange-500/15 flex items-center justify-center"><i data-lucide="percent" class="w-4 h-4 text-orange-400"></i></div>
<span class="text-xs text-gray-500 uppercase tracking-wider font-medium">Conversion</span>
</div>
<p class="text-2xl sm:text-3xl font-bold text-white" id="statConversion">0%</p>
<p class="text-xs mt-1 text-gray-500" id="statConversionSub">Plays → Unlocks</p>
</div>
</div>
<!-- Revenue Chart + Top Tracks -->
<div class="grid grid-cols-1 lg:grid-cols-5 gap-4 sm:gap-6 mb-8">
<!-- Revenue Chart -->
<div class="lg:col-span-3 glass-panel rounded-2xl p-5 sm:p-6">
<div class="flex items-center justify-between mb-5">
<h3 class="font-semibold text-white flex items-center gap-2"><i data-lucide="trending-up" class="w-4 h-4 text-green-400"></i>Monthly Revenue</h3>
<div class="flex gap-2 text-[11px]">
<span class="px-2 py-1 rounded bg-green-500/15 text-green-400 border border-green-500/20">You keep 85%</span>
</div>
</div>
<div class="chart-bar-wrap" id="revenueChart"></div>
<div class="flex justify-between mt-3 text-[10px] text-gray-600" id="revenueLabels"></div>
</div>
<!-- Top Performing Tracks -->
<div class="lg:col-span-2 glass-panel rounded-2xl p-5 sm:p-6">
<h3 class="font-semibold text-white mb-4 flex items-center gap-2"><i data-lucide="trophy" class="w-4 h-4 text-orange-400"></i>Top Tracks</h3>
<div class="space-y-3" id="topTracksList"></div>
</div>
</div>
<!-- My Tracks -->
<div class="glass-panel rounded-2xl p-5 sm:p-6 mb-8">
<div class="flex items-center justify-between mb-5">
<h3 class="font-semibold text-white flex items-center gap-2"><i data-lucide="disc" class="w-4 h-4 text-cyan-400"></i>My Tracks</h3>
<span class="text-xs text-gray-500" id="trackCount">0 tracks</span>
</div>
<div id="myTracksList"></div>
</div>
<!-- Badges & Achievements -->
<div class="glass-panel rounded-2xl p-5 sm:p-6 mb-8" id="badgesSection">
<div class="flex items-center justify-between mb-5">
<h3 class="font-semibold text-white flex items-center gap-2"><i data-lucide="award" class="w-4 h-4 text-orange-400"></i>Badges & Achievements</h3>
<span class="text-xs text-gray-500" id="badgeCount">0 earned</span>
</div>
<div id="badgesList" class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3"></div>
<!-- Onboarding Progress -->
<div id="onboardingProgress" class="mt-5 pt-5 border-t border-white/10 hidden">
<div class="flex items-center justify-between mb-3">
<h4 class="text-sm font-semibold text-gray-300 flex items-center gap-2"><i data-lucide="target" class="w-4 h-4 text-cyan-400"></i>Creator Checklist</h4>
<span class="text-xs text-gray-500" id="checklistProgress">0/4</span>
</div>
<div class="space-y-2" id="checklistSteps"></div>
<div class="mt-3 h-2 bg-white/5 rounded-full overflow-hidden">
<div class="h-full bg-gradient-to-r from-cyan-500 to-orange-500 rounded-full transition-all" id="checklistBar" style="width:0%"></div>
</div>
</div>
</div>
<!-- Recent Transactions -->
<div class="glass-panel rounded-2xl p-5 sm:p-6">
<div class="flex items-center justify-between mb-5">
<h3 class="font-semibold text-white flex items-center gap-2"><i data-lucide="receipt" class="w-4 h-4 text-orange-400"></i>Recent Transactions</h3>
<a href="library.html" class="text-xs text-cyan-400 hover:text-cyan-300 transition">View all</a>
</div>
<div id="transactionsList"></div>
</div>
</main>
<!-- Edit Track Modal -->
<div id="editModal" class="hidden">
<div class="modal-overlay" onclick="closeEditModal()"></div>
<div class="modal-card">
<div class="flex items-center justify-between mb-5">
<h3 class="text-lg font-bold text-white flex items-center gap-2"><i data-lucide="edit-3" class="w-5 h-5 text-cyan-400"></i>Edit Track</h3>
<button onclick="closeEditModal()" class="text-gray-400 hover:text-white transition"><i data-lucide="x" class="w-5 h-5"></i></button>
</div>
<div class="space-y-4">
<div>
<label class="block text-xs font-medium text-gray-400 uppercase tracking-wider mb-2">Title</label>
<input type="text" id="editTitle" class="bf-input">
</div>
<div>
<label class="block text-xs font-medium text-gray-400 uppercase tracking-wider mb-2">Genre</label>
<select id="editGenre" class="bf-select">
<option value="">Select genre</option>
<option value="techno">Techno</option><option value="house">House</option><option value="deep-house">Deep House</option>
<option value="amapiano">Amapiano</option><option value="trap">Trap</option><option value="ambient">Ambient</option>
<option value="synthwave">Synthwave</option><option value="drum-bass">Drum & Bass</option><option value="lo-fi">Lo-Fi</option>
<option value="experimental">Experimental</option><option value="hip-hop">Hip-Hop</option><option value="rnb">R&B</option>
</select>
</div>
<div class="p-4 rounded-xl bg-white/5 border border-white/10">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded-lg bg-orange-500/20 flex items-center justify-center"><i data-lucide="lock" class="w-4 h-4 text-orange-400"></i></div>
<div><p class="text-sm font-medium text-white">Paid Unlock</p><p class="text-[11px] text-gray-500">Listeners pay to download</p></div>
</div>
<button id="editMonetizeToggle" onclick="toggleEditMonetize()" class="relative w-11 h-6 rounded-full toggle-track bg-white/10 flex-shrink-0" role="switch" aria-checked="false">
<div class="toggle-thumb w-4 h-4 rounded-full bg-gray-400 absolute top-1 left-1"></div>
</button>
</div>
<div id="editPriceSection" class="hidden mt-3">
<label class="block text-xs text-gray-500 mb-1">Minimum Price</label>
<div class="relative"><span class="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 text-sm">$</span><input type="number" id="editPrice" value="0.50" min="0.50" step="0.01" class="bf-input pl-7"></div>
</div>
</div>
<div id="editError" class="hidden text-red-400 text-sm"></div>
<div class="flex gap-3 pt-2">
<button onclick="closeEditModal()" class="flex-1 py-3 bg-white/5 hover:bg-white/10 border border-white/10 rounded-xl text-sm font-medium text-gray-400 transition">Cancel</button>
<button onclick="saveEdit()" class="flex-1 py-3 bg-cyan-500 hover:bg-cyan-400 text-black font-semibold rounded-xl transition">Save Changes</button>
</div>
</div>
</div>
</div>
<!-- Performance Modal -->
<div id="perfModal" class="hidden">
<div class="modal-overlay" onclick="closePerfModal()"></div>
<div class="modal-card" style="max-width:560px">
<div class="flex items-center justify-between mb-5">
<h3 class="text-lg font-bold text-white flex items-center gap-2"><i data-lucide="bar-chart-2" class="w-5 h-5 text-purple-400"></i>Track Performance</h3>
<button onclick="closePerfModal()" class="text-gray-400 hover:text-white transition"><i data-lucide="x" class="w-5 h-5"></i></button>
</div>
<div id="perfContent"></div>
</div>
</div>
<!-- Sticky Bottom Player -->
<div class="sticky-player glass border-t border-white/10 px-4 py-3">
<div class="max-w-[1600px] mx-auto flex items-center gap-4">
<div class="flex items-center gap-3 w-48 sm:w-64 flex-shrink-0">
<div class="w-12 h-12 sm:w-14 sm:h-14 rounded-lg overflow-hidden flex-shrink-0"><img id="playerArt" src="http://static.photos/technology/200x200/5" class="w-full h-full object-cover"></div>
<div class="min-w-0 flex-1"><p id="playerTitle" class="text-sm font-medium text-white truncate">Midnight Synthesis</p><p id="playerArtist" class="text-xs text-gray-400 truncate">Aurora Void</p></div>
</div>
<div class="flex-1 flex items-center justify-center max-w-2xl mx-auto">
<button class="w-10 h-10 rounded-full bg-white text-black flex items-center justify-center hover:scale-105 transition" onclick="BF.togglePlay()"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5" id="playIcon"></i></button>
</div>
<div class="hidden sm:flex items-center gap-3 w-48 sm:w-64 justify-end">
<div class="flex items-center gap-2"><i data-lucide="volume-2" class="w-5 h-5 text-gray-400"></i><div class="w-20 h-1 bg-white/10 rounded-full overflow-hidden"><div class="h-full bg-cyan-400 w-[70%] rounded-full"></div></div></div>
</div>
</div>
</div>
<script src="mobile-nav.js"></script>
<script src="app.js"></script>
<script>
BF.init('home');
lucide.createIcons();
// ===== ACCESS CHECK =====
const dashUser = BF.getCurrentUser();
if (!dashUser || dashUser.role !== 'producer') {
document.getElementById('accessBlock').classList.remove('hidden');
document.getElementById('dashboardMain').classList.add('hidden');
if (dashUser && dashUser.role === 'fan') {
document.getElementById('accessMsg').textContent = 'Dashboard is for Producers only. Upgrade your account to start earning.';
document.getElementById('accessCta').textContent = 'Upgrade to Producer';
document.getElementById('accessCta').onclick = function() {
dashUser.role = 'producer'; dashUser.isArtist = true;
localStorage.setItem('beatfridge_current_user', JSON.stringify(dashUser));
BF.showToast('Upgraded! 🎵'); setTimeout(() => window.location.reload(), 500);
};
}
} else {
document.getElementById('dashboardMain').classList.remove('hidden');
document.getElementById('dashUsername').textContent = '@' + dashUser.username;
}
// ===== DATA =====
let editTrackId = null;
let editMonetizeOn = false;
function getUserTracks() {
const all = BF.getAllTracks();
return all.filter(t => t.artistId === dashUser?.id || t.artist === (dashUser?.displayName || dashUser?.username));
}
function getDashTransactions() {
const txs = BF.getTransactionHistory({});
const name = dashUser?.displayName || dashUser?.username || '';
return txs.filter(t => t.artist === name || t.userId === dashUser?.id);
}
function getEarningsSummary() {
const earnings = BF.getCreatorEarnings(dashUser?.id || (dashUser?.displayName || dashUser?.username));
const summary = { totalGross: 0, totalNet: 0, totalFees: 0, downloads: 0, byMonth: {} };
earnings.forEach(e => {
summary.totalGross += e.grossAmount;
summary.totalNet += e.netAmount;
summary.totalFees += e.platformFee;
if (e.source === 'download') summary.downloads++;
const m = e.date ? e.date.substring(0,7) : 'unknown';
summary.byMonth[m] = (summary.byMonth[m] || 0) + e.grossAmount;
});
return summary;
}
// ===== RENDER DASHBOARD =====
function refreshDashboard() {
if (!dashUser) return;
renderStats();
renderRevenueChart();
renderTopTracks();
renderMyTracks();
renderBadges();
renderOnboarding();
renderTransactions();
}
function renderBadges() {
const badges = BF.getCreatorBadges();
const container = document.getElementById('badgesList');
const countEl = document.getElementById('badgeCount');
if (!container) return;
const earned = badges.filter(b => b.earned);
if (countEl) countEl.textContent = earned.length + ' earned';
if (!badges.length) {
container.innerHTML = '<div class="col-span-full text-center py-8"><p class="text-gray-500 text-sm">Upload tracks and earn to unlock badges</p></div>';
return;
}
container.innerHTML = badges.map(badge => `
<div class="p-3 rounded-xl ${badge.earned ? 'bg-orange-500/10 border border-orange-500/25' : 'bg-white/[0.03] border border-white/[0.06] opacity-50'} text-center transition">
<div class="text-2xl mb-1.5">${badge.icon}</div>
<p class="text-xs font-semibold ${badge.earned ? 'text-orange-400' : 'text-gray-500'}">${badge.label}</p>
<p class="text-[10px] ${badge.earned ? 'text-gray-400' : 'text-gray-600'} mt-0.5">${badge.description}</p>
${badge.earned ? '<span class="inline-block mt-1.5 text-[9px] text-green-400 font-medium">✓ Earned</span>' : '<span class="inline-block mt-1.5 text-[9px] text-gray-600 font-medium">🔒 Locked</span>'}
</div>
`).join('');
lucide.createIcons();
}
function renderOnboarding() {
const state = BF.getOnboardingState();
const section = document.getElementById('onboardingProgress');
const stepsEl = document.getElementById('checklistSteps');
const progressEl = document.getElementById('checklistProgress');
const barEl = document.getElementById('checklistBar');
if (!section || !state.isOnboarding) { if(section) section.classList.add('hidden'); return; }
section.classList.remove('hidden');
if (progressEl) progressEl.textContent = state.completedCount + '/' + state.totalCount;
if (barEl) barEl.style.width = ((state.completedCount / state.totalCount) * 100) + '%';
if (stepsEl) {
stepsEl.innerHTML = state.steps.map(step => `
<div class="flex items-center gap-3 p-2 rounded-lg ${step.completed ? 'bg-green-500/5' : ''}">
<div class="w-6 h-6 rounded-full ${step.completed ? 'bg-green-500/20' : 'bg-white/5'} flex items-center justify-center flex-shrink-0">
${step.completed ? '<i data-lucide="check" class="w-3 h-3 text-green-400"></i>' : '<i data-lucide="' + step.icon + '" class="w-3 h-3 text-gray-500"></i>'}
</div>
<span class="text-xs ${step.completed ? 'text-green-400 line-through' : 'text-gray-300'}">${step.label}</span>
${!step.completed && step.id === 'first_upload' ? '<a href="upload.html" class="ml-auto text-[10px] text-cyan-400 font-semibold hover:underline">Upload now →</a>' : ''}
</div>
`).join('');
lucide.createIcons();
}
}
function renderStats() {
const summary = getEarningsSummary();
const tracks = getUserTracks();
const txs = getDashTransactions();
let totalPlays = 0;
tracks.forEach(t => {
const p = parseFloat(t.plays || '0');
totalPlays += (t.plays || '').includes('K') ? p * 1000 : p;
});
const downloads = summary.downloads || txs.filter(t => t.type === 'download').length;
const convRate = totalPlays > 0 ? ((downloads / totalPlays) * 100).toFixed(1) : '0';
document.getElementById('statEarnings').textContent = '$' + summary.totalNet.toFixed(2);
document.getElementById('statDownloads').textContent = downloads;
document.getElementById('statDownloadsSub').textContent = downloads + ' unlock conversions';
document.getElementById('statPlays').textContent = totalPlays >= 1000 ? (totalPlays / 1000).toFixed(1) + 'K' : totalPlays;
document.getElementById('statPlaysSub').textContent = 'Across ' + tracks.length + ' tracks';
document.getElementById('statConversion').textContent = convRate + '%';
document.getElementById('statConversionSub').textContent = 'Plays → Unlocks';
const prevEarnings = summary.totalNet * 0.77;
const growthPct = prevEarnings > 0 ? (((summary.totalNet - prevEarnings) / prevEarnings) * 100).toFixed(0) : 0;
const trendEl = document.getElementById('statEarningsTrend');
if (growthPct > 0) { trendEl.className = 'text-xs mt-1 trend-up flex items-center gap-1'; trendEl.innerHTML = '<i data-lucide="trending-up" class="w-3 h-3"></i>+' + growthPct + '% from last period'; }
else { trendEl.className = 'text-xs mt-1 text-gray-500 flex items-center gap-1'; trendEl.innerHTML = '<i data-lucide="minus" class="w-3 h-3"></i>No change'; }
lucide.createIcons();
}
function renderRevenueChart() {
const summary = getEarningsSummary();
const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
const year = new Date().getFullYear();
const data = [];
for (let i = 0; i < 12; i++) {
const key = year + '-' + String(i+1).padStart(2,'0');
data.push({ month: months[i], amount: summary.byMonth[key] || 0 });
}
const maxVal = Math.max(...data.map(d => d.amount), 1);
const chart = document.getElementById('revenueChart');
const labels = document.getElementById('revenueLabels');
if (!chart) return;
chart.innerHTML = data.map(d => {
const h = d.amount > 0 ? Math.max(8, (d.amount / maxVal) * 100) : 4;
const color = d.amount > 0 ? 'background: linear-gradient(to top, #22c55e, #16a34a);' : 'background: rgba(255,255,255,0.05);';
return '<div class="chart-bar" style="height:' + h + '%;' + color + '"><div class="tooltip">$' + d.amount.toFixed(2) + '</div></div>';
}).join('');
labels.innerHTML = data.map(d => '<span>' + d.month + '</span>').join('');
}
function renderTopTracks() {
const tracks = getUserTracks();
const earnings = BF.getCreatorEarnings(dashUser?.id || (dashUser?.displayName || dashUser?.username));
const container = document.getElementById('topTracksList');
if (!container) return;
const trackStats = tracks.map(t => {
const tEarnings = earnings.filter(e => e.trackId === t.id);
const revenue = tEarnings.reduce((s, e) => s + e.netAmount, 0);
const dlCount = tEarnings.filter(e => e.source === 'download').length;
const tipCount = tEarnings.filter(e => e.source === 'tip').length;
const p = parseFloat(t.plays || '0');
const plays = (t.plays || '').includes('K') ? p * 1000 : p;
return { ...t, revenue, dlCount, tipCount, plays };
}).sort((a, b) => b.revenue - a.revenue).slice(0, 5);
if (!trackStats.length) {
container.innerHTML = '<div class="text-center py-8"><p class="text-gray-500 text-sm">No tracks yet</p></div>';
return;
}
container.innerHTML = trackStats.map((t, i) => {
const medals = ['🥇','🥈','🥉'];
const rank = i < 3 ? medals[i] : '<span class="text-gray-600 text-sm font-bold">' + (i+1) + '</span>';
return '<div class="flex items-center gap-3 p-3 rounded-xl bg-white/[0.03] hover:bg-white/[0.06] transition cursor-pointer" onclick="openPerfModal(\'' + t.id + '\')">' +
'<span class="text-lg w-7 text-center flex-shrink-0">' + rank + '</span>' +
'<div class="w-10 h-10 rounded-lg overflow-hidden flex-shrink-0"><img src="' + t.image + '" class="w-full h-full object-cover" loading="lazy"></div>' +
'<div class="flex-1 min-w-0"><p class="text-sm font-medium text-white truncate">' + t.title + '</p><p class="text-[11px] text-gray-500">' + t.dlCount + ' unlocks · ' + t.tipCount + ' tips</p></div>' +
'<p class="text-sm font-bold text-green-400 flex-shrink-0">$' + t.revenue.toFixed(2) + '</p>' +
'</div>';
}).join('');
}
function renderMyTracks() {
const tracks = getUserTracks();
const container = document.getElementById('myTracksList');
const countEl = document.getElementById('trackCount');
if (!container) return;
if (countEl) countEl.textContent = tracks.length + ' track' + (tracks.length !== 1 ? 's' : '');
if (!tracks.length) {
container.innerHTML = '<div class="text-center py-12"><div class="w-14 h-14 rounded-full bg-white/5 flex items-center justify-center mx-auto mb-4"><i data-lucide="music" class="w-7 h-7 text-gray-600"></i></div><p class="text-gray-500 mb-3">No tracks yet</p><a href="upload.html" class="px-5 py-2.5 bg-cyan-500 hover:bg-cyan-400 text-black font-semibold rounded-xl transition inline-flex items-center gap-2 text-sm"><i data-lucide="upload-cloud" class="w-4 h-4"></i>Upload Your First Track</a></div>';
lucide.createIcons();
return;
}
const earnings = BF.getCreatorEarnings(dashUser?.id || (dashUser?.displayName || dashUser?.username));
container.innerHTML = '<div class="space-y-1">' + tracks.map(t => {
const mon = BF.getTrackMonetization(t.id);
const tEarnings = earnings.filter(e => e.trackId === t.id);
const revenue = tEarnings.reduce((s, e) => s + e.netAmount, 0);
const dlCount = tEarnings.filter(e => e.source === 'download').length;
const isMonetized = mon && mon.isMonetized;
const priceLabel = isMonetized ? '$' + (mon.minimumPrice || 0.50).toFixed(2) : 'Free';
const statusDot = isMonetized ? 'bg-orange-400' : 'bg-green-400';
const statusLabel = isMonetized ? 'Paid' : 'Free';
const safeTitle = String(t.title).replace(/'/g, "\\'").replace(/"/g, '&quot;');
const safeArtist = String(t.artist).replace(/'/g, "\\'").replace(/"/g, '&quot;');
return '<div class="track-row flex items-center gap-3 p-3 rounded-xl">' +
'<div class="w-12 h-12 rounded-lg overflow-hidden flex-shrink-0"><img src="' + t.image + '" class="w-full h-full object-cover" loading="lazy"></div>' +
'<div class="flex-1 min-w-0">' +
'<div class="flex items-center gap-2"><h4 class="text-sm font-medium text-white truncate">' + t.title + '</h4><span class="w-1.5 h-1.5 rounded-full ' + statusDot + ' flex-shrink-0"></span><span class="text-[10px] text-gray-500 flex-shrink-0">' + statusLabel + '</span></div>' +
'<p class="text-[11px] text-gray-500 truncate">' + (t.genre || '—') + ' · ' + t.plays + ' plays · ' + dlCount + ' unlocks · ' + priceLabel + '</p>' +
'</div>' +
'<div class="text-right flex-shrink-0 mr-1 hidden sm:block"><p class="text-sm font-semibold text-green-400">$' + revenue.toFixed(2) + '</p><p class="text-[10px] text-gray-600">revenue</p></div>' +
'<div class="flex items-center gap-1.5 flex-shrink-0">' +
'<button class="action-icon edit" onclick="openEditModal(\'' + t.id + '\')" title="Edit"><i data-lucide="edit-3" class="w-3.5 h-3.5"></i></button>' +
'<button class="action-icon perf" onclick="openPerfModal(\'' + t.id + '\')" title="Performance"><i data-lucide="bar-chart-2" class="w-3.5 h-3.5"></i></button>' +
'<button class="action-icon delete" onclick="deleteTrack(\'' + t.id + '\', \'' + safeTitle + '\')" title="Delete"><i data-lucide="trash-2" class="w-3.5 h-3.5"></i></button>' +
'</div>' +
'</div>';
}).join('') + '</div>';
lucide.createIcons();
}
function renderTransactions() {
const txs = getDashTransactions().slice(0, 10);
const container = document.getElementById('transactionsList');
if (!container) return;
if (!txs.length) {
container.innerHTML = '<div class="text-center py-8"><p class="text-gray-500 text-sm">No transactions yet — share your tracks to start earning!</p></div>';
return;
}
const icons = { download: 'download', tip: 'heart-handshake', subscription: 'repeat' };
const colors = { download: 'text-cyan-400', tip: 'text-orange-400', subscription: 'text-purple-400' };
const bgs = { download: 'bg-cyan-500/15', tip: 'bg-orange-500/15', subscription: 'bg-purple-500/15' };
container.innerHTML = txs.map(tx => {
const icon = icons[tx.type] || 'circle';
const color = colors[tx.type] || 'text-gray-400';
const bg = bgs[tx.type] || 'bg-white/5';
const date = tx.date ? new Date(tx.date).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) : '';
const time = tx.date ? new Date(tx.date).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }) : '';
const net = tx.amount ? ((tx.amount - (tx.fee || 0))).toFixed(2) : '0.00';
return '<div class="flex items-center gap-3 p-3 rounded-xl hover:bg-white/[0.03] transition">' +
'<div class="w-9 h-9 rounded-lg ' + bg + ' flex items-center justify-center flex-shrink-0"><i data-lucide="' + icon + '" class="w-4 h-4 ' + color + '"></i></div>' +
'<div class="flex-1 min-w-0">' +
'<div class="flex items-center gap-2"><p class="text-sm font-medium text-white capitalize">' + tx.type.replace(/_/g,' ') + '</p>' + (tx.track ? '<span class="text-[11px] text-gray-500">· ' + tx.track + '</span>' : '') + '</div>' +
'<p class="text-[11px] text-gray-600">' + date + ' at ' + time + '</p>' +
'</div>' +
'<div class="text-right flex-shrink-0">' +
'<p class="text-sm font-semibold text-green-400">+$' + net + '</p>' +
'<p class="text-[10px] text-gray-600">Your cut</p>' +
'</div>' +
'</div>';
}).join('');
lucide.createIcons();
}
// ===== EDIT MODAL =====
function openEditModal(trackId) {
const allT = BF.getAllTracks();
const track = allT.find(t => String(t.id) === String(trackId));
if (!track) return;
editTrackId = trackId;
editMonetizeOn = false;
document.getElementById('editTitle').value = track.title || '';
document.getElementById('editGenre').value = track.genre || '';
const mon = BF.getTrackMonetization(trackId);
if (mon && mon.isMonetized) {
editMonetizeOn = true;
document.getElementById('editMonetizeToggle').classList.remove('bg-white/10');
document.getElementById('editMonetizeToggle').classList.add('bg-orange-500');
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').style.transform = 'translateX(1.25rem)';
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').classList.remove('bg-gray-400');
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').classList.add('bg-white');
document.getElementById('editPriceSection').classList.remove('hidden');
document.getElementById('editPrice').value = mon.minimumPrice || 0.50;
} else {
editMonetizeOn = false;
document.getElementById('editMonetizeToggle').classList.add('bg-white/10');
document.getElementById('editMonetizeToggle').classList.remove('bg-orange-500');
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').style.transform = 'translateX(0)';
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').classList.add('bg-gray-400');
document.getElementById('editMonetizeToggle').querySelector('.toggle-thumb').classList.remove('bg-white');
document.getElementById('editPriceSection').classList.add('hidden');
}
document.getElementById('editError').classList.add('hidden');
document.getElementById('editModal').classList.remove('hidden');
lucide.createIcons();
}
function closeEditModal() {
document.getElementById('editModal').classList.add('hidden');
editTrackId = null;
}
function toggleEditMonetize() {
editMonetizeOn = !editMonetizeOn;
const toggle = document.getElementById('editMonetizeToggle');
const thumb = toggle.querySelector('.toggle-thumb');
const section = document.getElementById('editPriceSection');
if (editMonetizeOn) {
toggle.classList.remove('bg-white/10'); toggle.classList.add('bg-orange-500');
thumb.style.transform = 'translateX(1.25rem)'; thumb.classList.remove('bg-gray-400'); thumb.classList.add('bg-white');
section.classList.remove('hidden');
} else {
toggle.classList.add('bg-white/10'); toggle.classList.remove('bg-orange-500');
thumb.style.transform = 'translateX(0)'; thumb.classList.add('bg-gray-400'); thumb.classList.remove('bg-white');
section.classList.add('hidden');
}
}
function saveEdit() {
const title = document.getElementById('editTitle').value.trim();
const genre = document.getElementById('editGenre').value;
if (!title) { document.getElementById('editError').textContent = 'Title is required'; document.getElementById('editError').classList.remove('hidden'); return; }
try {
let allTracks = JSON.parse(localStorage.getItem('beatfridge_tracks') || '[]');
let userTracks = JSON.parse(localStorage.getItem('userTracks') || '[]');
const idx1 = allTracks.findIndex(t => String(t.id) === String(editTrackId));
const idx2 = userTracks.findIndex(t => String(t.id) === String(editTrackId));
if (idx1 > -1) { allTracks[idx1].title = title; allTracks[idx1].genre = genre; }
if (idx2 > -1) { userTracks[idx2].title = title; userTracks[idx2].genre = genre; }
localStorage.setItem('beatfridge_tracks', JSON.stringify(allTracks));
localStorage.setItem('userTracks', JSON.stringify(userTracks));
if (editMonetizeOn) {
const price = parseFloat(document.getElementById('editPrice').value) || 0.50;
BF.setTrackMonetization(editTrackId, { isMonetized: true, isLocked: true, minimumPrice: price, suggestedPrice: price, superFanFree: true });
} else {
BF.setTrackMonetization(editTrackId, { isMonetized: false, isLocked: false, superFanFree: true });
}
closeEditModal();
BF.showToast('Track updated ✓');
refreshDashboard();
} catch (e) {
document.getElementById('editError').textContent = 'Save failed: ' + e.message;
document.getElementById('editError').classList.remove('hidden');
}
}
// ===== DELETE =====
function deleteTrack(trackId, trackTitle) {
if (!confirm('Delete "' + trackTitle + '"? This cannot be undone.')) return;
try {
let allTracks = JSON.parse(localStorage.getItem('beatfridge_tracks') || '[]');
let userTracks = JSON.parse(localStorage.getItem('userTracks') || '[]');
allTracks = allTracks.filter(t => String(t.id) !== String(trackId));
userTracks = userTracks.filter(t => String(t.id) !== String(trackId));
localStorage.setItem('beatfridge_tracks', JSON.stringify(allTracks));
localStorage.setItem('userTracks', JSON.stringify(userTracks));
BF.showToast('Track deleted');
refreshDashboard();
} catch (e) { BF.showToast('Delete failed'); }
}
// ===== PERFORMANCE MODAL =====
function openPerfModal(trackId) {
const allT = BF.getAllTracks();
const track = allT.find(t => String(t.id) === String(trackId));
if (!track) return;
const earnings = BF.getCreatorEarnings(dashUser?.id || (dashUser?.displayName || dashUser?.username));
const tEarnings = earnings.filter(e => String(e.trackId) === String(trackId));
const totalRevenue = tEarnings.reduce((s, e) => s + e.netAmount, 0);
const dlCount = tEarnings.filter(e => e.source === 'download').length;
const tipCount = tEarnings.filter(e => e.source === 'tip').length;
const tipRevenue = tEarnings.filter(e => e.source === 'tip').reduce((s, e) => s + e.netAmount, 0);
const dlRevenue = tEarnings.filter(e => e.source === 'download').reduce((s, e) => s + e.netAmount, 0);
const subRevenue = tEarnings.filter(e => e.source === 'subscription').reduce((s, e) => s + e.netAmount, 0);
const p = parseFloat(track.plays || '0');
const plays = (track.plays || '').includes('K') ? p * 1000 : p;
const convRate = plays > 0 ? ((dlCount / plays) * 100).toFixed(1) : '0.0';
// Simulate 7-day plays data
const dailyPlays = [];
for (let i = 6; i >= 0; i--) {
const base = plays > 0 ? plays / 30 : 50;
dailyPlays.push(Math.round(base * (0.6 + Math.random() * 0.8)));
}
const maxDaily = Math.max(...dailyPlays, 1);
const mon = BF.getTrackMonetization(trackId);
const isMonetized = mon && mon.isMonetized;
const priceLabel = isMonetized ? '$' + (mon.minimumPrice || 0.50).toFixed(2) : 'Free';
const content = document.getElementById('perfContent');
content.innerHTML =
'<div class="flex items-center gap-4 mb-5">' +
'<div class="w-14 h-14 rounded-xl overflow-hidden flex-shrink-0"><img src="' + track.image + '" class="w-full h-full object-cover"></div>' +
'<div class="flex-1 min-w-0"><h4 class="font-bold text-white truncate">' + track.title + '</h4><p class="text-xs text-gray-500">' + (track.genre || '—') + ' · ' + priceLabel + ' · ' + track.duration + '</p></div>' +
'</div>' +
'<div class="grid grid-cols-4 gap-3 mb-5">' +
'<div class="text-center p-3 rounded-xl bg-white/[0.03]"><p class="text-lg font-bold text-white">' + (plays >= 1000 ? (plays/1000).toFixed(1) + 'K' : plays) + '</p><p class="text-[10px] text-gray-500 uppercase">Plays</p></div>' +
'<div class="text-center p-3 rounded-xl bg-white/[0.03]"><p class="text-lg font-bold text-cyan-400">' + dlCount + '</p><p class="text-[10px] text-gray-500 uppercase">Unlocks</p></div>' +
'<div class="text-center p-3 rounded-xl bg-white/[0.03]"><p class="text-lg font-bold text-green-400">$' + totalRevenue.toFixed(2) + '</p><p class="text-[10px] text-gray-500 uppercase">Revenue</p></div>' +
'<div class="text-center p-3 rounded-xl bg-white/[0.03]"><p class="text-lg font-bold text-orange-400">' + convRate + '%</p><p class="text-[10px] text-gray-500 uppercase">Conv.</p></div>' +
'</div>' +
'<div class="mb-5">' +
'<p class="text-xs font-medium text-gray-400 uppercase tracking-wider mb-3">7-Day Plays</p>' +
'<div class="flex items-end gap-2 h-20">' + dailyPlays.map((d, i) => {
const h = Math.max(8, (d / maxDaily) * 100);
const days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
const dayIdx = (new Date().getDay() - 6 + i + 7) % 7;
return '<div class="flex-1 flex flex-col items-center gap-1