Skip to content

Commit 9cb9c89

Browse files
committed
ui bugs fixed
1 parent 5d3c167 commit 9cb9c89

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

MyMusicClientSveltePwa/src/lib/components/Modals.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
}
3333
34-
async function handleCreatePlaylistSubmit(e) {
34+
async function handleCreatePlaylistSubmit(event) {
3535
event.preventDefault();
3636
const formData = new FormData(event.target);
3737
var response = await createPlaylist(formData);
@@ -42,11 +42,12 @@
4242
// Close modal
4343
const modalElement = document.getElementById('createPlaylistModal');
4444
const modalInstance = bootstrap.Modal.getInstance(modalElement);
45+
46+
// clear form
4547
modalInstance.hide();
4648
4749
// clear form
4850
event.target.reset();
49-
5051
} else {
5152
alert(`Failed to create playlist: ${response.data}`);
5253
}

MyMusicClientSveltePwa/src/lib/components/PlayerBar.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
<div class="container-fluid player-bar mb-2">
2020
<div class="row space-between">
21-
<div class="image-placeholder col-2 col-md-2 col-lg-2" style="--url: url({getImageUrl($currentSong.thumbnail_path)});">
21+
<div class="image-placeholder col-2 col-md-2 col-lg-2" style="--url: url({$currentSong.id !== -999 ? getImageUrl($currentSong.thumbnail_path) : "" });">
2222
&nbsp;
2323
</div>
24-
<div class="col-8 col-md-8 col-lg-9" style="background: linear-gradient(to right, #1DB954 {$playPercentage}%, #2c2c2c {$playPercentage}%);">
25-
<button type="button" class="btn clickable-text" data-bs-toggle="{$currentSong ? "modal" : ""}" data-bs-target="{$currentSong ? "#songControlModal" : ""}">
26-
{#if $currentSong}
24+
<div class="col-8 col-md-8 col-lg-9" style="background: linear-gradient(to right, #1DB954 {($currentSong && $currentSong.id !== -999) ? $playPercentage:0}%, #2c2c2c {($currentSong && $currentSong.id !== -999) ? $playPercentage:0}%);">
25+
<button type="button" class="btn clickable-text" data-bs-toggle="{($currentSong && $currentSong.id !== -999) ? "modal" : ""}" data-bs-target="{($currentSong && $currentSong.id !== -999) ? "#songControlModal" : ""}">
26+
{#if $currentSong && $currentSong.id !== -999}
2727
{$currentSong.name}
2828
{:else}
2929
No song playing
@@ -32,7 +32,7 @@
3232
</div>
3333
<div class="col-2 col-md-2 col-lg-1">
3434
<button on:click={togglePlay} class="btn play-button w-100">
35-
{#if $currentSong && $isPlaying && !$isLoading}
35+
{#if ($currentSong && $currentSong.id !== -999) && $isPlaying && !$isLoading}
3636
<i class="fa-solid fa-pause"></i>
3737
{:else if !$isLoading && !$isPlaying}
3838
<i class="fa-solid fa-play"></i>

MyMusicClientSveltePwa/src/lib/scripts/playbackService.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export function initializePlaybackService() {
5050
songIndex = getCurrentSongIndex();
5151
isPlaying.set(false);
5252
setCurrentTime(getCurrentSongTime());
53-
playOrPauseSong(playlistSongs[songIndex].id);
53+
54+
if(playlistSongs.length > 0 && songIndex >= 0 && songIndex <= playlistSongs.length){
55+
playOrPauseSong(playlistSongs[songIndex].id);
56+
}
5457
}
5558

5659
audioElement.addEventListener("play", () => {
@@ -74,10 +77,15 @@ export function initializePlaybackService() {
7477
updateMediaSessionPlaybackState(false);
7578
});
7679

77-
// audioElement.addEventListener("playing", () => {
78-
// isPlaying.set(true);
79-
// updateMediaSessionPlaybackState(true);
80-
// });
80+
audioElement.addEventListener("playing", () => {
81+
if(!get(isPlaying)){
82+
isPlaying.set(true);
83+
}
84+
if(get(isLoading)){
85+
isLoading.set(false);
86+
}
87+
updateMediaSessionPlaybackState(true);
88+
});
8189

8290
audioElement.addEventListener("timeupdate", () => {
8391
const percentage = (audioElement.currentTime / audioElement.duration) * 100;
@@ -104,10 +112,6 @@ export function initializePlaybackService() {
104112
});
105113
}
106114

107-
export function stopPlayback() {
108-
playOrPauseSong(currentSong.id);
109-
}
110-
111115
export function nextSong() {
112116
songIndex = (songIndex + 1) % playlistSongs.length; // Loop back to start if at end of playlist
113117
const nextSong = playlistSongs[songIndex];

MyMusicClientSveltePwa/src/lib/scripts/playlistService.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { writable, get } from "svelte/store";
22
import { getCachedPlaylists, setCachedPlaylists, setPlaylistSongs, getCachedPlaylistSongs, appConfiguration, getConfiguration, getCurrentPlaylistId } from "./storageService";
33
import { fetchPlaylists, fetchPlaylistSongs, fetchNewPlaylist, fetchNewPlaylistSongs, deletePlaylist } from "./api";
44
import { componentParams, navigateTo } from "./routeService";
5-
import { playOrPauseSong, setPlaylists, currentSong } from "./playbackService";
5+
import { playOrPauseSong, setPlaylists, currentSong, playPercentage } from "./playbackService";
66

77
export const playlistsStore = writable([]);
88

@@ -41,8 +41,6 @@ export async function initializePlaylistService() {
4141
}
4242
updateInterval = config.fetchTimer * 1000; // Need to multiply by 1000 to get milliseconds
4343

44-
console.log("Update interval set to:", updateInterval, "ms");
45-
4644
intervalId = setInterval(() => {
4745
if (isUpdating) return; // Prevent multiple updates at the same time
4846

@@ -73,12 +71,15 @@ export async function deleteCurrentPlaylist() {
7371
if (result.success) {
7472
const currentPlaylist = getCurrentPlaylistId();
7573

76-
// If the deleted playlist is the current playing playlist, stop playback
74+
// If the deleted playlist is the current playing playlist, stop playback
7775
if (currentPlaylist === playlistId) {
7876
// stop playback
7977
playOrPauseSong(null);
8078
setPlaylists(0);
79+
currentSong.set({id: -999, title: "", artist: "", album: "", source_id: ""});
8180
}
81+
82+
playPercentage.set(0);
8283

8384
// Remove playlist from cached playlists
8485
cachedPlaylists.splice(playlistIndex, 1);
@@ -111,11 +112,6 @@ async function backgroundUpdate() {
111112
const cachedSongs = getCachedPlaylistSongs(playlistId);
112113
const lastKnowSongPosition = cachedSongs.length;
113114

114-
if (playlistId === 22) {
115-
console.log("Updating playlist:", playlistId, "Last known song position:", lastKnowSongPosition);
116-
console.log("Cached songs:", cachedSongs);
117-
}
118-
119115
const newSongs = await fetchNewPlaylistSongs(playlistId, lastKnowSongPosition);
120116
if (newSongs.length > 0) {
121117
const updatedSongs = [...cachedSongs, ...newSongs];

0 commit comments

Comments
 (0)