veza/apps/web/dist_verification/assets/SocialView-C_G9BXzk.js
2026-02-07 20:36:48 +01:00

1 line
10 KiB
JavaScript

import{a as u,j as a}from"./vendor-react-YMhRUmcb.js";import{a as i,l as b,x as N,k as _,C as j,B as m}from"./index-D2uzyr9g.js";import{aC as S,w as T,a0 as C,Y as z,a8 as U}from"./vendor-icons-DINCNwpk.js";import{G as k}from"./vendor-fFnFILYR.js";import{S as p}from"./skeleton-BPDNnZ8E.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";const y=1024*1024*2,w={uploadTrack:async(e,s,t)=>{const r=Math.ceil(e.size/y),h=await i.post("/tracks/initiate",{filename:e.name,total_chunks:r,file_size:e.size,title:s.title,artist:s.artist,album:s.album,genre:s.genre}),{upload_id:c}=h.data;b.info(`[UPLOAD] Upload initiated with ID: ${c}`,{filename:e.name,totalChunks:r});for(let n=0;n<r;n++){const d=n*y,x=Math.min(d+y,e.size),l=e.slice(d,x),g=new FormData;g.append("chunk",l),g.append("index",n.toString()),g.append("upload_id",c);try{await i.post("/tracks/chunk",g,{timeout:3e5,_enableLogging:!1});const f=(n+1)/r*100;t&&t(f)}catch(f){throw b.error(`[UPLOAD] Failed to upload chunk ${n} for ${c}`,{error:f}),f}}const o=await i.post("/tracks/complete",{upload_id:c});return b.info(`[UPLOAD] Upload completed. Track ID: ${o.data.track_id}`),o.data},getTrackStatus:async e=>(await i.get(`/tracks/${e}/status`)).data},$={API_URL:"https://api.veza.com/api/v1"},v=e=>({id:e.id,title:e.title,artist:typeof e.artist=="object"?e.artist.name:e.artist,album:e.album||"Unknown",duration:e.duration_formatted||"0:00",durationSec:e.duration||0,genre:e.genre||"None",year:e.year||new Date().getFullYear(),coverUrl:e.cover_art_path?`${$.API_URL}${e.cover_art_path}`:void 0,cover_art_path:e.cover_art_path,filePath:e.file_path,file_path:e.file_path,file_size:e.file_size||0,format:e.format||"mp3",bitrate:e.bitrate||0,sample_rate:e.sample_rate||0,play_count:e.play_count||0,like_count:e.like_count||0,plays:e.play_count||0,likes:e.like_count||0,created_at:e.created_at,updated_at:e.updated_at,creator_id:e.creator_id,is_public:e.is_public??!0,status:e.status,stream_status:e.stream_status||"pending",stream_manifest_url:e.stream_manifest_url}),E={list:async e=>{const t=(await i.get("/tracks",{params:{...e,query:e?.query||e?.search}})).data;return{tracks:(t.items||[]).map(v),pagination:{total:t.total,page:t.page,limit:t.limit,total_pages:t.total_pages,has_next:t.has_next,has_prev:t.has_prev}}},search:async e=>({tracks:(await i.get("/tracks/search",{params:{query:e}})).data.map(v)}),get:async e=>{const s=await i.get(`/tracks/${e}`,{validateSchema:N});return{track:v(s.data)}},update:async(e,s)=>{const t={title:s.title,artist:s.artist,album:s.album,genre:s.genre,is_public:s.is_public},r=await i.put(`/tracks/${e}`,t,{validateSchema:N});return{track:v(r.data)}},delete:async e=>i.delete(`/tracks/${e}`),like:async e=>i.post(`/tracks/${e}/like`),unlike:async e=>i.delete(`/tracks/${e}/like`),recordPlay:async e=>i.post(`/tracks/${e}/play`),download:async e=>(await i.get(`/tracks/${e}/download`,{responseType:"blob"})).data,upload:async(e,s,t)=>await w.uploadTrack(e,s,t),getStatus:async e=>await w.getTrackStatus(e)};function D(){const{playTrack:e}=_(),[s,t]=u.useState("feed"),[r,h]=u.useState([]),[c,o]=u.useState(!0),[n,d]=u.useState(!1),x=u.useCallback(async()=>{o(!0),d(!1);try{const l=await E.list({limit:10,sort_by:"created_at"});h(l.tracks)}catch(l){b.error("Error loading feed tracks",{error:l instanceof Error?l.message:String(l),stack:l instanceof Error?l.stack:void 0}),d(!0)}finally{o(!1)}},[]);return u.useEffect(()=>{x()},[x]),{activeTab:s,setActiveTab:t,feedTracks:r,loading:c,error:n,retry:x,playTrack:e}}function F({activeTab:e,onTabChange:s,onProfileClick:t}){return a.jsxs("div",{className:"hidden lg:block lg:col-span-3 space-y-8",children:[a.jsxs(j,{variant:"glass",className:"p-0 overflow-hidden border-white/5 bg-black/20 backdrop-blur-xl hover-glow-cyan transition-shadow duration-300",children:[a.jsx("div",{className:"h-20 bg-gradient-gaming"}),a.jsxs("div",{className:"px-4 pb-4",children:[a.jsx("div",{className:"relative -mt-10 mb-3 cursor-pointer",onClick:t,onKeyDown:r=>r.key==="Enter"&&t(),role:"button",tabIndex:0,children:a.jsx("div",{className:"w-20 h-20 rounded-full border-4 border-border overflow-hidden bg-muted",children:a.jsx("img",{src:"https://picsum.photos/id/237/200/200",alt:"",className:"w-full h-full object-cover"})})}),a.jsx("h3",{className:"font-bold text-foreground text-lg tracking-tight",children:"My Profile"}),a.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"View your stats"})]})]}),a.jsx(j,{variant:"glass",className:"p-2 border-white/5 bg-black/20 backdrop-blur-xl",children:a.jsxs("nav",{className:"space-y-1",children:[a.jsxs(m,{variant:e==="feed"?"outline":"ghost",size:"sm",className:"w-full justify-start",onClick:()=>s("feed"),children:[a.jsx(S,{className:"w-4 h-4"})," Fresh Tracks"]}),a.jsxs(m,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>s("communities"),children:[a.jsx(T,{className:"w-4 h-4"})," Communities"]})]})})]})}function I({track:e,onPlay:s}){return a.jsx(k.div,{whileHover:{scale:1.01},transition:{duration:.2},className:"mb-4",children:a.jsxs(j,{variant:"glass",className:"p-0 overflow-hidden border-white/5 bg-black/20 backdrop-blur-xl hover-glow-cyan transition-all duration-300",children:[a.jsxs("div",{className:"p-4 flex items-center gap-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-muted overflow-hidden",children:a.jsx("img",{src:e.coverUrl,alt:"",className:"w-full h-full object-cover"})}),a.jsxs("div",{children:[a.jsx("div",{className:"font-bold text-foreground text-sm",children:e.artist}),a.jsx("div",{className:"text-xs text-muted-foreground",children:"uploaded a new track"})]}),a.jsx(m,{variant:"ghost",size:"sm",className:"ml-auto",children:a.jsx(C,{className:"w-4 h-4"})})]}),a.jsx("div",{className:"px-4 pb-4",children:a.jsxs("div",{className:"bg-card p-4 rounded-xl flex items-center gap-4 border border-border group cursor-pointer",onClick:()=>s(e),onKeyDown:t=>t.key==="Enter"&&s(e),role:"button",tabIndex:0,children:[a.jsxs("div",{className:"w-16 h-16 rounded overflow-hidden relative",children:[a.jsx("img",{src:e.coverUrl,alt:"",className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute inset-0 bg-black/30 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:a.jsx(z,{className:"w-6 h-6 text-white fill-current"})})]}),a.jsxs("div",{className:"flex-1",children:[a.jsx("h4",{className:"font-bold text-foreground tracking-tight",children:e.title}),a.jsx("p",{className:"text-xs text-muted-foreground",children:e.genre||"Electronic"})]}),a.jsx("div",{className:"text-xs text-muted-foreground font-mono pr-2",children:e.duration})]})}),a.jsxs("div",{className:"px-4 py-4 border-t border-border flex gap-4 text-xs text-muted-foreground",children:[a.jsxs(m,{variant:"ghost",size:"sm",className:"text-xs h-auto py-0",children:["Like (",e.like_count,")"]}),a.jsx(m,{variant:"ghost",size:"sm",className:"text-xs h-auto py-0",children:"Comment"}),a.jsx(m,{variant:"ghost",size:"sm",className:"text-xs h-auto py-0",children:"Share"})]})]})})}const V={visible:{transition:{staggerChildren:.05,delayChildren:.02}}},P={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}};function A({tracks:e,loading:s,onPlayTrack:t}){return a.jsxs("div",{className:"col-span-1 lg:col-span-6 space-y-8",children:[a.jsxs("div",{className:"mb-4",children:[a.jsx("h2",{className:"text-2xl font-bold text-foreground mb-1 tracking-tight",children:"Community Feed"}),a.jsx("p",{className:"text-muted-foreground text-xs",children:"New uploads from the network"})]}),s?null:a.jsx(a.Fragment,{children:e.length>0?a.jsx(k.div,{className:"space-y-4",variants:V,initial:"hidden",animate:"visible",children:e.map(r=>a.jsx(k.div,{variants:P,children:a.jsx(I,{track:r,onPlay:t})},r.id))}):a.jsx("div",{className:"text-center py-24 text-muted-foreground",children:"No recent activity."})})]})}const L=["#Techno","#Synthwave","#NewGear","#Tutorial"];function R(){return a.jsx("div",{className:"hidden lg:block lg:col-span-3 space-y-8",children:a.jsxs(j,{variant:"glass",className:"border-white/5 bg-black/20 backdrop-blur-xl hover-glow-cyan transition-shadow duration-300",children:[a.jsxs("h3",{className:"font-bold text-sm text-foreground uppercase tracking-wider mb-4 flex items-center gap-2",children:[a.jsx(U,{className:"w-4 h-4 text-primary"})," Trending Tags"]}),a.jsx("div",{className:"flex flex-wrap gap-2",children:L.map(e=>a.jsx("span",{className:"text-xs bg-muted px-2 py-1 rounded text-muted-foreground cursor-pointer hover:text-foreground hover:bg-muted/80 transition-all duration-200",children:e},e))})]})})}function G(){return a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-8 animate-fadeIn pb-20 min-h-layout-page",children:[a.jsxs("div",{className:"hidden lg:block lg:col-span-3 space-y-8",children:[a.jsx(p,{className:"h-48 rounded-[var(--radius-xl)]"}),a.jsx(p,{className:"h-32 rounded-[var(--radius-xl)]"})]}),a.jsxs("div",{className:"col-span-1 lg:col-span-6 space-y-8",children:[a.jsxs("div",{className:"mb-4",children:[a.jsx(p,{className:"h-8 w-48 mb-2"}),a.jsx(p,{className:"h-4 w-64"})]}),[1,2,3].map(e=>a.jsx(p,{className:"h-44 rounded-[var(--radius-xl)]"},e))]}),a.jsx("div",{className:"hidden lg:block lg:col-span-3",children:a.jsx(p,{className:"h-40 rounded-[var(--radius-xl)]"})})]})}function H({onRetry:e}){return a.jsxs("div",{className:"flex flex-col items-center justify-center min-h-layout-page-sm text-center px-4",children:[a.jsx("p",{className:"text-destructive font-medium mb-2",children:"Failed to load feed"}),a.jsx("p",{className:"text-muted-foreground text-sm mb-4",children:"We couldn't load the community feed. Please try again."}),e!=null&&a.jsx(m,{variant:"outline",onClick:e,children:"Retry"})]})}function J({onViewProfile:e}){const{activeTab:s,setActiveTab:t,feedTracks:r,loading:h,error:c,retry:o,playTrack:n}=D();return h?a.jsx(G,{}):c?a.jsx(H,{onRetry:o}):a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-8 animate-fadeIn pb-20 min-h-layout-page",children:[a.jsx(F,{activeTab:s,onTabChange:d=>t(d),onProfileClick:()=>e(null)}),a.jsx(A,{tracks:r,loading:!1,onPlayTrack:n}),a.jsx(R,{})]})}export{J as SocialView};