Skip to content

Commit 78397d6

Browse files
committed
Tweak and better skip track
1 parent 10a8332 commit 78397d6

5 files changed

Lines changed: 34 additions & 19 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stronk-tech/react-librespot-controller",
33
"description": "`go-librespot` squeezebox-alike web frontend for small touchscreens",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",
77
"files": [

src/components/Info/Header.css

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,32 @@
7777

7878
.spotify-player-connected-icon {
7979
font-size: 2rem;
80-
color: var(--blue);
80+
color: var(--lightest);
8181
}
8282

8383
.spotify-player-connected-icon.spotify-player-disconnected {
8484
color: var(--red);
8585
}
8686

8787
.spotify-player-connected-icon.spotify-player-rotating {
88-
animation: spin 2s linear infinite;
88+
animation: rotate 2s linear infinite;
89+
color: var(--blue);
8990
}
9091

91-
@keyframes spin {
92+
@keyframes rotate {
9293
0% {
9394
transform: rotate(0deg);
9495
}
96+
25% {
97+
transform: rotate(20deg);
98+
}
99+
50% {
100+
transform: rotate(0deg);
101+
}
102+
75% {
103+
transform: rotate(-20deg);
104+
}
95105
100% {
96-
transform: rotate(360deg);
106+
transform: rotate(-0deg);
97107
}
98108
}

src/components/Info/TextInfo.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ const TextInfo = ({ track, isStopped, isConnected, error }) => {
1313
)
1414
}
1515

16-
// Tries to format the release date to YYYY-MM-DD
16+
// Tries to format the release date to YYYY-MM-DD or partial formats if data is incomplete
1717
const formatReleaseDate = (releaseDate) => {
18-
if (!releaseDate || !releaseDate.length){
18+
if (!releaseDate || !releaseDate.length) {
1919
return "Unknown";
2020
}
21+
2122
// Match the format with optional spaces: "year:YYYY month:MM day:DD"
22-
const match = releaseDate.match(/year:\s*(\d+)\s*month:\s*(\d+)\s*day:\s*(\d+)/);
23+
const match = releaseDate.match(/year:\s*(\d+)?\s*month:\s*(\d+)?\s*day:\s*(\d+)?/);
24+
2325
if (match) {
24-
const year = match[1];
25-
const month = match[2].padStart(2, "0"); // Ensure two-digit month
26-
const day = match[3].padStart(2, "0"); // Ensure two-digit day
27-
return `${year}-${month}-${day}`;
26+
const year = match[1] || "";
27+
const month = match[2] ? match[2].padStart(2, "0") : "";
28+
const day = match[3] ? match[3].padStart(2, "0") : "";
29+
30+
// Construct the result based on available parts
31+
let result = year;
32+
if (month) result += `-${month}`;
33+
if (day) result += `-${day}`;
34+
35+
return result || "Unknown"; // Fallback to "Unknown" if no valid parts
2836
}
2937
return releaseDate; // Return as-is for invalid formats
3038
};

src/hooks/useLibrespot.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
seek,
99
play,
1010
previousTrack,
11+
nextTrack,
1112
setVolume,
1213
toggleShuffleContext,
1314
getPlaylists
@@ -117,11 +118,7 @@ const useLibrespot = (websocketUrl, apiBaseUrl) => {
117118
console.error("Unable to skip track, as the player is inactive.");
118119
return;
119120
}
120-
if (!isPlaying) {
121-
resume(apiBaseUrl);
122-
}
123-
seek(apiBaseUrl, trackInfo.duration - 5);
124-
setRemotePosition(trackInfo.duration - 5);
121+
nextTrack(apiBaseUrl);
125122
};
126123

127124
//

src/util/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ export const pause = async (baseUrl) =>
5353
export const togglePlayPause = async (baseUrl) =>
5454
await callApi(`${baseUrl}/player/playpause`, { method: "POST" });
5555

56-
export const nextTrack = async (baseUrl, uri) =>
56+
export const nextTrack = async (baseUrl) =>
5757
await callApi(`${baseUrl}/player/next`, {
5858
method: "POST",
5959
headers: { "Content-Type": "application/json" },
60-
body: JSON.stringify({ uri }),
60+
body: JSON.stringify({}),
6161
});
6262

6363
export const previousTrack = async (baseUrl) =>

0 commit comments

Comments
 (0)