diff --git a/webui/src/components/TheSidebar.vue b/webui/src/components/TheSidebar.vue index e96bbe1..6e0d331 100644 --- a/webui/src/components/TheSidebar.vue +++ b/webui/src/components/TheSidebar.vue @@ -102,6 +102,10 @@ export default defineComponent({ left: 30px; } +a[aria-label="spotify home"] i { + transform: rotate(-90deg); +} + .theme_toggler { transition: border 200ms ease-in-out; } diff --git a/webui/src/components/pages/Spotify.vue b/webui/src/components/pages/Spotify.vue new file mode 100644 index 0000000..c2c8567 --- /dev/null +++ b/webui/src/components/pages/Spotify.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/webui/src/data/sidebar.js b/webui/src/data/sidebar.js index 8306c72..065b25c 100644 --- a/webui/src/data/sidebar.js +++ b/webui/src/data/sidebar.js @@ -27,6 +27,13 @@ export const links = [ icon: 'star', label: 'sidebar.favorites', auth: true + }, + { + name: 'spotify-home', + ariaLabel: 'spotify home', + routerName: 'Spotify Home', + icon: 'contactless', + label: 'sidebar.spotify', }, { name: 'analyzer', diff --git a/webui/src/lang/en.mjs b/webui/src/lang/en.mjs index 1f05a12..8487e09 100644 --- a/webui/src/lang/en.mjs +++ b/webui/src/lang/en.mjs @@ -500,6 +500,7 @@ const en = { charts: 'charts', favorites: 'favorites', linkAnalyzer: 'link analyzer', + spotify: 'spotify home', settings: 'settings', logs: 'logs', about: 'about' diff --git a/webui/src/router.js b/webui/src/router.js index db8b61e..a7cdfc8 100644 --- a/webui/src/router.js +++ b/webui/src/router.js @@ -14,6 +14,7 @@ import LinkAnalyzer from '@/components/pages/LinkAnalyzer.vue' import Search from '@/components/pages/Search.vue' import Settings from '@/components/pages/Settings.vue' import Tracklist from '@/components/pages/Tracklist.vue' +import Spotify from '@/components/pages/Spotify.vue' import { fetchData } from '@/utils/api' import EventBus from '@/utils/EventBus' @@ -98,6 +99,11 @@ const routes = [ name: 'Spotify Features', component: InfoSpotifyFeatures }, + { + path: '/spotify-home', + name: 'Spotify Home', + component: Spotify + }, { path: '/settings', name: 'Settings', diff --git a/webui/src/use/spotifyplaylists.js b/webui/src/use/spotifyplaylists.js new file mode 100644 index 0000000..7d7da76 --- /dev/null +++ b/webui/src/use/spotifyplaylists.js @@ -0,0 +1,49 @@ +import { ref, computed } from '@vue/composition-api' +import store from '@/store' +import { fetchData } from '@/utils/api' +import { toast } from '@/utils/toasts' +import i18n from '@/plugins/i18n' +import { SPOTIFY_STATUS } from '@/constants' + +const favoriteSpotifyPlaylists = ref([]) +const isLoggedWithSpotify = computed(() => store.getters.isLoggedWithSpotify) + +const isRefreshingSpotifyPlaylists = ref(false) + +const setSpotifyPlaylists = response => { + if (response.error) { + favoriteSpotifyPlaylists.value = [] + switch (response.error) { + case 'spotifyNotEnabled': + store.dispatch('setSpotifyStatus', SPOTIFY_STATUS.DISABLED).catch(console.error) + break + case 'wrongSpotifyUsername': + toast(i18n.t('toasts.wrongSpotifyUsername', { username: response.username }), 'person_off') + break + default: + break + } + return + } + + favoriteSpotifyPlaylists.value = response || [] +} + +const refreshSpotifyPlaylists = async () => { + isRefreshingSpotifyPlaylists.value = true + await store.dispatch('refreshSpotifyStatus') + + if (isLoggedWithSpotify.value) { + const spotifyUser = store.getters.getSpotifyUser.id + + fetchData('getUserSpotifyPlaylists', { spotifyUser }).then(setSpotifyPlaylists).catch(console.error) + } else { + favoriteSpotifyPlaylists.value = [] + } +} + +export const useSpotifyPlaylists = () => ({ + favoriteSpotifyPlaylists, + isRefreshingSpotifyPlaylists, + refreshSpotifyPlaylists +})