(spotify) add spotify player

This commit is contained in:
2020-07-22 22:19:05 +02:00
parent 589fe8ee5f
commit 149d6eb2ad
13 changed files with 829 additions and 41 deletions

View File

@@ -7,8 +7,11 @@ Vue.use(Vuex)
export interface State {
interval: number
hasMusic: boolean
hasSpotify: boolean
dev1: string | null
dev2: string | null
accessToken: string | null
tokenExpire: Date | null
}
export interface RootActions extends ActionTree<State, State> {
@@ -16,6 +19,8 @@ export interface RootActions extends ActionTree<State, State> {
setHasMusic: (ctx: ActionContext<State, State>, payload: boolean) => void
setDev1: (ctx: ActionContext<State, State>, payload: string) => void
setDev2: (ctx: ActionContext<State, State>, payload: string) => void
setAccessToken: (ctx: ActionContext<State, State>, payload: string) => void
setTokenExpire: (ctx: ActionContext<State, State>, payload: Date) => void
}
const vuexLocal = new VuexPersistence<State>({
@@ -25,21 +30,35 @@ const vuexLocal = new VuexPersistence<State>({
const SET_INTERVAL = 'SET_INTERVAL'
const WITH_MUSIC = 'WITH_MUSIC'
const WITH_SPOTIFY = 'WITH_SPOTIFY'
const SET_DEV_1 = 'SET_DEV_1'
const SET_DEV_2 = 'SET_DEV_2'
const SET_ACCESS_TOKEN = 'SET_ACCESS_TOKEN'
const SET_TOKEN_EXPIRE = 'SET_TOKEN_EXPIRE'
const store = new Vuex.Store<State>({
state: {
interval: 5,
hasMusic: false,
hasSpotify: false,
dev1: null,
dev2: null
dev2: null,
accessToken: null,
tokenExpire: null
},
getters: {
interval: ({ interval }) => interval,
hasMusic: ({ hasMusic }) => hasMusic,
hasSpotify: ({ hasSpotify }) => hasSpotify,
dev1: ({ dev1 }) => dev1,
dev2: ({ dev2 }) => dev2
dev2: ({ dev2 }) => dev2,
accessToken: ({ accessToken }) => accessToken,
hasValidAccessToken: ({ accessToken, tokenExpire }) => {
if (!accessToken || !tokenExpire) {
return false
}
return new Date() < tokenExpire
}
},
mutations: {
[SET_INTERVAL](state, interval: number) {
@@ -48,11 +67,20 @@ const store = new Vuex.Store<State>({
[WITH_MUSIC](state, hasMusic: boolean) {
state.hasMusic = hasMusic
},
[WITH_SPOTIFY](state, hasSpotify: boolean) {
state.hasSpotify = hasSpotify
},
[SET_DEV_1](state, dev1: string) {
state.dev1 = dev1
},
[SET_DEV_2](state, dev2: string) {
state.dev2 = dev2
},
[SET_ACCESS_TOKEN](state, accessToken: string) {
state.accessToken = accessToken
},
[SET_TOKEN_EXPIRE](state, tokenExpire: Date) {
state.tokenExpire = tokenExpire
}
},
actions: {
@@ -64,11 +92,20 @@ const store = new Vuex.Store<State>({
setHasMusic({ commit }, hasMusic: boolean) {
commit(WITH_MUSIC, hasMusic)
},
setHasSpotify({ commit }, hasSpotify: boolean) {
commit(WITH_SPOTIFY, hasSpotify)
},
setDev1({ commit }, dev1: string) {
commit(SET_DEV_1, dev1)
},
setDev2({ commit }, dev2: string) {
commit(SET_DEV_2, dev2)
},
setAccessToken({ commit }, accessToken: string) {
commit(SET_ACCESS_TOKEN, accessToken)
},
setTokenExpire({ commit }, tokenExpire: Date) {
commit(SET_TOKEN_EXPIRE, tokenExpire)
}
},
plugins: [vuexLocal.plugin]