[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.

Merge pull request #81 from flo-bit/sorting-hotfix

fix of not getting first item of sorted queue

author
Florian
committer
GitHub
date (Jul 16, 2024, 8:55 PM +0200) commit 2e7b62a3 parent 1b710b6d
+10 -8
+10 -8
backend/sessions.ts
··· 33 33 // map of session codes to session data 34 34 export const sessions = eternalVar('sessions-1234') ?? $$({} as Record<string, SessionData>); 35 35 36 + const sorter = (a: Item, b: Item) => { 37 + if (a.likes.size > b.likes.size) return -1; 38 + if (a.likes.size < b.likes.size) return 1; 39 + if (a.added > b.added) return 1; 40 + if (a.added < b.added) return -1; 41 + return 0; 42 + } 43 + 36 44 export const getAndRemoveNextVideoFromSession = (code: string) => { 37 45 const session = sessions[code]; 38 46 if (!session) { 39 47 return; 40 48 } 41 - const video = session.queue.shift(); 49 + const video = session.queue.sort(sorter).shift(); 42 50 if (video) { 43 51 session.currentlyPlaying = video; 44 52 const playerInstances = getUserPlayerInstances(session.hostId); ··· 184 192 return $$([]) 185 193 } 186 194 return always(() => { 187 - return session.queue.toSorted((a, b) => { 188 - if (a.likes.size > b.likes.size) return -1; 189 - if (a.likes.size < b.likes.size) return 1; 190 - if (a.added > b.added) return 1; 191 - if (a.added < b.added) return -1; 192 - return 0; 193 - }); 195 + return session.queue.toSorted(sorter); 194 196 }); 195 197 } 196 198