Skip to content

Commit

Permalink
feat(web): user can now add a song to the queue or favorites by press…
Browse files Browse the repository at this point in the history
…ing Enter key

fix(web): DOM now has title.
  • Loading branch information
slashtube committed Oct 27, 2023
1 parent 9a56372 commit 0303cee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
15 changes: 15 additions & 0 deletions web/src/lib/utilities.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AddFavorite } from "./favorites";
import { AddToQueue } from "./queue";

// Function to add an object to the array
export function addObjectToArray(promise, objectToAdd) {
Expand Down Expand Up @@ -33,3 +35,16 @@ export function GetToken() {
export function GetHost() {
return window.location.protocol + "//" + window.location.host;
}

export function KeyPressed(e, scope, GuildId = "", token = "", host = "") {
switch(e.key) {
case 'Enter':
switch(scope) {
case 'queue':
AddToQueue(GuildId, token, host);
case 'favorite':
AddFavorite(token, host);
}
break;
}
}
1 change: 1 addition & 0 deletions web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
GuildId = GetGuildID();
token = GetToken();
host = GetHost();
document.title = "YADMB Web UI"
});
Expand Down
3 changes: 2 additions & 1 deletion web/src/routes/favorites.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { Button } from "flowbite-svelte";
import { GetFavorites, AddFavorite, RemoveFavorite} from "../lib/favorites";
import {KeyPressed} from "../lib/utilities"
import {Modal} from "flowbite-svelte";
import {Input, Label} from "flowbite-svelte"
import {Heading, P} from "flowbite-svelte"
Expand Down Expand Up @@ -37,7 +38,7 @@
</div>
</form>
<svelte:fragment slot="footer">
<Button on:click={() => AddFavorite(token, host)}>Add</Button>
<Button on:click={() => AddFavorite(token, host)} on:keydown={(e) => (KeyPressed(e, "favorite", "", token, host))}>Add</Button>
</svelte:fragment>
</Modal>

Expand Down
20 changes: 5 additions & 15 deletions web/src/routes/queue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {A, Avatar, Button, Checkbox, Heading, Input, Label, Modal, P} from "flowbite-svelte";
import {AddToQueue, GetQueue, RemoveFromQueue} from "../lib/queue";
import {ToggleSong} from "../lib/song";
import {addObjectToArray, RemoveObjectFromArray, ClearArray} from "../lib/utilities"
import {addObjectToArray, RemoveObjectFromArray, ClearArray, KeyPressed} from "../lib/utilities"
import PlaySolid from "flowbite-svelte-icons/PlaySolid.svelte";
import PauseSolid from "flowbite-svelte-icons/PauseSolid.svelte";
import Error from "./errors.svelte"
Expand All @@ -16,12 +16,7 @@
// variables
let queue = GetQueue(GuildId, token, host);
let isPaused = queue.then((json) => {
if (json.length !== 0) {
return json[0].isPaused;
}
return false;
});
let isPaused = false;
let showModal = false;
let isPlaylist = false;
Expand Down Expand Up @@ -60,19 +55,14 @@
queue = ClearArray(queue);
isPaused = false;
break;
case Notification.Pause:
isPaused = true;
break;
case Notification.Resume:
isPaused = false;
case Notification.Pause:
isPaused = !isPaused;
break;
}
}
return () => socket.close();
});
</script>

<Button class="w-25 absolute right-9 bottom-5" on:click={() => (showModal = true)}>
Expand All @@ -95,7 +85,7 @@
</div>
</form>
<svelte:fragment slot="footer">
<Button on:click={() => AddToQueue(GuildId, token, host)}>Add</Button>
<Button on:click={() => AddToQueue(GuildId, token, host)} on:keydown={(e) => (KeyPressed(e, "queue", GuildId, token, host))}>Add</Button>
</svelte:fragment>
</Modal>

Expand Down

0 comments on commit 0303cee

Please sign in to comment.