2026-01-07 09:31:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Card } from '../ui/card';
|
|
|
|
|
import { Button } from '../ui/button';
|
|
|
|
|
import { StatCard } from '../dashboard/StatCard';
|
2026-01-13 18:47:57 +00:00
|
|
|
import {
|
|
|
|
|
Play,
|
|
|
|
|
SkipForward,
|
|
|
|
|
Clock,
|
|
|
|
|
Users,
|
|
|
|
|
Map,
|
|
|
|
|
ArrowLeft,
|
|
|
|
|
Download,
|
|
|
|
|
} from 'lucide-react';
|
2026-01-26 13:12:17 +00:00
|
|
|
import { useToast } from '../../components/feedback/ToastProvider';
|
2026-01-07 09:31:02 +00:00
|
|
|
|
|
|
|
|
interface TrackAnalyticsViewProps {
|
2026-01-13 18:47:57 +00:00
|
|
|
trackId: string;
|
|
|
|
|
onBack: () => void;
|
2026-01-07 09:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
export const TrackAnalyticsView: React.FC<TrackAnalyticsViewProps> = ({
|
|
|
|
|
trackId: _trackId,
|
|
|
|
|
onBack,
|
|
|
|
|
}) => {
|
2026-01-07 09:31:02 +00:00
|
|
|
const { addToast } = useToast();
|
|
|
|
|
|
|
|
|
|
// Mock Track Data
|
|
|
|
|
const trackData = {
|
2026-01-13 18:47:57 +00:00
|
|
|
title: 'Neon Nights',
|
|
|
|
|
artist: 'Cyber_Producer',
|
|
|
|
|
plays: 15420,
|
|
|
|
|
skips: 320,
|
|
|
|
|
avgListen: '2:45', // vs 3:45 total
|
|
|
|
|
completion: 78,
|
|
|
|
|
demographics: { '18-24': 45, '25-34': 30, '35+': 25 },
|
|
|
|
|
geo: [
|
|
|
|
|
{ country: 'USA', percent: 40 },
|
|
|
|
|
{ country: 'Japan', percent: 25 },
|
|
|
|
|
{ country: 'Germany', percent: 15 },
|
|
|
|
|
{ country: 'UK', percent: 10 },
|
|
|
|
|
],
|
2026-01-07 09:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-8 animate-fadeIn pb-20">
|
2026-01-13 18:47:57 +00:00
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
<Button variant="ghost" size="icon" onClick={onBack}>
|
|
|
|
|
<ArrowLeft className="w-5 h-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
<div>
|
|
|
|
|
<h2 className="text-2xl font-bold text-white">{trackData.title}</h2>
|
2026-01-16 00:59:31 +00:00
|
|
|
<p className="text-kodo-content-dim text-sm">Analytics Report</p>
|
2026-01-13 18:47:57 +00:00
|
|
|
</div>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
icon={<Download className="w-4 h-4" />}
|
|
|
|
|
onClick={() => addToast('Report downloaded')}
|
|
|
|
|
>
|
|
|
|
|
Export CSV
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-01-07 09:31:02 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
{/* Key Metrics */}
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
|
|
|
|
<StatCard
|
|
|
|
|
label="Total Plays"
|
|
|
|
|
value={trackData.plays.toLocaleString()}
|
|
|
|
|
icon={<Play className="w-5 h-5" />}
|
|
|
|
|
color="cyan"
|
|
|
|
|
trend={12}
|
|
|
|
|
sparklineData={[10, 15, 12, 20, 25, 30, 28, 35, 40]}
|
|
|
|
|
/>
|
|
|
|
|
<StatCard
|
|
|
|
|
label="Completion Rate"
|
|
|
|
|
value={`${trackData.completion}%`}
|
|
|
|
|
icon={<Clock className="w-5 h-5" />}
|
|
|
|
|
color="lime"
|
|
|
|
|
trend={2.5}
|
|
|
|
|
/>
|
|
|
|
|
<StatCard
|
|
|
|
|
label="Skip Rate"
|
|
|
|
|
value={`${((trackData.skips / trackData.plays) * 100).toFixed(1)}%`}
|
|
|
|
|
icon={<SkipForward className="w-5 h-5" />}
|
|
|
|
|
color="red"
|
|
|
|
|
trend={-0.5} // Negative is good for skip rate, logic in StatCard handles green/red based on +/-. might need tweak for inverse metrics
|
|
|
|
|
/>
|
|
|
|
|
<StatCard
|
|
|
|
|
label="Avg Listen Time"
|
|
|
|
|
value={trackData.avgListen}
|
|
|
|
|
icon={<Users className="w-5 h-5" />}
|
|
|
|
|
color="gold"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-01-07 09:31:02 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
|
|
|
|
{/* Plays Over Time Graph Placeholder */}
|
|
|
|
|
<Card variant="default">
|
|
|
|
|
<h3 className="font-bold text-white mb-6">
|
|
|
|
|
Plays Over Time (30 Days)
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="h-64 flex items-end gap-2 px-4 pb-4">
|
|
|
|
|
{Array.from({ length: 30 }).map((_, i) => {
|
|
|
|
|
const h = Math.random() * 100;
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={i}
|
2026-01-16 10:13:36 +00:00
|
|
|
className="flex-1 bg-kodo-steel/20 hover:bg-kodo-steel/50 transition-colors rounded-t relative group"
|
2026-01-13 18:47:57 +00:00
|
|
|
style={{ height: `${h}%` }}
|
|
|
|
|
>
|
|
|
|
|
<div className="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-black text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 pointer-events-none">
|
|
|
|
|
{Math.floor(h * 10)} plays
|
|
|
|
|
</div>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
2026-01-07 09:31:02 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
{/* Demographics & Geo */}
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
<Card variant="default">
|
|
|
|
|
<h3 className="font-bold text-white mb-4 flex items-center gap-2">
|
|
|
|
|
<Map className="w-4 h-4 text-kodo-magenta" /> Top Locations
|
|
|
|
|
</h3>
|
aesthetic-improvements: align spacing to 8px grid (Action 11.2.1.3)
- Created automated script (scripts/align-8px-grid.py) to align all spacing to 8px grid
- Replaced non-8px-aligned spacing: gap-3/p-3/m-3 (12px) → gap-4/p-4/m-4 (16px), gap-5/p-5/m-5 (20px) → gap-6/p-6/m-6 (24px), gap-10/p-10/m-10 (40px) → gap-12/p-12/m-12 (48px), gap-20/p-20/m-20 (80px) → gap-24/p-24/m-24 (96px)
- Preserved: 4px values (gap-1, p-1, m-1) as they may be intentional fine-tuning, responsive breakpoints (sm:, md:, lg:), test files, documentation
- Modified files across all components to ensure consistent 8px grid alignment
- Action 11.2.1.3: Align all elements to 8px grid - COMPLETE
2026-01-16 10:50:46 +00:00
|
|
|
<div className="space-y-4">
|
2026-01-13 18:47:57 +00:00
|
|
|
{trackData.geo.map((g) => (
|
|
|
|
|
<div key={g.country} className="flex items-center gap-4">
|
2026-01-16 00:59:31 +00:00
|
|
|
<div className="w-16 text-sm text-kodo-content-dim">{g.country}</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
<div className="flex-1 h-2 bg-kodo-steel rounded-full overflow-hidden">
|
|
|
|
|
<div
|
|
|
|
|
className="h-full bg-kodo-magenta"
|
|
|
|
|
style={{ width: `${g.percent}%` }}
|
|
|
|
|
></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-12 text-right text-sm font-bold text-white">
|
|
|
|
|
{g.percent}%
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
2026-01-07 09:31:02 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
<Card variant="default">
|
|
|
|
|
<h3 className="font-bold text-white mb-4 flex items-center gap-2">
|
|
|
|
|
<Users className="w-4 h-4 text-kodo-gold" /> Listeners Age
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="flex gap-2 h-8">
|
|
|
|
|
{Object.entries(trackData.demographics).map(([range, val]) => (
|
|
|
|
|
<div
|
|
|
|
|
key={range}
|
|
|
|
|
className="h-full first:rounded-l last:rounded-r relative group"
|
|
|
|
|
style={{
|
|
|
|
|
width: `${val}%`,
|
|
|
|
|
backgroundColor:
|
|
|
|
|
range === '18-24'
|
|
|
|
|
? '#66FCF1'
|
|
|
|
|
: range === '25-34'
|
|
|
|
|
? '#36E5D1'
|
|
|
|
|
: '#1F2833',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="absolute inset-0 flex items-center justify-center text-[10px] font-bold text-black opacity-0 group-hover:opacity-100 transition-opacity">
|
|
|
|
|
{range}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-01-16 00:59:31 +00:00
|
|
|
<div className="flex justify-between text-xs text-kodo-content-dim mt-2">
|
2026-01-13 18:47:57 +00:00
|
|
|
{Object.entries(trackData.demographics).map(([range, val]) => (
|
|
|
|
|
<span key={range}>
|
|
|
|
|
{range}: {val}%
|
|
|
|
|
</span>
|
|
|
|
|
))}
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
</Card>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
</div>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|