Skip to content

Commit

Permalink
refactor(loading): move loading to utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed May 7, 2024
1 parent b60f0e4 commit b8ce8bb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions static/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const playPauseToggleEl = document.getElementById("play"),
songDurationEl = document.getElementById("song-duration"),
songCurrentTimeEl = document.getElementById("song-current-time"),
songImageEl = document.getElementById("song-image"),
loadingEl = document.getElementById("loading"),
audioPlayerEl = document.getElementById("audio-player"),
muzikkContainerEl = document.getElementById("muzikk");

Expand Down Expand Up @@ -144,7 +143,7 @@ async function fetchMusic(youtubeId) {
audioPlayerEl.load();
}

async function playYTSongById(id, thumbnailUrl, title, artist) {
async function playYTSong(id, thumbnailUrl, title, artist) {
const videoData = { id, thumbnailUrl, title, artist };
await fetchMusic(videoData.id);
setMediaSession(videoData);
Expand Down Expand Up @@ -250,7 +249,7 @@ audioPlayerEl.addEventListener("progress", () => {
});

window.Player = {
playYTSongById,
playYTSong,
showPlayer,
hidePlayer,
};
2 changes: 2 additions & 0 deletions static/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const loadingEl = document.getElementById("loading");

function showLoading() {
loadingEl.classList.remove("hidden");
}
Expand Down
2 changes: 1 addition & 1 deletion views/pages/search_results.templ
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ templ searchResults(results []SearchResult) {
}

script playSong(id, thumbnailUrl, title, artist string) {
window.playYTSongById(id, thumbnailUrl, title, artist);
window.Player.playYTSong(id, thumbnailUrl, title, artist);
}

0 comments on commit b8ce8bb

Please sign in to comment.