2021-10-25 01:25:44 +02:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="bookmarks" :width="500" :height="'unset'">
|
2022-07-30 02:06:52 +02:00
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-3xl text-white truncate">{{ $strings.LabelYourBookmarks }}</p>
|
2022-07-30 02:06:52 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div ref="container" class="w-full rounded-lg bg-bg 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">
|
2022-11-08 15:37:39 +01:00
|
|
|
<p class="text-xl">{{ $strings.MessageNoBookmarks }}</p>
|
2021-10-25 01:25:44 +02:00
|
|
|
</div>
|
2022-07-30 02:06:52 +02:00
|
|
|
<div v-if="!hideCreate" class="w-full h-px bg-white bg-opacity-10" />
|
|
|
|
<form v-if="!hideCreate" @submit.prevent="submitCreateBookmark">
|
2021-11-03 23:45:47 +01:00
|
|
|
<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>
|
2024-07-08 18:36:37 +02:00
|
|
|
<ui-btn type="submit" color="success" :padding-x="4" class="h-10"><span class="material-symbols text-2xl -mt-px">add</span></ui-btn>
|
2021-11-03 23:45:47 +01:00
|
|
|
</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-07-30 02:06:52 +02:00
|
|
|
libraryItemId: String,
|
|
|
|
hideCreate: Boolean
|
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)
|
2023-02-27 19:04:26 +01:00
|
|
|
},
|
|
|
|
dateFormat() {
|
|
|
|
return this.$store.state.serverSettings.dateFormat
|
|
|
|
},
|
|
|
|
timeFormat() {
|
|
|
|
return this.$store.state.serverSettings.timeFormat
|
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(() => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastBookmarkRemoveSuccess)
|
2022-03-18 02:28:04 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkRemoveFailed)
|
2022-03-18 02:28:04 +01:00
|
|
|
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(() => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastBookmarkUpdateSuccess)
|
2022-03-18 02:28:04 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkUpdateFailed)
|
2022-03-18 02:28:04 +01:00
|
|
|
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) {
|
2023-02-27 19:04:26 +01:00
|
|
|
this.newBookmarkTitle = this.$formatDatetime(Date.now(), this.dateFormat, this.timeFormat)
|
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(() => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastBookmarkCreateSuccess)
|
2022-03-18 02:28:04 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkCreateFailed)
|
2022-03-18 02:28:04 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-27 19:04:26 +01:00
|
|
|
</script>
|