- Relocated code from App.vue to their respective stores
- Linked to privacy page in wiki (related to #15)
This commit is contained in:
Shiny Nematoda 2022-09-09 18:49:13 +00:00
parent 1b5ee1d2d5
commit 44db54737b
No known key found for this signature in database
GPG key ID: 6506D50F5613A42D
17 changed files with 666 additions and 620 deletions

View file

@ -1,6 +1,11 @@
import { ref, reactive } from 'vue';
import { defineStore } from 'pinia';
import { useNav } from '@/stores/misc.js';
import { getJsonPiped, getJsonHyp } from '@/scripts/fetch.js';
import { useRoute } from '@/scripts/util.js';
export const useResults = defineStore('results', () => {
const items = ref({}),
search = ref('');
@ -11,12 +16,43 @@ export const useResults = defineStore('results', () => {
}
function resetItems() {
useArtist().reset();
for (let i in items.value) {
items.value[i] = undefined;
}
}
return { items, search, setItem, resetItems };
async function getExplore() {
const json = await getJsonHyp('/explore');
console.log(json);
useArtist().reset();
setItem('songs', { items: json.trending });
setItem('albums', { items: json.albums_and_singles });
}
async function getAlbum(e) {
console.log('Album: ', e);
const hash = new URLSearchParams(e.substring(e.indexOf('?'))).get('list'),
json = await getJsonPiped('/playlists/' + hash);
console.log(json, json.relatedStreams);
resetItems();
setItem('songs', {
items: json.relatedStreams,
title: json.name,
});
useRoute(e);
useNav().state.page = 'home';
useArtist().reset();
}
return { items, search, setItem, resetItems, getExplore, getAlbum };
});
export const useArtist = defineStore('artist', () => {
@ -40,5 +76,32 @@ export const useArtist = defineStore('artist', () => {
}
}
return { state, set, reset };
async function getArtist(e) {
console.log(e);
e = e.replace('/channel/', '');
const json = await getJsonHyp('/channel/' + e),
results = useResults();
console.log(json);
results.resetItems();
for (let i in json.items) {
results.setItem(i, { items: json.items[i] });
}
console.log(results.items);
json.items = undefined;
reset();
set(json);
useRoute('/channel/' + e);
useNav().state.page = 'home';
}
return { state, set, reset, getArtist };
});