diff --git a/src/stores/search.ts b/src/stores/search.ts index f5287210..7c5a98e2 100644 --- a/src/stores/search.ts +++ b/src/stores/search.ts @@ -50,17 +50,21 @@ export default defineStore("search", () => { * Searches for tracks, albums and artists * @param query query to search for */ - function search(query: string) { + function fetchTracks(query: string) { searchTracks(query).then((res) => { tracks.value = res.tracks; tracks.more = res.more; }); + } + function fetchAlbums(query: string) { searchAlbums(query).then((res) => { albums.value = res.albums; albums.more = res.more; }); + } + function fetchArtists(query: string) { searchArtists(query).then((res) => { artists.value = res.artists; artists.more = res.more; @@ -118,12 +122,46 @@ export default defineStore("search", () => { watch( () => query.value, (newQuery) => { - search(newQuery); const tabs = useTabStore(); if (tabs.current !== "search") { tabs.switchToSearch(); } + + switch (currentTab.value) { + case "tracks": + fetchTracks(newQuery); + break; + case "albums": + fetchAlbums(newQuery); + break; + case "artists": + fetchArtists(newQuery); + break; + default: + fetchTracks(newQuery); + break; + } + } + ); + + watch( + () => currentTab.value, + (newTab) => { + switch (newTab) { + case "tracks": + fetchTracks(query.value); + break; + case "albums": + fetchAlbums(query.value); + break; + case "artists": + fetchArtists(query.value); + break; + default: + fetchTracks(query.value); + break; + } } ); @@ -139,7 +177,6 @@ export default defineStore("search", () => { artists, query, currentTab, - search, loadTracks, loadAlbums, loadArtists, diff --git a/src/stores/tabs.ts b/src/stores/tabs.ts index 540b1134..f76b90b0 100644 --- a/src/stores/tabs.ts +++ b/src/stores/tabs.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import perks from "../composables/perks"; +import { focusCurrent } from "../composables/perks"; const tablist = { home: "home", @@ -16,7 +16,7 @@ export default defineStore("tabs", { changeTab(tab: string) { if (tab === this.tabs.queue) { setTimeout(() => { - perks.focusCurrent(); + focusCurrent(); }, 500); } this.current = tab;