@@ -36,6 +36,8 @@ const PlayerPage: React.FC<PageProps> = ({ playbackId, videoExists, shareUrl, po
3636 const [ metadataLoading , setMetadataLoading ] = useState ( false ) ;
3737 const [ metadata , setMetadata ] = useState < any > ( null ) ;
3838 const [ isMetadataCopied , setIsMetadataCopied ] = useState ( false ) ;
39+ const [ viewCount , setViewCount ] = useState < number | null > ( null ) ;
40+ const [ viewCountLoading , setViewCountLoading ] = useState ( false ) ;
3941 const copyTimeoutRef = useRef < number | null > ( null ) ;
4042 const metadataCopyTimeoutRef = useRef < number | null > ( null ) ;
4143 const router = useRouter ( ) ;
@@ -65,6 +67,30 @@ const PlayerPage: React.FC<PageProps> = ({ playbackId, videoExists, shareUrl, po
6567 }
6668 } , [ playerType ] ) ;
6769
70+ useEffect ( ( ) => {
71+ if ( showAdvanced ) {
72+ fetchViewCount ( ) ;
73+ }
74+ } , [ showAdvanced , playbackId ] ) ;
75+
76+ const fetchViewCount = async ( ) => {
77+ if ( ! playbackId ) return ;
78+
79+ console . log ( 'Fetching view count for playback ID:' , playbackId ) ;
80+ setViewCountLoading ( true ) ;
81+ try {
82+ const response = await fetch ( `/api/views/${ playbackId } ` ) ;
83+ const data = await response . json ( ) ;
84+ console . log ( 'View count API response:' , data ) ;
85+ setViewCount ( typeof data . views === 'number' ? data . views : null ) ;
86+ } catch ( error ) {
87+ console . error ( 'Error fetching view count:' , error ) ;
88+ setViewCount ( null ) ;
89+ } finally {
90+ setViewCountLoading ( false ) ;
91+ }
92+ } ;
93+
6894 const color = useMemo ( ( ) => {
6995 if ( router . query ?. color ) {
7096 const val = ( router . query ?. color as string ) ;
@@ -330,6 +356,16 @@ const PlayerPage: React.FC<PageProps> = ({ playbackId, videoExists, shareUrl, po
330356 </ span >
331357 ) ) }
332358 </ div >
359+ < div className = "view-count" >
360+ < span className = "label" > Views (7d): </ span >
361+ { viewCountLoading ? (
362+ < span className = "loading" > Loading...</ span >
363+ ) : typeof viewCount === 'number' ? (
364+ < span className = "count" > { viewCount . toLocaleString ( ) } </ span >
365+ ) : (
366+ < span className = "error" > No data</ span >
367+ ) }
368+ </ div >
333369 < div className = "metadata-toggle" >
334370 < a
335371 onClick = { toggleMetadata }
@@ -556,6 +592,25 @@ const PlayerPage: React.FC<PageProps> = ({ playbackId, videoExists, shareUrl, po
556592 flex: 0 0 300px;
557593 margin-top: 40px;
558594 }
595+ .view-count {
596+ margin-top: 15px;
597+ padding-top: 15px;
598+ border-top: 1px solid rgba(255, 255, 255, 0.1);
599+ display: flex;
600+ align-items: center;
601+ gap: 8px;
602+ }
603+ .view-count .loading {
604+ color: #ccc;
605+ font-style: italic;
606+ }
607+ .view-count .count {
608+ color: #fff;
609+ font-weight: bold;
610+ }
611+ .view-count .error {
612+ color: #ff6b6b;
613+ }
559614 @media (max-width: 900px) {
560615 .content-container {
561616 flex-direction: column;
0 commit comments