feat: mark playlists not accepting song drops

This commit is contained in:
Phan An 2022-04-30 15:20:47 +02:00
parent 223cfd42e5
commit 099ab12a15
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
2 changed files with 10 additions and 9 deletions

View file

@ -6,7 +6,7 @@
:class="{ active }"
:href="url"
@contextmenu.prevent="openContextMenu"
v-koel-droppable="handleDrop"
v-koel-droppable:[contentEditable]="handleDrop"
>{{ playlist.name }}</a>
<NameEditor
@ -29,8 +29,8 @@
<script lang="ts" setup>
import { computed, defineAsyncComponent, nextTick, ref, toRefs } from 'vue'
import { alerts, eventBus, pluralize } from '@/utils'
import router from '@/router'
import { favoriteStore, playlistStore, songStore } from '@/stores'
import router from '@/router'
type PlaylistType = 'playlist' | 'favorites' | 'recently-played'

View file

@ -1,10 +1,12 @@
import { $ } from '@/utils'
import { Directive } from 'vue'
import { $ } from '@/utils'
export const droppable: Directive = {
created: (el: HTMLElement, { value }: { value: TAnyFunction | never }) => {
if (!(value instanceof Function)) {
throw new Error(`Expect a function, received ${typeof value}`)
created: (el: HTMLElement, binding) => {
const acceptsDrops = binding.arg === undefined || Boolean(binding.arg)
if (!acceptsDrops) {
return
}
el.addEventListener('dragenter', (event: DragEvent) => {
@ -15,15 +17,14 @@ export const droppable: Directive = {
return false
})
el.addEventListener('dragover', (event: DragEvent): void => event.preventDefault())
el.addEventListener('dragover', (event: DragEvent) => event.preventDefault())
el.addEventListener('dragleave', () => $.removeClass(el, 'droppable'))
el.addEventListener('drop', (event: DragEvent) => {
event.preventDefault()
event.stopPropagation()
$.removeClass(el, 'droppable')
value(event)
binding.value(event)
})
}
}