koel/resources/assets/js/components/layout/ModalWrapper.vue

68 lines
2.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<div class="modal-wrapper" :class="{ overlay: showingModalName }">
2022-04-15 17:00:08 +00:00
<CreateSmartPlaylistForm v-if="showingModalName === 'create-smart-playlist-form'" @close="close"/>
2022-07-10 15:17:48 +00:00
<EditSmartPlaylistForm v-if="showingModalName === 'edit-smart-playlist-form'" @close="close"/>
2022-04-15 17:00:08 +00:00
<AddUserForm v-if="showingModalName === 'add-user-form'" @close="close"/>
2022-07-10 15:17:48 +00:00
<EditUserForm v-if="showingModalName === 'edit-user-form'" @close="close"/>
<EditSongForm v-if="showingModalName === 'edit-song-form'" @close="close"/>
<AboutKoel v-if="showingModalName === 'about-koel'" @close="close"/>
2022-04-15 14:24:30 +00:00
</div>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-07-20 08:00:02 +00:00
import { defineAsyncComponent, ref } from 'vue'
import { arrayify, eventBus, provideReadonly } from '@/utils'
2022-07-10 15:17:48 +00:00
import { EditSongFormInitialTabKey, PlaylistKey, SongsKey, UserKey } from '@/symbols'
2022-04-15 14:24:30 +00:00
declare type ModalName =
| 'create-smart-playlist-form'
| 'edit-smart-playlist-form'
| 'add-user-form'
| 'edit-user-form'
| 'edit-song-form'
| 'about-koel'
2022-04-15 14:24:30 +00:00
const CreateSmartPlaylistForm = defineAsyncComponent(() => import('@/components/playlist/smart-playlist/SmartPlaylistCreateForm.vue'))
const EditSmartPlaylistForm = defineAsyncComponent(() => import('@/components/playlist/smart-playlist/SmartPlaylistEditForm.vue'))
2022-04-23 21:36:19 +00:00
const AddUserForm = defineAsyncComponent(() => import('@/components/user/UserAddForm.vue'))
2022-04-23 21:46:25 +00:00
const EditUserForm = defineAsyncComponent(() => import('@/components/user/UserEditForm.vue'))
2022-04-21 09:38:24 +00:00
const EditSongForm = defineAsyncComponent(() => import('@/components/song/SongEditForm.vue'))
2022-04-24 08:29:14 +00:00
const AboutKoel = defineAsyncComponent(() => import('@/components/meta/AboutKoelModal.vue'))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const showingModalName = ref<ModalName | null>(null)
2022-04-15 14:24:30 +00:00
2022-07-10 15:17:48 +00:00
const close = () => (showingModalName.value = null)
const playlistToEdit = ref<Playlist>()
const userToEdit = ref<User>()
const songsToEdit = ref<Song[]>()
const editSongFormInitialTab = ref<EditSongFormTabName>('details')
2022-07-20 08:00:02 +00:00
provideReadonly(PlaylistKey, playlistToEdit, false)
provideReadonly(UserKey, userToEdit)
provideReadonly(SongsKey, songsToEdit, false)
provideReadonly(EditSongFormInitialTabKey, editSongFormInitialTab)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
eventBus.on({
'MODAL_SHOW_ABOUT_KOEL': () => (showingModalName.value = 'about-koel'),
2022-04-15 17:00:08 +00:00
'MODAL_SHOW_ADD_USER_FORM': () => (showingModalName.value = 'add-user-form'),
'MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM': () => (showingModalName.value = 'create-smart-playlist-form'),
2022-04-15 14:24:30 +00:00
2022-07-10 15:17:48 +00:00
'MODAL_SHOW_EDIT_SMART_PLAYLIST_FORM': (playlist: Playlist) => {
playlistToEdit.value = playlist
2022-04-15 17:00:08 +00:00
showingModalName.value = 'edit-smart-playlist-form'
},
2022-04-15 14:24:30 +00:00
2022-07-10 15:17:48 +00:00
'MODAL_SHOW_EDIT_USER_FORM': (user: User) => {
userToEdit.value = user
2022-04-15 17:00:08 +00:00
showingModalName.value = 'edit-user-form'
},
2022-04-15 14:24:30 +00:00
2022-07-10 15:17:48 +00:00
'MODAL_SHOW_EDIT_SONG_FORM': (songs: Song | Song[], initialTab: EditSongFormTabName = 'details') => {
songsToEdit.value = arrayify(songs)
editSongFormInitialTab.value = initialTab
2022-04-15 17:00:08 +00:00
showingModalName.value = 'edit-song-form'
2022-04-15 14:24:30 +00:00
}
})
</script>