fix loadmore counter not resetting

- store load more counter in search store
This commit is contained in:
geoffrey45
2022-06-11 10:01:16 +03:00
parent 75123f5384
commit 191ac0bc7b
9 changed files with 47 additions and 27 deletions
+25
View File
@@ -29,6 +29,11 @@ function scrollOnLoad() {
export default defineStore("search", () => {
const query = useDebouncedRef(null, 600);
const currentTab = ref("tracks");
const loadCounter = reactive({
tracks: 0,
albums: 0,
artists: 0,
});
const tracks = reactive({
query: "",
@@ -118,9 +123,27 @@ export default defineStore("search", () => {
.then(() => scrollOnLoad());
}
function updateLoadCounter(type: string, value: number) {
switch (type) {
case "tracks":
loadCounter.tracks += value;
break;
case "albums":
loadCounter.albums += value;
break;
case "artists":
loadCounter.artists += value;
break;
}
}
watch(
() => query.value,
(newQuery) => {
for (const key in loadCounter) {
loadCounter[key] = 0;
}
const tabs = useTabStore();
if (tabs.current !== "search") {
@@ -183,6 +206,8 @@ export default defineStore("search", () => {
artists,
query,
currentTab,
loadCounter,
updateLoadCounter,
loadTracks,
loadAlbums,
loadArtists,