2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<ScreenBase id="homeWrapper">
|
|
|
|
|
<template #header>
|
|
|
|
|
<ScreenHeader layout="collapsed">{{ greeting }}</ScreenHeader>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<ScreenEmptyState v-if="libraryEmpty">
|
|
|
|
|
<template #icon>
|
|
|
|
|
<Icon :icon="faVolumeOff" />
|
2022-07-12 09:05:12 +00:00
|
|
|
|
</template>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
No songs found.
|
|
|
|
|
<span class="secondary d-block">
|
|
|
|
|
{{ isAdmin ? 'Have you set up your library yet?' : 'Contact your administrator to set up your library.' }}
|
|
|
|
|
</span>
|
|
|
|
|
</ScreenEmptyState>
|
|
|
|
|
|
|
|
|
|
<div v-else class="space-y-12">
|
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 w-full gap-8 md:gap-4">
|
|
|
|
|
<MostPlayedSongs data-testid="most-played-songs" :loading="loading" />
|
|
|
|
|
<RecentlyPlayedSongs data-testid="recently-played-songs" :loading="loading" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 w-full gap-8 md:gap-4">
|
|
|
|
|
<RecentlyAddedAlbums data-testid="recently-added-albums" :loading="loading" />
|
|
|
|
|
<RecentlyAddedSongs data-testid="recently-added-songs" :loading="loading" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<MostPlayedArtists data-testid="most-played-artists" :loading="loading" />
|
|
|
|
|
<MostPlayedAlbums data-testid="most-played-albums" :loading="loading" />
|
|
|
|
|
|
|
|
|
|
<BtnScrollToTop />
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</div>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
</ScreenBase>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
|
import { faVolumeOff } from '@fortawesome/free-solid-svg-icons'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
import { sample } from 'lodash'
|
2022-10-22 08:19:20 +00:00
|
|
|
|
import { computed, ref } from 'vue'
|
2024-04-23 11:24:29 +00:00
|
|
|
|
import { eventBus } from '@/utils'
|
2022-07-12 09:05:12 +00:00
|
|
|
|
import { commonStore, overviewStore, userStore } from '@/stores'
|
2024-04-23 11:24:29 +00:00
|
|
|
|
import { useAuthorization, useErrorHandler, useRouter } from '@/composables'
|
2022-06-10 10:47:46 +00:00
|
|
|
|
|
|
|
|
|
import MostPlayedSongs from '@/components/screens/home/MostPlayedSongs.vue'
|
|
|
|
|
import RecentlyPlayedSongs from '@/components/screens/home/RecentlyPlayedSongs.vue'
|
|
|
|
|
import RecentlyAddedAlbums from '@/components/screens/home/RecentlyAddedAlbums.vue'
|
|
|
|
|
import RecentlyAddedSongs from '@/components/screens/home/RecentlyAddedSongs.vue'
|
|
|
|
|
import MostPlayedArtists from '@/components/screens/home/MostPlayedArtists.vue'
|
2022-07-10 16:12:04 +00:00
|
|
|
|
import MostPlayedAlbums from '@/components/screens/home/MostPlayedAlbums.vue'
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
2022-07-12 09:05:12 +00:00
|
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
2024-03-16 18:11:08 +00:00
|
|
|
|
import BtnScrollToTop from '@/components/ui/BtnScrollToTop.vue'
|
2024-04-04 22:20:42 +00:00
|
|
|
|
import ScreenBase from '@/components/screens/ScreenBase.vue'
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-07-12 09:05:12 +00:00
|
|
|
|
const { isAdmin } = useAuthorization()
|
2022-10-22 09:27:03 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const greetings = [
|
|
|
|
|
'Oh hai!',
|
|
|
|
|
'Hey, %s!',
|
|
|
|
|
'Howdy, %s!',
|
|
|
|
|
'Yo!',
|
|
|
|
|
'How’s it going, %s?',
|
|
|
|
|
'Sup, %s?',
|
|
|
|
|
'How’s life, %s?',
|
|
|
|
|
'How’s your day, %s?',
|
|
|
|
|
'How have you been, %s?'
|
|
|
|
|
]
|
|
|
|
|
|
2023-04-18 20:12:19 +00:00
|
|
|
|
const greeting = computed(() => userStore.current ? sample(greetings)!.replace('%s', userStore.current.name) : '')
|
2022-07-12 09:05:12 +00:00
|
|
|
|
const libraryEmpty = computed(() => commonStore.state.song_length === 0)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-08-01 07:55:23 +00:00
|
|
|
|
const loading = ref(false)
|
2022-06-10 10:47:46 +00:00
|
|
|
|
let initialized = false
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-11-15 15:52:38 +00:00
|
|
|
|
eventBus.on('SONGS_DELETED', () => overviewStore.refresh())
|
|
|
|
|
.on('SONGS_UPDATED', () => overviewStore.refresh())
|
2022-09-15 09:07:25 +00:00
|
|
|
|
|
2022-11-18 18:56:21 +00:00
|
|
|
|
useRouter().onScreenActivated('Home', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
|
if (!initialized) {
|
2022-08-01 07:55:23 +00:00
|
|
|
|
loading.value = true
|
2022-10-22 09:27:03 +00:00
|
|
|
|
try {
|
|
|
|
|
await overviewStore.init()
|
|
|
|
|
initialized = true
|
2024-04-23 11:24:29 +00:00
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
useErrorHandler('dialog').handleHttpError(error)
|
2022-10-22 09:27:03 +00:00
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
|
}
|
2022-10-22 08:19:20 +00:00
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</script>
|