Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
522e062a36 | ||
|
|
4754d61279 | ||
|
|
dbb91a3918 | ||
|
|
6a3dffae7d | ||
|
|
c1079dcbba | ||
|
|
5f572e769e | ||
|
|
464bbaef9e | ||
|
|
581c522b00 | ||
|
|
470cf122a3 | ||
|
|
464b016fcb | ||
|
|
e5ee065468 | ||
|
|
49d4bd86f1 | ||
|
|
6c10a53a75 | ||
|
|
1060eeba58 | ||
|
|
6e54868cc3 | ||
|
|
fcd12aa27d | ||
|
|
b7262be0a6 | ||
|
|
e1f5077c20 | ||
|
|
5b2d1bb977 | ||
|
|
bd0fc5394f | ||
|
|
2012e7f566 | ||
|
|
9c3f6af7b3 |
No files matched your search
@@ -1,8 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type Option } from "~/ui/SearchSelect.vue"
|
||||
|
||||
type InputType = "text" | "file" | "search-select"
|
||||
|
||||
interface BaseField<T> {
|
||||
key: keyof T
|
||||
label?: string
|
||||
@@ -12,6 +10,11 @@ interface TextField<T> extends BaseField<T> {
|
||||
type?: "text"
|
||||
}
|
||||
|
||||
interface TextAreaField<T> extends BaseField<T> {
|
||||
type?: "textarea"
|
||||
rows: number
|
||||
}
|
||||
|
||||
interface FileField<T> extends BaseField<T> {
|
||||
type: "file"
|
||||
}
|
||||
@@ -26,11 +29,17 @@ interface SearchSelectArrayField<T> extends BaseField<T> {
|
||||
fetchOptions: (q?: string) => Promise<Option[]>
|
||||
}
|
||||
|
||||
interface CheckboxField<T> extends BaseField<T> {
|
||||
type?: "checkbox"
|
||||
}
|
||||
|
||||
export type Field<T = any> =
|
||||
| TextField<T>
|
||||
| TextAreaField<T>
|
||||
| FileField<T>
|
||||
| SearchSelectField<T>
|
||||
| SearchSelectArrayField<T>
|
||||
| CheckboxField<T>
|
||||
|
||||
interface ModalFormProps<T> {
|
||||
item?: T
|
||||
@@ -44,27 +53,60 @@ const open = defineModel("open", { required: true })
|
||||
|
||||
let localItem = reactive<any>({})
|
||||
|
||||
const getNestedValue = (obj: any, path: string) =>
|
||||
path.split(".").reduce((acc, key) => acc?.[key], obj)
|
||||
|
||||
const setNestedValue = (obj: any, path: string, value: any) => {
|
||||
const keys = path.split(".")
|
||||
keys.reduce((acc, key, i) => {
|
||||
if (i === keys.length - 1) acc[key] = value
|
||||
else acc[key] ??= {}
|
||||
return acc[key]
|
||||
}, obj)
|
||||
}
|
||||
|
||||
const expandDotKeys = (flat: Record<string, any>) => {
|
||||
const result: any = {}
|
||||
for (const [key, value] of Object.entries(flat)) {
|
||||
setNestedValue(result, key, toRaw(value))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
const expanded = expandDotKeys(localItem)
|
||||
|
||||
Object.keys(expanded).forEach((k) => {
|
||||
if (expanded[k] == undefined || expanded[k] == null) delete expanded[k]
|
||||
})
|
||||
|
||||
if (await props.onSave(expanded)) open.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.item,
|
||||
(item) => {
|
||||
Object.keys(localItem).forEach((k) => delete localItem[k])
|
||||
|
||||
if (!item) return
|
||||
|
||||
for (const [key, value] of Object.entries(item)) {
|
||||
if (item)
|
||||
for (const [key, value] of Object.entries(item))
|
||||
localItem[key] = value
|
||||
}
|
||||
|
||||
for (const field of props.fields) {
|
||||
if (field.type == "file") localItem[field.key as string] = null
|
||||
const key = field.key as string
|
||||
if (field.type === "file") {
|
||||
localItem[key] = null
|
||||
} else if (field.type === "checkbox") {
|
||||
localItem[key] = item
|
||||
? (getNestedValue(item, key) ?? false)
|
||||
: false
|
||||
} else {
|
||||
localItem[key] = item ? getNestedValue(item, key) : undefined
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
const save = async () => {
|
||||
if (await props.onSave(localItem)) open.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -84,12 +126,19 @@ const save = async () => {
|
||||
:predefined="props.item?.[field.key]"
|
||||
:multiple="field.type == 'search-select-array'"
|
||||
/>
|
||||
<Checkbox
|
||||
v-else-if="field.type == 'checkbox'"
|
||||
:label="field.label || field.key"
|
||||
@change="(v) => (localItem[field.key] = v)"
|
||||
/>
|
||||
<Input
|
||||
v-else
|
||||
:type="field.type"
|
||||
:key="field.key"
|
||||
:label="field.label || field.key"
|
||||
v-model:value="localItem[field.key]"
|
||||
:textarea="field.type == 'textarea'"
|
||||
:rows="field.type == 'textarea' ? field.rows : 0"
|
||||
full
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -27,6 +27,7 @@ const { data, pending, refresh } = useAsyncData("random-albums", async () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="slider">
|
||||
<template v-for="item in data" :key="item.genre._id">
|
||||
<Slider v-if="item.albums.length" :title="item.genre.name">
|
||||
<AlbumCard
|
||||
@@ -39,4 +40,13 @@ const { data, pending, refresh } = useAsyncData("random-albums", async () => {
|
||||
/>
|
||||
</Slider>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.slider {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
@@ -127,7 +127,7 @@ const toast = useToast()
|
||||
position: fixed;
|
||||
bottom: 1rem;
|
||||
|
||||
height: 72px;
|
||||
height: $player-height;
|
||||
|
||||
border-radius: $border-radius-lg;
|
||||
border: 1px solid $color-border;
|
||||
|
||||
@@ -29,7 +29,7 @@ const computeIfScroll = () => {
|
||||
onMounted(() => {
|
||||
computeIfScroll()
|
||||
|
||||
window.addEventListener("reisze", computeIfScroll)
|
||||
window.addEventListener("resize", computeIfScroll)
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener("resize", computeIfScroll)
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<script setup lang="ts">
|
||||
import type { DropdownMenuItem } from "~/ui/DropdownMenu.vue"
|
||||
|
||||
interface TrackRowProps {
|
||||
track: Track
|
||||
index: number
|
||||
extendedInfo?: boolean
|
||||
}
|
||||
|
||||
const { track, index, extendedInfo } = defineProps<TrackRowProps>()
|
||||
const emit = defineEmits<{ (e: "playAlbumAtIndex"): void }>()
|
||||
|
||||
const hovering = ref(false)
|
||||
|
||||
const toast = useToast()
|
||||
|
||||
const dropdownMenuItems: DropdownMenuItem[] = [
|
||||
{
|
||||
label: "Play only this",
|
||||
icon: "lucide:play",
|
||||
onSelect() {},
|
||||
},
|
||||
{
|
||||
label: "Play next",
|
||||
icon: "lucide:list-start",
|
||||
onSelect() {
|
||||
toast.show("Playing next")
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Add to queue",
|
||||
icon: "lucide:list-end",
|
||||
onSelect() {
|
||||
toast.show("Added to queue")
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const durationFormatted = computed(() =>
|
||||
new Date(track.durationInSeconds * 1000).toISOString().slice(14, 19),
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article
|
||||
class="track"
|
||||
:class="{ extended: extendedInfo, odd: index % 2 == 1 }"
|
||||
@mouseover="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<div class="index">
|
||||
<Icon
|
||||
name="lucide:play"
|
||||
@click="emit('playAlbumAtIndex')"
|
||||
v-if="hovering"
|
||||
/>
|
||||
<p v-else>{{ index + 1 }}</p>
|
||||
</div>
|
||||
|
||||
<p>{{ track.name }}</p>
|
||||
|
||||
<template v-if="extendedInfo">
|
||||
<ArtistName :artists="track.artists" class="artists" />
|
||||
<NuxtLink :to="`/album/${track.album._id}`">
|
||||
<p>{{ track.album.name }}</p>
|
||||
</NuxtLink>
|
||||
</template>
|
||||
|
||||
<p>{{ durationFormatted }}</p>
|
||||
|
||||
<DropdownMenu :items="dropdownMenuItems">
|
||||
<Icon name="lucide:ellipsis" class="dropdown-icon" />
|
||||
</DropdownMenu>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use "@/styles/variables" as *;
|
||||
@use "@/styles/util" as *;
|
||||
@use "sass:color";
|
||||
|
||||
.track {
|
||||
display: grid;
|
||||
grid-template-columns: 30px 1fr 50px 30px;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
padding: 0.6rem 1rem;
|
||||
border-radius: $border-radius-standard;
|
||||
background-color: $color-background;
|
||||
line-height: 1;
|
||||
|
||||
&.odd {
|
||||
background-color: color.adjust($color-background, $lightness: 5%);
|
||||
}
|
||||
|
||||
&.extended {
|
||||
grid-template-columns: 30px 2fr 1fr 1fr 50px 30px;
|
||||
}
|
||||
|
||||
p {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.index {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 20px;
|
||||
height: 20px;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.artists {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.dropdown-icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -4,7 +4,7 @@ import defu from "defu"
|
||||
export function useApiFetch<DataT = any, ErrorT = any>(
|
||||
url: string | Request | Ref<string | Request> | (() => string | Request),
|
||||
options?: UseFetchOptions<DataT, ErrorT>,
|
||||
authorize: boolean = true
|
||||
authorize: boolean = true,
|
||||
): ReturnType<typeof useFetch<DataT, ErrorT>> {
|
||||
const baseUrl = import.meta.env.VITE_PUBLIC_BACKEND
|
||||
|
||||
@@ -15,26 +15,25 @@ export function useApiFetch<DataT = any, ErrorT = any>(
|
||||
const defaults: UseFetchOptions<DataT, ErrorT> = {
|
||||
baseURL: baseUrl,
|
||||
|
||||
retry: 1,
|
||||
retryDelay: 0,
|
||||
retryStatusCodes: [401],
|
||||
|
||||
headers:
|
||||
authorize && sessionToken.value
|
||||
? { Authorization: `Bearer ${sessionToken.value}` }
|
||||
: {},
|
||||
onResponseError: async ({ response, options }) => {
|
||||
onResponseError: async ({ request, response, options }) => {
|
||||
if (response.status == 401 && authorize) {
|
||||
const newToken = await refreshSessionToken()
|
||||
|
||||
if (!newToken) return
|
||||
|
||||
const newOptions = {
|
||||
...options,
|
||||
headers: {
|
||||
...(options.headers || {}),
|
||||
Authorization: `Bearer ${newToken}`,
|
||||
},
|
||||
}
|
||||
|
||||
options.headers = {
|
||||
...(options.headers as unknown as Record<string, string>),
|
||||
// @ts-ignore
|
||||
return await $fetch<DataT, ErrorT>(url, newOptions)
|
||||
Authorization: `Bearer ${newToken}`,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -79,7 +79,10 @@ export const useAuth = () => {
|
||||
|
||||
const signup = async (name: string, email: string, password: string) => {}
|
||||
|
||||
const signout = () => {}
|
||||
const signout = () => {
|
||||
refreshToken.value = null
|
||||
sessionToken.value = null
|
||||
}
|
||||
|
||||
const refreshSessionToken = async () => {
|
||||
if (waitForPromise) {
|
||||
|
||||
@@ -14,7 +14,7 @@ const tableRows: Row[] = [
|
||||
name: "file",
|
||||
displayName: "Cover",
|
||||
type: "image",
|
||||
prefix: `${BACKEND_SERVE}/static/`,
|
||||
prefix: `${BACKEND_SERVE}`,
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
@@ -31,7 +31,7 @@ const tableRows: Row[] = [
|
||||
|
||||
import { type Option } from "~/ui/SearchSelect.vue"
|
||||
|
||||
const { data: artistData } = useApiFetch<Genre[]>("/all/artists")
|
||||
const { data: artistData } = useApiFetch<Artist[]>("/all/artists")
|
||||
const artistFetchOptions = async (q?: string): Promise<Option[]> => {
|
||||
return artistData.value.map<Option>((g) => ({
|
||||
label: g.name,
|
||||
@@ -65,7 +65,7 @@ const modalFields: Field[] = [
|
||||
]
|
||||
|
||||
const showModal = ref<boolean>(false)
|
||||
const item = ref<Track | undefined>(undefined)
|
||||
const item = ref<Album | undefined>(undefined)
|
||||
|
||||
const save = async (value: any) => {
|
||||
if (value._id) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Field } from "~/components/Admin/ModalForm.vue"
|
||||
import type { Row } from "~/ui/Table.vue"
|
||||
|
||||
const { data, refresh } = useApiFetch<Track[]>("/all/artists")
|
||||
const { data, refresh } = useApiFetch<Artist[]>("/all/artists")
|
||||
const toast = useToast()
|
||||
|
||||
const tableRows: Row[] = [
|
||||
@@ -31,7 +31,7 @@ const modalFields: Field[] = [
|
||||
]
|
||||
|
||||
const showModal = ref<boolean>(false)
|
||||
const item = ref<Track | undefined>(undefined)
|
||||
const item = ref<Artist | undefined>(undefined)
|
||||
|
||||
const save = async (value: any) => {
|
||||
if (value._id) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Field } from "~/components/Admin/ModalForm.vue"
|
||||
import type { Row } from "~/ui/Table.vue"
|
||||
|
||||
const { data, refresh } = useApiFetch<Track[]>("/all/genres")
|
||||
const { data, refresh } = useApiFetch<Genre[]>("/all/genres")
|
||||
const toast = useToast()
|
||||
|
||||
const tableRows: Row[] = [
|
||||
@@ -22,7 +22,7 @@ const tableRows: Row[] = [
|
||||
const modalFields: Field[] = [{ key: "name", label: "Name" }]
|
||||
|
||||
const showModal = ref<boolean>(false)
|
||||
const item = ref<Track | undefined>(undefined)
|
||||
const item = ref<Genre | undefined>(undefined)
|
||||
|
||||
const save = async (value: any) => {
|
||||
if (value._id) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Field } from "~/components/Admin/ModalForm.vue"
|
||||
import type { Row } from "~/ui/Table.vue"
|
||||
|
||||
const { data, refresh } = useApiFetch<Album[]>("/all/tracks")
|
||||
const { data, refresh } = useApiFetch<Track[]>("/all/tracks")
|
||||
const toast = useToast()
|
||||
|
||||
const tableRows: Row[] = [
|
||||
@@ -15,7 +15,7 @@ const tableRows: Row[] = [
|
||||
displayName: "Audio File",
|
||||
type: "audio",
|
||||
prefix: `${BACKEND_SERVE}`,
|
||||
suffix: "/original.m4a",
|
||||
suffix: "/high.m4a",
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
@@ -32,7 +32,7 @@ const tableRows: Row[] = [
|
||||
|
||||
import { type Option } from "~/ui/SearchSelect.vue"
|
||||
|
||||
const { data: artistData } = useApiFetch<Genre[]>("/all/artists")
|
||||
const { data: artistData } = useApiFetch<Artist[]>("/all/artists")
|
||||
const artistFetchOptions = async (q?: string): Promise<Option[]> => {
|
||||
return artistData.value.map<Option>((g) => ({
|
||||
label: g.name,
|
||||
@@ -40,7 +40,7 @@ const artistFetchOptions = async (q?: string): Promise<Option[]> => {
|
||||
}))
|
||||
}
|
||||
|
||||
const { data: albumData } = useApiFetch<Genre[]>("/all/albums")
|
||||
const { data: albumData } = useApiFetch<Album[]>("/all/albums")
|
||||
const albumFetchOptions = async (q?: string): Promise<Option[]> => {
|
||||
return albumData.value.map<Option>((g) => ({
|
||||
label: g.name,
|
||||
@@ -63,6 +63,8 @@ const modalFields: Field[] = [
|
||||
type: "search-select",
|
||||
fetchOptions: albumFetchOptions,
|
||||
},
|
||||
{ key: "lyrics.text", label: "Lyrics", type: "textarea", rows: 6 },
|
||||
{ key: "lyrics.synced", label: "Synced lyrics", type: "checkbox" },
|
||||
]
|
||||
|
||||
const showModal = ref<boolean>(false)
|
||||
@@ -73,7 +75,10 @@ const save = async (value: any) => {
|
||||
try {
|
||||
await cfetch("/admin/track", {
|
||||
method: "PATCH",
|
||||
data: value,
|
||||
data: {
|
||||
...value,
|
||||
lyrics: JSON.stringify(value.lyrics),
|
||||
},
|
||||
params: { id: value._id },
|
||||
forceFormData: true,
|
||||
})
|
||||
@@ -88,7 +93,10 @@ const save = async (value: any) => {
|
||||
try {
|
||||
await cfetch("/admin/track", {
|
||||
method: "POST",
|
||||
data: value,
|
||||
data: {
|
||||
...value,
|
||||
lyrics: JSON.stringify(value.lyrics),
|
||||
},
|
||||
})
|
||||
|
||||
toast.show("Song added successfully", "success")
|
||||
@@ -137,8 +145,6 @@ const show = (id?: string) => {
|
||||
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
watch(data, () => console.log(data))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1 +1,96 @@
|
||||
<template></template>
|
||||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const id = computed(() => route.params.id)
|
||||
|
||||
const { data: albumData } = await useApiFetch<Album>(`/albums/${id.value}`)
|
||||
|
||||
const { data: tracksData } = await useApiFetch<Track[]>(
|
||||
`/albums/${id.value}/tracks`,
|
||||
)
|
||||
|
||||
const { playAlbum, playShuffledAlbum, playAlbumAtIndex } = usePlayer()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="info" v-if="albumData">
|
||||
<NuxtImg
|
||||
:src="GET_FILE(albumData.file)"
|
||||
width="300"
|
||||
height="300"
|
||||
placeholder
|
||||
/>
|
||||
|
||||
<div class="details">
|
||||
<h1>{{ albumData.name }}</h1>
|
||||
<ArtistName :artists="albumData.artists" class="artist" />
|
||||
|
||||
<div class="buttons">
|
||||
<Button
|
||||
icon-name="lucide:play"
|
||||
@click="() => playAlbum(tracksData)"
|
||||
>Play</Button
|
||||
>
|
||||
<Button
|
||||
icon-name="lucide:shuffle"
|
||||
@click="() => playShuffledAlbum(tracksData)"
|
||||
>Shuffle</Button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="tracks">
|
||||
<TrackRow
|
||||
v-for="(track, i) in tracksData"
|
||||
:key="track._id"
|
||||
:track="track"
|
||||
:index="i"
|
||||
@play-album-at-index="() => playAlbumAtIndex(tracksData, i)"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use "@/styles/variables" as *;
|
||||
@use "@/styles/util";
|
||||
|
||||
.info {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
|
||||
& img {
|
||||
border-radius: $border-radius-standard;
|
||||
}
|
||||
|
||||
.details {
|
||||
padding-top: 3.5rem;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
|
||||
& h1 {
|
||||
@include util.fontSize(32px);
|
||||
font-weight: 700;
|
||||
line-height: 2.4rem;
|
||||
}
|
||||
|
||||
.artist {
|
||||
@include util.fontSize(18px);
|
||||
}
|
||||
|
||||
.buttons {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tracks {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
</style>
|
||||
+1
-3
@@ -10,9 +10,7 @@ const play = () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Button @click="play">Test play</Button>
|
||||
<h1>Home</h1>
|
||||
|
||||
<AlbumSlider />
|
||||
|
||||
<div :style="{ height: '100vh' }"></div>
|
||||
</template>
|
||||
+40
-2
@@ -138,7 +138,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
updateMediaSession()
|
||||
}
|
||||
|
||||
const next = async () => {
|
||||
const next = async (autoplay: boolean = true) => {
|
||||
if (currentSong.value) {
|
||||
prevQueue.value.unshift(currentSong.value)
|
||||
}
|
||||
@@ -153,7 +153,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
currentSong.value = queue.value.shift() || null
|
||||
}
|
||||
|
||||
if (currentSong.value) await play()
|
||||
if (currentSong.value && autoplay) await play()
|
||||
|
||||
updateMediaSession()
|
||||
}
|
||||
@@ -184,6 +184,11 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
currentQueue.value.push(song)
|
||||
}
|
||||
|
||||
const addToFrontOfQueue = (song: Track) => {
|
||||
queue.value.unshift(song)
|
||||
currentQueue.value.unshift(song)
|
||||
}
|
||||
|
||||
const clear = () => {
|
||||
queue.value = []
|
||||
currentQueue.value = []
|
||||
@@ -196,6 +201,35 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
queue.value.sort(() => Math.random() - 0.5)
|
||||
}
|
||||
|
||||
// Album
|
||||
const playAlbum = async (songs: Track[]) => {
|
||||
clear()
|
||||
|
||||
songs.forEach((song) => addToQueue(song))
|
||||
|
||||
await next()
|
||||
}
|
||||
|
||||
const playShuffledAlbum = async (songs: Track[]) => {
|
||||
clear()
|
||||
|
||||
songs.forEach((song) => addToQueue(song))
|
||||
shuffle()
|
||||
|
||||
await next()
|
||||
}
|
||||
|
||||
const playAlbumAtIndex = async (songs: Track[], index: number) => {
|
||||
clear()
|
||||
songs.forEach((song) => addToQueue(song))
|
||||
|
||||
for (let i = 0; i < index + 1; i++) {
|
||||
await next(false)
|
||||
}
|
||||
|
||||
await play()
|
||||
}
|
||||
|
||||
// Info
|
||||
const getDuration = () =>
|
||||
new Promise<number>((resolve) => {
|
||||
@@ -218,8 +252,12 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
next,
|
||||
prev,
|
||||
addToQueue,
|
||||
addToFrontOfQueue,
|
||||
clear,
|
||||
shuffle,
|
||||
playAlbum,
|
||||
playShuffledAlbum,
|
||||
playAlbumAtIndex,
|
||||
getDuration,
|
||||
secondsPlayed,
|
||||
duration,
|
||||
|
||||
@@ -10,3 +10,5 @@ $color-attention: #fc8181;
|
||||
|
||||
$border-radius-standard: 0.3rem;
|
||||
$border-radius-lg: 0.6rem;
|
||||
|
||||
$player-height: 72px;
|
||||
+10
-1
@@ -1,7 +1,16 @@
|
||||
@use "reset" as *;
|
||||
@use "util" as *;
|
||||
|
||||
html {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
|
||||
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
color: white;
|
||||
}
|
||||
|
||||
main > h1 {
|
||||
@include fontSize(32px);
|
||||
font-weight: 700;
|
||||
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<script setup lang="ts">
|
||||
export interface DropdownMenuItem {
|
||||
label: string
|
||||
icon: string
|
||||
onSelect?: () => void
|
||||
}
|
||||
|
||||
interface DropdownMenuProps {
|
||||
items: DropdownMenuItem[]
|
||||
}
|
||||
|
||||
const props = defineProps<DropdownMenuProps>()
|
||||
|
||||
const open = ref(false)
|
||||
const placement = ref<"bottom" | "top">("bottom")
|
||||
const root = useTemplateRef("root")
|
||||
|
||||
const toggle = async () => {
|
||||
open.value = !open.value
|
||||
|
||||
if (open.value) {
|
||||
await nextTick()
|
||||
updatePlacement()
|
||||
}
|
||||
}
|
||||
const close = () => (open.value = false)
|
||||
|
||||
const updatePlacement = () => {
|
||||
const el = root.value
|
||||
if (!el) return
|
||||
|
||||
const rect = el.getBoundingClientRect()
|
||||
|
||||
const spaceBelow = window.innerHeight - rect.bottom
|
||||
const spaceAbove = rect.top
|
||||
|
||||
// TODO: Calculate height instead
|
||||
const menuHeight = 220
|
||||
|
||||
console.log(
|
||||
spaceBelow,
|
||||
menuHeight,
|
||||
spaceAbove,
|
||||
spaceBelow < menuHeight && spaceAbove > spaceBelow,
|
||||
spaceBelow < menuHeight && spaceAbove > spaceBelow ? "top" : "bottom",
|
||||
)
|
||||
|
||||
placement.value =
|
||||
spaceBelow < menuHeight && spaceAbove > spaceBelow ? "top" : "bottom"
|
||||
}
|
||||
|
||||
const handleOutsideClick = (e: MouseEvent) => {
|
||||
if (!root.value) return
|
||||
if (!root.value.contains(e.target as Node)) close()
|
||||
}
|
||||
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key == "Escape") close()
|
||||
}
|
||||
|
||||
const handleReposition = () => {
|
||||
if (open.value) updatePlacement()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("click", handleOutsideClick)
|
||||
document.addEventListener("keydown", handleKey)
|
||||
window.addEventListener("resize", handleReposition)
|
||||
window.addEventListener("scroll", handleReposition, true)
|
||||
})
|
||||
|
||||
onBeforeMount(() => {
|
||||
document.removeEventListener("click", handleOutsideClick)
|
||||
document.removeEventListener("keydown", handleKey)
|
||||
window.removeEventListener("resize", handleReposition)
|
||||
window.removeEventListener("scroll", handleReposition, true)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="dropdown">
|
||||
<div @click="toggle" class="trigger">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<Transition name="dropdown">
|
||||
<div v-show="open" class="menu" :class="placement">
|
||||
<button
|
||||
v-for="(item, i) in items"
|
||||
:key="i"
|
||||
class="item"
|
||||
@click="
|
||||
() => {
|
||||
item.onSelect?.()
|
||||
close()
|
||||
}
|
||||
"
|
||||
>
|
||||
<Icon :name="item.icon" class="icon" />
|
||||
<span>{{ item.label }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use "@/styles/variables" as *;
|
||||
|
||||
.dropdown {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
|
||||
.menu {
|
||||
position: absolute;
|
||||
|
||||
right: 0;
|
||||
|
||||
min-width: 180px;
|
||||
padding: 0.5rem;
|
||||
|
||||
background-color: $color-secondary-background;
|
||||
border-radius: $border-radius-standard;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
|
||||
z-index: 1000;
|
||||
|
||||
&.bottom {
|
||||
top: calc(100% + 0.5rem);
|
||||
transform-origin: top right;
|
||||
}
|
||||
|
||||
&.top {
|
||||
bottom: calc(100% + 0.5rem);
|
||||
transform-origin: bottom right;
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
padding: 0.5rem;
|
||||
border-radius: $border-radius-standard;
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.item:hover {
|
||||
background-color: $color-button-hover;
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-enter-active,
|
||||
.dropdown-leave-active {
|
||||
transition:
|
||||
opacity 0.14s ease-out,
|
||||
transform 0.14s ease-out;
|
||||
}
|
||||
|
||||
/* Starting state */
|
||||
.dropdown-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(-6px) scale(0.96);
|
||||
}
|
||||
|
||||
/* End state */
|
||||
.dropdown-enter-to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
|
||||
/* Leaving */
|
||||
.dropdown-leave-from {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
|
||||
.dropdown-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-4px) scale(0.98);
|
||||
}
|
||||
</style>
|
||||
+23
-2
@@ -11,6 +11,8 @@ interface InputProps {
|
||||
required?: boolean
|
||||
autocomplete?: AutocompleteType
|
||||
label?: string
|
||||
textarea?: boolean
|
||||
rows?: number
|
||||
}
|
||||
|
||||
const value = defineModel<string | File | File[] | null>("value")
|
||||
@@ -63,7 +65,7 @@ const onFileChange = (e: Event) => {
|
||||
</span>
|
||||
|
||||
<input
|
||||
v-if="props.type != 'file'"
|
||||
v-if="props.type != 'file' && props.type != 'textarea'"
|
||||
:placeholder="props.placeholder"
|
||||
v-model="value"
|
||||
@input="(e) => emit('input', e.target?.value)"
|
||||
@@ -76,6 +78,20 @@ const onFileChange = (e: Event) => {
|
||||
:autocomplete="props.autocomplete"
|
||||
/>
|
||||
|
||||
<textarea
|
||||
v-else-if="props.textarea"
|
||||
:placeholder="props.placeholder"
|
||||
v-model="value"
|
||||
@input="(e) => emit('input', e.target?.value)"
|
||||
@focus="emit('focus')"
|
||||
@blur="emit('blur')"
|
||||
:name="props.name"
|
||||
:id="props.name"
|
||||
:required="props.required"
|
||||
:autocomplete="props.autocomplete"
|
||||
:rows="props.rows"
|
||||
/>
|
||||
|
||||
<input
|
||||
v-else
|
||||
@focus="emit('focus')"
|
||||
@@ -120,7 +136,8 @@ const onFileChange = (e: Event) => {
|
||||
outline: 2px solid $color-accent;
|
||||
}
|
||||
|
||||
& input {
|
||||
& input,
|
||||
& textarea {
|
||||
width: 100%;
|
||||
background: none;
|
||||
|
||||
@@ -132,6 +149,10 @@ const onFileChange = (e: Event) => {
|
||||
}
|
||||
}
|
||||
|
||||
& textarea:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
& input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
padding: 2rem 3rem;
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
const { toasts, remove } = useToast()
|
||||
const song = useSong()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="toast-container">
|
||||
<div class="toast-container" :class="{ playerShown: song != undefined }">
|
||||
<TransitionGroup name="toast">
|
||||
<div
|
||||
v-for="toast in toasts"
|
||||
@@ -27,11 +28,17 @@ const { toasts, remove } = useToast()
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
|
||||
padding: 20px;
|
||||
padding: 2rem;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
|
||||
transition: trasnform 0.2s ease-out;
|
||||
}
|
||||
|
||||
.playerShown {
|
||||
transform: translateY(-$player-height);
|
||||
}
|
||||
|
||||
.toast {
|
||||
@@ -44,7 +51,9 @@ const { toasts, remove } = useToast()
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
transition:
|
||||
transform 0.2s ease,
|
||||
opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.toast-enter-from {
|
||||
|
||||
+3
-3
@@ -62,13 +62,13 @@ export const cfetch = async (
|
||||
let response
|
||||
try {
|
||||
response = await axios(url, config)
|
||||
} catch {
|
||||
if (response?.status == 401) {
|
||||
} catch (error: any) {
|
||||
if (error.response?.status == 401) {
|
||||
if (!config.headers) config.headers = {}
|
||||
config.headers.Authorization = `Bearer ${await refreshSessionToken()}`
|
||||
|
||||
response = await axios(url, config)
|
||||
}
|
||||
} else throw error
|
||||
}
|
||||
|
||||
if (!response) throw new Error("Something went wrong. Please try again")
|
||||
|
||||
@@ -27,4 +27,5 @@ export interface Track extends Base {
|
||||
}
|
||||
album: Album
|
||||
artists: Artist[]
|
||||
durationInSeconds: number
|
||||
}
|
||||
Reference in new issue
Block a user