koel/resources/assets/js/composables/useSongListControls.ts

37 lines
917 B
TypeScript
Raw Normal View History

2024-01-18 11:13:05 +00:00
import { merge } from 'lodash'
import { reactive } from 'vue'
2024-01-18 11:13:05 +00:00
import SongListControls from '@/components/song/SongListControls.vue'
2024-01-18 11:13:05 +00:00
export const useSongListControls = (
screen: ScreenName,
configOverrides: Partial<SongListControlsConfig> | (() => Partial<SongListControlsConfig>) = {}
) => {
const defaults: SongListControlsConfig = {
play: true,
addTo: {
queue: screen !== 'Queue',
favorites: screen !== 'Favorites',
},
clearQueue: screen === 'Queue',
deletePlaylist: screen === 'Playlist',
refresh: screen === 'Playlist',
filter: [
'Queue',
'Artist',
'Album',
'Favorites',
'RecentlyPlayed',
'Playlist',
'Search.Songs'
2024-01-18 11:13:05 +00:00
].includes(screen)
}
2024-01-18 11:13:05 +00:00
const config = merge(defaults, typeof configOverrides === 'function' ? configOverrides() : configOverrides)
return {
2024-01-18 11:13:05 +00:00
SongListControls,
config: reactive(config)
}
}