mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
separate search tab requests
This commit is contained in:
+40
-3
@@ -50,17 +50,21 @@ export default defineStore("search", () => {
|
|||||||
* Searches for tracks, albums and artists
|
* Searches for tracks, albums and artists
|
||||||
* @param query query to search for
|
* @param query query to search for
|
||||||
*/
|
*/
|
||||||
function search(query: string) {
|
function fetchTracks(query: string) {
|
||||||
searchTracks(query).then((res) => {
|
searchTracks(query).then((res) => {
|
||||||
tracks.value = res.tracks;
|
tracks.value = res.tracks;
|
||||||
tracks.more = res.more;
|
tracks.more = res.more;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchAlbums(query: string) {
|
||||||
searchAlbums(query).then((res) => {
|
searchAlbums(query).then((res) => {
|
||||||
albums.value = res.albums;
|
albums.value = res.albums;
|
||||||
albums.more = res.more;
|
albums.more = res.more;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchArtists(query: string) {
|
||||||
searchArtists(query).then((res) => {
|
searchArtists(query).then((res) => {
|
||||||
artists.value = res.artists;
|
artists.value = res.artists;
|
||||||
artists.more = res.more;
|
artists.more = res.more;
|
||||||
@@ -118,12 +122,46 @@ export default defineStore("search", () => {
|
|||||||
watch(
|
watch(
|
||||||
() => query.value,
|
() => query.value,
|
||||||
(newQuery) => {
|
(newQuery) => {
|
||||||
search(newQuery);
|
|
||||||
const tabs = useTabStore();
|
const tabs = useTabStore();
|
||||||
|
|
||||||
if (tabs.current !== "search") {
|
if (tabs.current !== "search") {
|
||||||
tabs.switchToSearch();
|
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,
|
artists,
|
||||||
query,
|
query,
|
||||||
currentTab,
|
currentTab,
|
||||||
search,
|
|
||||||
loadTracks,
|
loadTracks,
|
||||||
loadAlbums,
|
loadAlbums,
|
||||||
loadArtists,
|
loadArtists,
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import perks from "../composables/perks";
|
import { focusCurrent } from "../composables/perks";
|
||||||
|
|
||||||
const tablist = {
|
const tablist = {
|
||||||
home: "home",
|
home: "home",
|
||||||
@@ -16,7 +16,7 @@ export default defineStore("tabs", {
|
|||||||
changeTab(tab: string) {
|
changeTab(tab: string) {
|
||||||
if (tab === this.tabs.queue) {
|
if (tab === this.tabs.queue) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
perks.focusCurrent();
|
focusCurrent();
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
this.current = tab;
|
this.current = tab;
|
||||||
|
|||||||
Reference in New Issue
Block a user