Skip to content

Commit

Permalink
fix(web): add song with priority correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Nov 16, 2023
1 parent 326a384 commit 23cf485
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions web/src/lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export function AddObjectToArray(promise, objectToAdd) {
});
}

// Function to add an object to the array as the second element
export function AddObjectToArrayAsSecond(promise, objectToAdd) {
return promise.then((array) => {
return [array[0], objectToAdd, ...array.slice(1)];
});
}

// Function to remove the first object from the array
export function RemoveFirstObjectFromArray(promise) {
return promise.then((array) => {
Expand Down
18 changes: 11 additions & 7 deletions web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import StarSolid from "flowbite-svelte-icons/StarSolid.svelte"
import ListMusicSolid from "flowbite-svelte-icons/ListMusicSolid.svelte"
import {
AddObjectToArray,
ClearArray,
RemoveFirstObjectFromArray,
SetPause,
AddObjectToArray,
ClearArray,
RemoveFirstObjectFromArray,
SetPause,
TogglePause,
GetGuildID,
GetToken,
GetGuildID,
GetToken,
GetHost,
GetPauseStatus,
GetFrames,
GetTime,
GetTime, AddObjectToArrayAsSecond,
} from "../lib/utilities"
import {onMount} from "svelte";
import {GetQueue} from "$lib/queue"
Expand Down Expand Up @@ -64,6 +64,7 @@
Clear: 4,
Finished: 5,
Playing: 6,
NewSongPriority: 7,
});
let signal = JSON.parse(e.data)
switch (signal.notification) {
Expand All @@ -90,6 +91,9 @@
case Notification.Playing:
playing = true;
break;
case Notification.NewSongPriority:
queue = AddObjectToArrayAsSecond(queue, signal.song);
break;
}
}
Expand Down

0 comments on commit 23cf485

Please sign in to comment.