[READ-ONLY] Mirror of https://github.com/flo-bit/youtube-party-dj. democratic youtube player, everyone can vote and add songs, uni project, made with uix
0

Configure Feed

Select the types of activity you want to include in your feed.

changes in sorting and queue handling

+13 -2
+13 -2
backend/sessions.ts
··· 22 22 // map of session codes to session data 23 23 export const sessions = eternalVar('sessions-1234') ?? $$({} as Record<string, SessionData>); 24 24 25 + const sorter = (a: Item, b: Item) => { 26 + if (a.likes.size > b.likes.size) return -1; 27 + if (a.likes.size < b.likes.size) return 1; 28 + if (a.added > b.added) return 1; 29 + if (a.added < b.added) return -1; 30 + return 0; 31 + } 32 + 25 33 export const getAndRemoveNextVideoFromSession = (code: string) => { 26 34 const session = sessions[code]; 27 35 console.log(session); 28 36 if (!session) { 29 37 return; 30 38 } 31 - console.log(session.queue); 32 - const video = session.queue.shift(); 39 + 40 + // sort queue by likes and added date, get and remove the first video 41 + const video = session.queue.sort(sorter).shift(); 33 42 if (video) { 34 43 session.currentlyPlaying = video; 44 + } else { 45 + session.currentlyPlaying = null; 35 46 } 36 47 return video; 37 48 }