mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
feat: merge useScreen into useRouter
This commit is contained in:
parent
bc5081cd0f
commit
758322988a
10 changed files with 38 additions and 40 deletions
|
@ -43,8 +43,8 @@ const shuffle = () => trigger(async () => {
|
|||
go('queue')
|
||||
})
|
||||
|
||||
const viewAlbumDetails = () => trigger(() => router.go(`album/${album.value!.id}`))
|
||||
const viewArtistDetails = () => trigger(() => router.go(`artist/${album.value!.artist_id}`))
|
||||
const viewAlbumDetails = () => trigger(() => go(`album/${album.value!.id}`))
|
||||
const viewArtistDetails = () => trigger(() => go(`artist/${album.value!.artist_id}`))
|
||||
const download = () => trigger(() => downloadService.fromAlbum(album.value!))
|
||||
|
||||
eventBus.on('ALBUM_CONTEXT_MENU_REQUESTED', async (e, _album) => {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed, ref, toRef, watch } from 'vue'
|
||||
import { albumStore, preferenceStore as preferences } from '@/stores'
|
||||
import { useInfiniteScroll, useScreen } from '@/composables'
|
||||
import { useInfiniteScroll, useRouter } from '@/composables'
|
||||
|
||||
import AlbumCard from '@/components/album/AlbumCard.vue'
|
||||
import AlbumCardSkeleton from '@/components/ui/skeletons/ArtistAlbumCardSkeleton.vue'
|
||||
|
@ -63,7 +63,7 @@ const fetchAlbums = async () => {
|
|||
loading.value = false
|
||||
}
|
||||
|
||||
useScreen('Albums').onScreenActivated(async () => {
|
||||
useRouter().onScreenActivated('Albums', async () => {
|
||||
if (!initialized) {
|
||||
viewMode.value = preferences.albumsViewMode || 'thumbnails'
|
||||
initialized = true
|
||||
|
|
|
@ -39,7 +39,7 @@ import { computed, ref, toRef } from 'vue'
|
|||
import { logger, pluralize, secondsToHumanReadable } from '@/utils'
|
||||
import { commonStore, queueStore, songStore } from '@/stores'
|
||||
import { playbackService } from '@/services'
|
||||
import { useMessageToaster, useRouter, useScreen, useSongList } from '@/composables'
|
||||
import { useMessageToaster, useRouter, useSongList } from '@/composables'
|
||||
|
||||
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
||||
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
|
||||
|
@ -65,7 +65,7 @@ const {
|
|||
} = useSongList(toRef(songStore.state, 'songs'))
|
||||
|
||||
const { toastError } = useMessageToaster()
|
||||
const { go } = useRouter()
|
||||
const { go, onScreenActivated } = useRouter()
|
||||
|
||||
let initialized = false
|
||||
const loading = ref(false)
|
||||
|
@ -111,7 +111,7 @@ const playAll = async (shuffle: boolean) => {
|
|||
await playbackService.playFirstInQueue()
|
||||
}
|
||||
|
||||
useScreen('Songs').onScreenActivated(async () => {
|
||||
onScreenActivated('Songs', async () => {
|
||||
if (!initialized) {
|
||||
initialized = true
|
||||
await fetchSongs()
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed, ref, toRef, watch } from 'vue'
|
||||
import { artistStore, preferenceStore as preferences } from '@/stores'
|
||||
import { useInfiniteScroll, useScreen } from '@/composables'
|
||||
import { useInfiniteScroll, useRouter } from '@/composables'
|
||||
|
||||
import ArtistCard from '@/components/artist/ArtistCard.vue'
|
||||
import ArtistCardSkeleton from '@/components/ui/skeletons/ArtistAlbumCardSkeleton.vue'
|
||||
|
@ -63,7 +63,7 @@ const fetchArtists = async () => {
|
|||
loading.value = false
|
||||
}
|
||||
|
||||
useScreen('Artists').onScreenActivated(async () => {
|
||||
useRouter().onScreenActivated('Artists', async () => {
|
||||
if (!initialized) {
|
||||
viewMode.value = preferences.artistsViewMode || 'thumbnails'
|
||||
initialized = true
|
||||
|
|
|
@ -63,7 +63,7 @@ import { faHeart } from '@fortawesome/free-regular-svg-icons'
|
|||
import { pluralize } from '@/utils'
|
||||
import { commonStore, favoriteStore } from '@/stores'
|
||||
import { downloadService } from '@/services'
|
||||
import { useScreen, useSongList } from '@/composables'
|
||||
import { useRouter, useSongList } from '@/composables'
|
||||
import { nextTick, ref, toRef } from 'vue'
|
||||
|
||||
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
||||
|
@ -106,7 +106,7 @@ const fetchSongs = async () => {
|
|||
sort()
|
||||
}
|
||||
|
||||
useScreen('Favorites').onScreenActivated(async () => {
|
||||
useRouter().onScreenActivated('Favorites', async () => {
|
||||
if (!initialized) {
|
||||
initialized = true
|
||||
await fetchSongs()
|
||||
|
|
|
@ -39,7 +39,7 @@ import { sample } from 'lodash'
|
|||
import { computed, ref } from 'vue'
|
||||
import { eventBus, logger, noop } from '@/utils'
|
||||
import { commonStore, overviewStore, userStore } from '@/stores'
|
||||
import { useAuthorization, useDialogBox, useInfiniteScroll, useScreen } from '@/composables'
|
||||
import { useAuthorization, useDialogBox, useInfiniteScroll, useRouter } from '@/composables'
|
||||
|
||||
import MostPlayedSongs from '@/components/screens/home/MostPlayedSongs.vue'
|
||||
import RecentlyPlayedSongs from '@/components/screens/home/RecentlyPlayedSongs.vue'
|
||||
|
@ -75,7 +75,7 @@ let initialized = false
|
|||
eventBus.on('SONGS_DELETED', () => overviewStore.refresh())
|
||||
.on('SONGS_UPDATED', () => overviewStore.refresh())
|
||||
|
||||
useScreen('Home').onScreenActivated(async () => {
|
||||
useRouter().onScreenActivated('Home', async () => {
|
||||
if (!initialized) {
|
||||
loading.value = true
|
||||
try {
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
import { faClock } from '@fortawesome/free-regular-svg-icons'
|
||||
import { pluralize } from '@/utils'
|
||||
import { recentlyPlayedStore } from '@/stores'
|
||||
import { useScreen, useSongList } from '@/composables'
|
||||
import { useRouter, useSongList } from '@/composables'
|
||||
import { ref, toRef } from 'vue'
|
||||
|
||||
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
||||
|
@ -70,7 +70,7 @@ const {
|
|||
let initialized = false
|
||||
let loading = ref(false)
|
||||
|
||||
useScreen('RecentlyPlayed').onScreenActivated(async () => {
|
||||
useRouter().onScreenActivated('RecentlyPlayed', async () => {
|
||||
if (!initialized) {
|
||||
loading.value = true
|
||||
initialized = true
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
export * from './useAuthorization'
|
||||
export * from './useContextMenu'
|
||||
export * from './useDialogBox'
|
||||
export * from './useDragAndDrop'
|
||||
export * from './useFloatingUi'
|
||||
export * from './useInfiniteScroll'
|
||||
export * from './useMessageToaster'
|
||||
export * from './useNetworkStatus'
|
||||
export * from './useNewVersionNotification'
|
||||
export * from './usePlaylistManagement'
|
||||
export * from './useRouter'
|
||||
export * from './useSmartPlaylistForm'
|
||||
export * from './useSongList'
|
||||
export * from './useSongMenuMethods'
|
||||
export * from './useContextMenu'
|
||||
export * from './useAuthorization'
|
||||
export * from './useNewVersionNotification'
|
||||
export * from './useThirdPartyServices'
|
||||
export * from './useDragAndDrop'
|
||||
export * from './useUpload'
|
||||
export * from './useScreen'
|
||||
export * from './usePlaylistManagement'
|
||||
export * from './useNetworkStatus'
|
||||
export * from './useFloatingUi'
|
||||
export * from './useMessageToaster'
|
||||
export * from './useDialogBox'
|
||||
export * from './useSmartPlaylistForm'
|
||||
export * from './useRouter'
|
||||
|
|
|
@ -4,13 +4,22 @@ import { requireInjection } from '@/utils'
|
|||
export const useRouter = () => {
|
||||
const router = requireInjection(RouterKey)
|
||||
|
||||
const getRouteParam = (name: string) => router.$currentRoute.value?.params?.[name]
|
||||
const getCurrentScreen = () => router.$currentRoute.value?.screen
|
||||
const isCurrentScreen = (...screens: ScreenName[]) => screens.includes(router.$currentRoute.value?.screen!)
|
||||
|
||||
const onScreenActivated = (screen: ScreenName, cb: Closure) => {
|
||||
router.onRouteChanged(route => route.screen === screen && cb())
|
||||
}
|
||||
|
||||
return {
|
||||
getRouteParam,
|
||||
getCurrentScreen,
|
||||
isCurrentScreen,
|
||||
onScreenActivated,
|
||||
go: router.go.bind(router),
|
||||
onRouteChanged: router.onRouteChanged.bind(router),
|
||||
resolveRoute: router.resolve.bind(router),
|
||||
triggerNotFound: router.triggerNotFound.bind(router),
|
||||
getRouteParam: (name: string) => router.$currentRoute.value?.params?.[name],
|
||||
getCurrentScreen: () => router.$currentRoute.value?.screen,
|
||||
isCurrentScreen: (...screens: ScreenName[]) => screens.includes(router.$currentRoute.value?.screen!)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import { useRouter } from '@/composables'
|
||||
|
||||
export const useScreen = (screen: ScreenName) => {
|
||||
const { onRouteChanged } = useRouter()
|
||||
const onScreenActivated = (cb: Closure) => onRouteChanged(route => route.screen === screen && cb())
|
||||
|
||||
return {
|
||||
onScreenActivated
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue