282 lines
7.7 KiB
JavaScript
Raw Normal View History

2022-02-19 06:18:01 +01:00
import { createStore } from 'vuex'
import * as types from './mutation_types'
2022-02-19 06:18:01 +01:00
export default createStore({
state() {
2022-02-19 06:18:01 +01:00
return {
albums_sort: 1,
artist_albums_sort: 1,
artist_tracks_sort: 1,
2023-12-14 20:47:27 +01:00
artists_sort: 1,
composer_tracks_sort: 1,
2022-02-19 06:18:01 +01:00
config: {
buildoptions: [],
2022-02-19 06:18:01 +01:00
version: '',
websocket_port: 0
2022-02-19 06:18:01 +01:00
},
genre_tracks_sort: 1,
hide_singles: false,
hide_spotify: false,
2023-12-14 20:47:27 +01:00
lastfm: {},
2022-02-19 06:18:01 +01:00
library: {
albums: 0,
artists: 0,
2022-02-19 06:18:01 +01:00
db_playtime: 0,
songs: 0,
started_at: '01',
updated_at: '01',
2022-02-19 06:18:01 +01:00
updating: false
},
lyrics: {
content: [],
pane: false
},
notifications: {
list: [],
next_id: 1
},
2022-02-19 06:18:01 +01:00
outputs: [],
pairing: {},
2022-02-19 06:18:01 +01:00
player: {
consume: false,
item_id: 0,
item_length_ms: 0,
item_progress_ms: 0,
2023-12-14 20:47:27 +01:00
repeat: 'off',
shuffle: false,
state: 'stop',
volume: 0
},
2022-02-19 06:18:01 +01:00
queue: {
count: 0,
items: [],
version: 0
2022-02-19 06:18:01 +01:00
},
recent_searches: [],
rss_count: {},
search_source: 'library',
settings: {
categories: []
},
2022-02-19 06:18:01 +01:00
show_only_next_items: false,
show_burger_menu: false,
show_player_menu: false,
show_update_dialog: false,
spotify: {},
spotify_featured_playlists: [],
spotify_new_releases: [],
2022-02-19 06:18:01 +01:00
update_dialog_scan_kind: ''
}
},
getters: {
now_playing: (state) => {
2023-11-24 15:48:29 +01:00
const item = state.queue.items.find((e) => e.id === state.player.item_id)
return item === undefined ? {} : item
},
settings_option_recently_added_limit: (state, getters) => {
if (getters.settings_webinterface) {
const option = getters.settings_webinterface.options.find(
(elem) => elem.name === 'recently_added_limit'
)
if (option) {
return option.value
}
}
return 100
},
2023-12-14 20:47:27 +01:00
settings_option: (state) => (categoryName, optionName) => {
const category = state.settings.categories.find(
(elem) => elem.name === categoryName
)
if (!category) {
return {}
}
return category.options.find((elem) => elem.name === optionName)
},
settings_option_show_composer_for_genre: (state, getters) => {
if (getters.settings_webinterface) {
const option = getters.settings_webinterface.options.find(
2023-12-14 20:47:27 +01:00
(elem) => elem.name === 'show_composer_for_genre'
)
if (option) {
return option.value
}
}
2023-12-14 20:47:27 +01:00
return null
},
2023-12-14 20:47:27 +01:00
settings_option_show_composer_now_playing: (state, getters) => {
if (getters.settings_webinterface) {
const option = getters.settings_webinterface.options.find(
2023-12-14 20:47:27 +01:00
(elem) => elem.name === 'show_composer_now_playing'
)
if (option) {
return option.value
}
}
2023-12-14 20:47:27 +01:00
return false
},
settings_option_show_filepath_now_playing: (state, getters) => {
if (getters.settings_webinterface) {
const option = getters.settings_webinterface.options.find(
(elem) => elem.name === 'show_filepath_now_playing'
)
if (option) {
return option.value
}
}
return false
},
2023-12-14 20:47:27 +01:00
settings_webinterface: (state) => {
if (state.settings) {
return state.settings.categories.find(
(elem) => elem.name === 'webinterface'
)
}
2023-12-14 20:47:27 +01:00
return null
}
},
mutations: {
[types.UPDATE_CONFIG](state, config) {
state.config = config
},
[types.UPDATE_SETTINGS](state, settings) {
state.settings = settings
},
[types.UPDATE_LIBRARY_STATS](state, libraryStats) {
state.library = libraryStats
},
[types.UPDATE_LIBRARY_RSS_COUNT](state, count) {
state.rss_count = count
},
[types.UPDATE_OUTPUTS](state, outputs) {
state.outputs = outputs
},
[types.UPDATE_PLAYER_STATUS](state, playerStatus) {
state.player = playerStatus
},
[types.UPDATE_QUEUE](state, queue) {
state.queue = queue
},
[types.UPDATE_LYRICS](state, lyrics) {
state.lyrics.content = lyrics
},
[types.UPDATE_LASTFM](state, lastfm) {
state.lastfm = lastfm
},
[types.UPDATE_SPOTIFY](state, spotify) {
state.spotify = spotify
},
[types.UPDATE_PAIRING](state, pairing) {
state.pairing = pairing
},
[types.SPOTIFY_NEW_RELEASES](state, newReleases) {
state.spotify_new_releases = newReleases
},
[types.SPOTIFY_FEATURED_PLAYLISTS](state, featuredPlaylists) {
state.spotify_featured_playlists = featuredPlaylists
},
[types.SEARCH_SOURCE](state, searchSource) {
state.search_source = searchSource
},
[types.COMPOSER_TRACKS_SORT](state, sort) {
state.composer_tracks_sort = sort
},
[types.GENRE_TRACKS_SORT](state, sort) {
state.genre_tracks_sort = sort
},
[types.HIDE_SINGLES](state, hideSingles) {
state.hide_singles = hideSingles
},
[types.HIDE_SPOTIFY](state, hideSpotify) {
state.hide_spotify = hideSpotify
},
[types.ARTISTS_SORT](state, sort) {
state.artists_sort = sort
},
[types.ARTIST_ALBUMS_SORT](state, sort) {
state.artist_albums_sort = sort
},
[types.ARTIST_TRACKS_SORT](state, sort) {
state.artist_tracks_sort = sort
},
[types.ALBUMS_SORT](state, sort) {
state.albums_sort = sort
},
[types.SHOW_ONLY_NEXT_ITEMS](state, showOnlyNextItems) {
state.show_only_next_items = showOnlyNextItems
},
[types.SHOW_BURGER_MENU](state, showBurgerMenu) {
state.show_burger_menu = showBurgerMenu
},
[types.SHOW_PLAYER_MENU](state, showPlayerMenu) {
state.show_player_menu = showPlayerMenu
},
[types.SHOW_UPDATE_DIALOG](state, showUpdateDialog) {
state.show_update_dialog = showUpdateDialog
},
[types.UPDATE_DIALOG_SCAN_KIND](state, scanKind) {
state.update_dialog_scan_kind = scanKind
}
},
actions: {
add_notification({ commit, state }, notification) {
const newNotification = {
id: state.notifications.next_id++,
text: notification.text,
2023-12-14 20:47:27 +01:00
timeout: notification.timeout,
topic: notification.topic,
2023-12-14 20:47:27 +01:00
type: notification.type
}
2024-02-21 14:02:47 +01:00
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(() => {
2024-02-21 14:02:47 +01:00
this.dispatch('delete_notification', newNotification)
}, notification.timeout)
}
2024-02-21 14:02:47 +01:00
},
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)
}
},
2024-02-24 11:46:24 +01:00
update_settings_option({ commit, state }, option) {
2024-02-21 14:02:47 +01:00
const settingCategory = state.settings.categories.find(
2024-02-24 11:46:24 +01:00
(e) => e.name === option.category
),
settingOption = settingCategory.options.find(
(e) => e.name === option.name
)
2024-02-21 14:02:47 +01:00
settingOption.value = option.value
}
}
})