mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
refactor queu store to use play track using index
- this allows to have duplicate tracks in queue safely - store indexes in localstorage instead of track objects.
This commit is contained in:
committed by
Mungai Geoffrey
parent
f0d3c1c663
commit
c9830842ed
@@ -9,29 +9,6 @@ const uris = {
|
||||
artists: `${base_url}/artists?q=`,
|
||||
};
|
||||
|
||||
async function search(query: string) {
|
||||
state.loading.value = true;
|
||||
|
||||
const url = base_url + encodeURIComponent(query.trim());
|
||||
|
||||
const res = await fetch(url);
|
||||
|
||||
if (!res.ok) {
|
||||
const message = `An error has occured: ${res.status}`;
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
state.loading.value = false;
|
||||
|
||||
return {
|
||||
tracks: data.data[0],
|
||||
albums: data.data[1],
|
||||
artists: data.data[2],
|
||||
};
|
||||
}
|
||||
|
||||
async function searchTracks(query: string) {
|
||||
const url = uris.tracks + encodeURIComponent(query.trim());
|
||||
|
||||
@@ -43,7 +20,6 @@ async function searchTracks(query: string) {
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
console.log(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ export default function play(
|
||||
const f = store();
|
||||
|
||||
useQueue.playFromFolder(f.path, f.tracks);
|
||||
useQueue.play(f.tracks[0]);
|
||||
useQueue.play();
|
||||
break;
|
||||
case playSources.album:
|
||||
store = store as typeof album;
|
||||
const a = store();
|
||||
|
||||
useQueue.playFromAlbum(a.info.title, a.info.artist, a.tracks);
|
||||
useQueue.play(store().tracks[0]);
|
||||
useQueue.play();
|
||||
break;
|
||||
case playSources.playlist:
|
||||
store = store as typeof playlist;
|
||||
@@ -41,7 +41,7 @@ export default function play(
|
||||
if (p.tracks.length === 0) return;
|
||||
|
||||
useQueue.playFromPlaylist(p.info.name, p.info.playlistid, p.tracks);
|
||||
useQueue.play(store().tracks[0]);
|
||||
useQueue.play();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user