2021-10-25 01:25:44 +02:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="bookmarks" :width="500" :height="'unset'">
|
|
|
|
<div ref="container" class="w-full rounded-lg bg-primary box-shadow-md overflow-y-auto overflow-x-hidden" style="max-height: 80vh">
|
2021-11-03 23:45:47 +01:00
|
|
|
<div v-if="show" class="w-full h-full">
|
2021-10-25 01:25:44 +02:00
|
|
|
<template v-for="bookmark in bookmarks">
|
2021-11-03 23:45:47 +01:00
|
|
|
<modals-bookmarks-bookmark-item :key="bookmark.id" :highlight="currentTime === bookmark.time" :bookmark="bookmark" @click="clickBookmark" @update="submitUpdateBookmark" @delete="deleteBookmark" />
|
2021-10-25 01:25:44 +02:00
|
|
|
</template>
|
|
|
|
<div v-if="!bookmarks.length" class="flex h-32 items-center justify-center">
|
|
|
|
<p class="text-xl">No Bookmarks</p>
|
|
|
|
</div>
|
2021-11-03 23:45:47 +01:00
|
|
|
<div class="w-full h-px bg-white bg-opacity-10" />
|
|
|
|
<form @submit.prevent="submitCreateBookmark">
|
|
|
|
<div v-show="canCreateBookmark" class="flex px-4 py-2 items-center text-center border-b border-white border-opacity-10 text-white text-opacity-80">
|
2021-11-04 01:12:17 +01:00
|
|
|
<div class="w-16 max-w-16 text-center">
|
|
|
|
<p class="text-sm font-mono text-gray-400">
|
2021-11-03 23:45:47 +01:00
|
|
|
{{ this.$secondsToTimestamp(currentTime) }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<ui-text-input v-model="newBookmarkTitle" placeholder="Note" class="w-full" />
|
|
|
|
</div>
|
|
|
|
<ui-btn type="submit" color="success" :padding-x="4" class="h-10"><span class="material-icons -mt-px">add</span></ui-btn>
|
|
|
|
</div>
|
|
|
|
</form>
|
2021-10-25 01:25:44 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: Boolean,
|
|
|
|
bookmarks: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
|
|
|
currentTime: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
2022-03-18 02:28:04 +01:00
|
|
|
libraryItemId: String
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-10-27 03:09:04 +02:00
|
|
|
selectedBookmark: null,
|
2021-10-25 01:25:44 +02:00
|
|
|
showBookmarkTitleInput: false,
|
|
|
|
newBookmarkTitle: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
show(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.showBookmarkTitleInput = false
|
|
|
|
this.newBookmarkTitle = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
2021-10-27 03:09:04 +02:00
|
|
|
},
|
|
|
|
canCreateBookmark() {
|
|
|
|
return !this.bookmarks.find((bm) => bm.time === this.currentTime)
|
2021-10-25 01:25:44 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-27 03:09:04 +02:00
|
|
|
editBookmark(bm) {
|
|
|
|
this.selectedBookmark = bm
|
|
|
|
this.newBookmarkTitle = bm.title
|
|
|
|
this.showBookmarkTitleInput = true
|
|
|
|
},
|
|
|
|
deleteBookmark(bm) {
|
2022-03-18 02:28:04 +01:00
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/me/item/${this.libraryItemId}/bookmark/${bm.time}`)
|
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('Bookmark removed')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.$toast.error(`Failed to remove bookmark`)
|
|
|
|
console.error(error)
|
|
|
|
})
|
2021-11-03 23:45:47 +01:00
|
|
|
this.show = false
|
2021-10-27 03:09:04 +02:00
|
|
|
},
|
2021-10-25 01:25:44 +02:00
|
|
|
clickBookmark(bm) {
|
|
|
|
this.$emit('select', bm)
|
|
|
|
},
|
2021-11-03 23:45:47 +01:00
|
|
|
submitUpdateBookmark(updatedBookmark) {
|
|
|
|
var bookmark = { ...updatedBookmark }
|
2022-03-18 02:28:04 +01:00
|
|
|
this.$axios
|
|
|
|
.$patch(`/api/me/item/${this.libraryItemId}/bookmark`, bookmark)
|
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('Bookmark updated')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.$toast.error(`Failed to update bookmark`)
|
|
|
|
console.error(error)
|
|
|
|
})
|
2021-11-03 23:45:47 +01:00
|
|
|
this.show = false
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2021-11-03 23:45:47 +01:00
|
|
|
submitCreateBookmark() {
|
|
|
|
if (!this.newBookmarkTitle) {
|
|
|
|
this.newBookmarkTitle = this.$formatDate(Date.now(), 'MMM dd, yyyy HH:mm')
|
2021-10-25 01:25:44 +02:00
|
|
|
}
|
2021-11-03 23:45:47 +01:00
|
|
|
var bookmark = {
|
|
|
|
title: this.newBookmarkTitle,
|
2022-03-18 02:28:04 +01:00
|
|
|
time: Math.floor(this.currentTime)
|
2021-11-03 23:45:47 +01:00
|
|
|
}
|
2022-03-18 02:28:04 +01:00
|
|
|
this.$axios
|
|
|
|
.$post(`/api/me/item/${this.libraryItemId}/bookmark`, bookmark)
|
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('Bookmark added')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.$toast.error(`Failed to create bookmark`)
|
|
|
|
console.error(error)
|
|
|
|
})
|
2021-11-03 23:45:47 +01:00
|
|
|
|
2021-10-25 01:25:44 +02:00
|
|
|
this.newBookmarkTitle = ''
|
|
|
|
this.showBookmarkTitleInput = false
|
2021-11-03 23:45:47 +01:00
|
|
|
|
|
|
|
this.show = false
|
2021-10-25 01:25:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|