[web] Prepare for the switch to Pinia

This commit is contained in:
Alain Nussbaumer
2024-02-21 14:02:47 +01:00
parent 95521c8a48
commit 5c2845784f
8 changed files with 42 additions and 61 deletions

View File

@@ -153,15 +153,6 @@ export default createStore({
[types.UPDATE_SETTINGS](state, settings) {
state.settings = settings
},
[types.UPDATE_SETTINGS_OPTION](state, option) {
const settingCategory = state.settings.categories.find(
(e) => e.name === option.category
),
settingOption = settingCategory.options.find(
(e) => e.name === option.name
)
settingOption.value = option.value
},
[types.UPDATE_LIBRARY_STATS](state, libraryStats) {
state.library = libraryStats
},
@@ -195,40 +186,9 @@ export default createStore({
[types.SPOTIFY_FEATURED_PLAYLISTS](state, featuredPlaylists) {
state.spotify_featured_playlists = featuredPlaylists
},
[types.ADD_NOTIFICATION](state, notification) {
if (notification.topic) {
const index = state.notifications.list.findIndex(
(elem) => elem.topic === notification.topic
)
if (index >= 0) {
state.notifications.list.splice(index, 1, notification)
return
}
}
state.notifications.list.push(notification)
},
[types.DELETE_NOTIFICATION](state, notification) {
const index = state.notifications.list.indexOf(notification)
if (index !== -1) {
state.notifications.list.splice(index, 1)
}
},
[types.SEARCH_SOURCE](state, searchSource) {
state.search_source = searchSource
},
[types.ADD_RECENT_SEARCH](state, query) {
const index = state.recent_searches.findIndex((elem) => elem === query)
if (index >= 0) {
state.recent_searches.splice(index, 1)
}
state.recent_searches.splice(0, 0, query)
if (state.recent_searches.length > 5) {
state.recent_searches.pop()
}
},
[types.COMPOSER_TRACKS_SORT](state, sort) {
state.composer_tracks_sort = sort
},
@@ -279,14 +239,46 @@ export default createStore({
topic: notification.topic,
type: notification.type
}
commit(types.ADD_NOTIFICATION, newNotification)
if (newNotification.topic) {
const index = state.notifications.list.findIndex(
(elem) => elem.topic === newNotification.topic
)
if (index >= 0) {
state.notifications.list.splice(index, 1, newNotification)
return
}
}
state.notifications.list.push(newNotification)
if (notification.timeout > 0) {
setTimeout(() => {
commit(types.DELETE_NOTIFICATION, newNotification)
this.dispatch('delete_notification', newNotification)
}, notification.timeout)
}
},
add_recent_search({ commit, state }, query) {
const index = state.recent_searches.findIndex((elem) => elem === query)
if (index >= 0) {
state.recent_searches.splice(index, 1)
}
state.recent_searches.splice(0, 0, query)
if (state.recent_searches.length > 5) {
state.recent_searches.pop()
}
},
delete_notification({ commit, state }, notification) {
const index = state.notifications.list.indexOf(notification)
if (index !== -1) {
state.notifications.list.splice(index, 1)
}
},
update_settings_option({commit, state}, option) {
const settingCategory = state.settings.categories.find(
(e) => e.name === option.category
),
settingOption = settingCategory.options.find(
(e) => e.name === option.name
)
settingOption.value = option.value
}
}
})

View File

@@ -1,6 +1,5 @@
export const UPDATE_CONFIG = 'UPDATE_CONFIG'
export const UPDATE_SETTINGS = 'UPDATE_SETTINGS'
export const UPDATE_SETTINGS_OPTION = 'UPDATE_SETTINGS_OPTION'
export const UPDATE_LIBRARY_STATS = 'UPDATE_LIBRARY_STATS'
export const UPDATE_LIBRARY_RSS_COUNT = 'UPDATE_LIBRARY_RSS_COUNT'
export const UPDATE_OUTPUTS = 'UPDATE_OUTPUTS'
@@ -14,11 +13,7 @@ export const UPDATE_PAIRING = 'UPDATE_PAIRING'
export const SPOTIFY_NEW_RELEASES = 'SPOTIFY_NEW_RELEASES'
export const SPOTIFY_FEATURED_PLAYLISTS = 'SPOTIFY_FEATURED_PLAYLISTS'
export const ADD_NOTIFICATION = 'ADD_NOTIFICATION'
export const DELETE_NOTIFICATION = 'DELETE_NOTIFICATION'
export const SEARCH_SOURCE = 'SEARCH_SOURCE'
export const ADD_RECENT_SEARCH = 'ADD_RECENT_SEARCH'
export const COMPOSER_TRACKS_SORT = 'COMPOSER_TRACKS_SORT'
export const GENRE_TRACKS_SORT = 'GENRE_TRACKS_SORT'