create re-usable components

This commit is contained in:
geoffrey45
2022-01-22 12:04:33 +03:00
parent f6787421c3
commit 7945c04a06
9 changed files with 283 additions and 181 deletions
+17 -6
View File
@@ -3,15 +3,26 @@ import state from "./state.js";
const base_url = "http://0.0.0.0:9876/search?q=";
async function search(query) {
state.loading.value = true;
const url = base_url + encodeURIComponent(query);
const res = await fetch(url);
const json = await res.json();
state.search_tracks.value = json.songs;
state.search_albums.value = json.albums;
state.search_artists.value = json.artists;
console.log(state.search_tracks.value);
if (!res.ok) {
const message = `An error has occured: ${res.status}`;
throw new Error(message);
}
const data = await res.json();
console.log(data.data[1]);
state.loading.value = false;
return {
tracks: data.data[0],
albums: data.data[1],
artists: data.data[2],
};
}
export default search;
export default search;