funkwhale/front/src/App.vue

129 wiersze
3.7 KiB
Vue
Czysty Zwykły widok Historia

<script setup lang="ts">
2022-07-04 22:52:53 +00:00
import type { Track } from '~/types'
2022-04-23 07:37:43 +00:00
import AudioPlayer from '~/components/audio/Player.vue'
import Queue from '~/components/Queue.vue'
import PlaylistModal from '~/components/playlists/PlaylistModal.vue'
import ChannelUploadModal from '~/components/channels/UploadModal.vue'
import Sidebar from '~/components/Sidebar.vue'
import ServiceMessages from '~/components/ServiceMessages.vue'
import SetInstanceModal from '~/components/SetInstanceModal.vue'
import ShortcutsModal from '~/components/ShortcutsModal.vue'
import FilterModal from '~/components/moderation/FilterModal.vue'
import ReportModal from '~/components/moderation/ReportModal.vue'
import { useIntervalFn, useToggle, useWindowSize } from '@vueuse/core'
2022-04-18 08:24:47 +00:00
import { computed, nextTick, onMounted, ref, watchEffect } from 'vue'
import onKeyboardShortcut from '~/composables/onKeyboardShortcut'
2022-07-03 21:36:27 +00:00
import useQueue from '~/composables/audio/useQueue'
import { useStore } from '~/store'
const store = useStore()
// Tracks
const { currentTrack } = useQueue()
const getTrackInformationText = (track: Track | undefined) => {
if (!track) {
return null
}
const artist = track.artist ?? track.album?.artist
return `${track.title}${artist?.name}`
}
// Update title
const initialTitle = document.title
watchEffect(() => {
const parts = [
getTrackInformationText(currentTrack.value),
store.state.ui.pageTitle,
initialTitle || 'Funkwhale'
]
document.title = parts.filter(i => i).join(' – ')
})
// Styles
const customStylesheets = computed(() => {
return store.state.instance.frontSettings.additionalStylesheets ?? []
})
// Fake content
onMounted(async () => {
await nextTick()
document.getElementById('fake-content')?.classList.add('loaded')
})
// Time ago
// TODO (wvffle): Migrate to useTimeAgo
useIntervalFn(() => {
// used to redraw ago dates every minute
store.commit('ui/computeLastDate')
}, 1000 * 60)
// Shortcuts
const [showShortcutsModal, toggleShortcutsModal] = useToggle(false)
onKeyboardShortcut('h', () => toggleShortcutsModal())
const { width } = useWindowSize()
const showSetInstanceModal = ref(false)
2022-07-21 23:19:16 +00:00
// Fetch user data on startup
if (store.state.auth.authenticated) {
store.dispatch('auth/fetchUser')
}
</script>
<template>
2021-11-26 11:01:58 +00:00
<div
:key="String(store.state.instance.instanceUrl)"
:class="[store.state.ui.queueFocused ? 'queue-focused' : '',
{'has-bottom-player': store.state.queue.tracks.length > 0}]"
2021-11-26 11:01:58 +00:00
>
<!-- here, we display custom stylesheets, if any -->
2018-12-04 14:13:37 +00:00
<link
v-for="url in customStylesheets"
2021-11-26 11:01:58 +00:00
:key="url"
2018-12-04 14:13:37 +00:00
rel="stylesheet"
property="stylesheet"
:href="url"
>
2022-05-01 11:45:07 +00:00
2021-11-26 11:01:58 +00:00
<sidebar
:width="width"
@show:set-instance-modal="showSetInstanceModal = !showSetInstanceModal"
@show:shortcuts-modal="toggleShortcutsModal"
2021-11-26 11:01:58 +00:00
/>
2022-05-01 11:45:07 +00:00
<set-instance-modal v-model:show="showSetInstanceModal" />
2021-11-26 11:01:58 +00:00
<service-messages />
<transition name="queue">
2022-07-22 03:02:53 +00:00
<queue v-show="store.state.ui.queueFocused" />
2021-11-26 11:01:58 +00:00
</transition>
2022-04-18 16:17:51 +00:00
2022-05-01 13:11:50 +00:00
<router-view v-slot="{ Component }">
2022-05-01 11:45:07 +00:00
<template v-if="Component">
2022-05-01 13:11:50 +00:00
<keep-alive :max="1">
2022-07-22 03:02:53 +00:00
<Suspense>
<component :is="Component" />
2022-05-01 13:11:50 +00:00
<template #fallback>
<!-- TODO (wvffle): Add loader -->
Loading...
</template>
</Suspense>
</keep-alive>
2022-05-01 11:45:07 +00:00
</template>
2022-04-18 16:17:51 +00:00
</router-view>
2022-07-03 23:57:14 +00:00
<audio-player />
<playlist-modal v-if="store.state.auth.authenticated" />
<channel-upload-modal v-if="store.state.auth.authenticated" />
<filter-modal v-if="store.state.auth.authenticated" />
2021-11-26 11:01:58 +00:00
<report-modal />
2022-05-01 11:45:07 +00:00
<shortcuts-modal v-model:show="showShortcutsModal" />
</div>
</template>
<style lang="scss">
2018-12-19 21:04:35 +00:00
@import "style/_main";
</style>