feat: isolated downloads and slim sidebar logic to store
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { getInitialPreviewVolume, checkInitialSlimDownloads, checkInitialSlimSidebar } from '@/data/settings'
|
||||
|
||||
/**
|
||||
* @typedef {object} AppInfo
|
||||
* @property {string} currentCommit
|
||||
@@ -5,6 +7,8 @@
|
||||
* @property {boolean} updateAvailable
|
||||
* @property {string} deemixVersion
|
||||
* @property {number} previewVolume
|
||||
* @property {boolean} hasSlimDownloads
|
||||
* @property {boolean} hasSlimSidebar
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -15,7 +19,9 @@ const state = () => ({
|
||||
latestCommit: null,
|
||||
updateAvailable: false,
|
||||
deemixVersion: null,
|
||||
previewVolume: Number(localStorage.getItem('previewVolume')) || 100
|
||||
previewVolume: getInitialPreviewVolume(),
|
||||
hasSlimDownloads: checkInitialSlimDownloads(),
|
||||
hasSlimSidebar: checkInitialSlimSidebar()
|
||||
})
|
||||
|
||||
const actions = {
|
||||
@@ -36,6 +42,27 @@ const actions = {
|
||||
setPreviewVolume({ commit }, payload) {
|
||||
commit('SET_PREVIEW_VOLUME', payload)
|
||||
localStorage.setItem('previewVolume', payload.toString())
|
||||
},
|
||||
/**
|
||||
* @param {any} action
|
||||
* @param {AppInfo['hasSlimDownloads']} payload
|
||||
*/
|
||||
setSlimDownloads({ commit }, payload) {
|
||||
commit('SET_SLIM_DOWNLOADS', payload)
|
||||
localStorage.setItem('slimDownloads', payload.toString())
|
||||
},
|
||||
/**
|
||||
* @param {any} action
|
||||
* @param {AppInfo['hasSlimSidebar']} payload
|
||||
*/
|
||||
setSlimSidebar({ commit }, payload) {
|
||||
commit('SET_SLIM_SIDEBAR', payload)
|
||||
localStorage.setItem('slimSidebar', payload.toString())
|
||||
|
||||
// Moves all toast messages when the option changes
|
||||
Array.from(document.getElementsByClassName('toastify')).forEach(toast => {
|
||||
toast.style.transform = `translate(${payload ? '3rem' : '14rem'}, 0)`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,47 +73,71 @@ const getters = {
|
||||
*/
|
||||
getAppInfo: state => state,
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo} state
|
||||
* @returns {AppInfo['previewVolume']}
|
||||
*/
|
||||
getPreviewVolume: state => state.previewVolume
|
||||
getPreviewVolume: state => state.previewVolume,
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @returns {AppInfo['hasSlimDownloads']}
|
||||
*/
|
||||
getSlimDownloads: state => state.hasSlimDownloads,
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @returns {AppInfo['hasSlimSidebar']}
|
||||
*/
|
||||
getSlimSidebar: state => state.hasSlimSidebar
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['currentCommit']} payload
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['currentCommit']} payload
|
||||
*/
|
||||
SET_CURRENT_COMMIT(state, payload) {
|
||||
state.currentCommit = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['latestCommit']} payload
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['latestCommit']} payload
|
||||
*/
|
||||
SET_LATEST_COMMIT(state, payload) {
|
||||
state.latestCommit = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['updateAvailable']} payload
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['updateAvailable']} payload
|
||||
*/
|
||||
SET_UPDATE_AVAILABLE(state, payload) {
|
||||
state.updateAvailable = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['deemixVersion']} payload
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['deemixVersion']} payload
|
||||
*/
|
||||
SET_DEEMIX_VERSION(state, payload) {
|
||||
state.deemixVersion = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['previewVolume']} payload
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['previewVolume']} payload
|
||||
*/
|
||||
SET_PREVIEW_VOLUME(state, payload) {
|
||||
state.previewVolume = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['hasSlimDownloads']} payload
|
||||
*/
|
||||
SET_SLIM_DOWNLOADS(state, payload) {
|
||||
state.hasSlimDownloads = payload
|
||||
},
|
||||
/**
|
||||
* @param {AppInfo} state
|
||||
* @param {AppInfo['hasSlimSidebar']} payload
|
||||
*/
|
||||
SET_SLIM_SIDEBAR(state, payload) {
|
||||
state.hasSlimSidebar = payload
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user