2021-11-02 19:44:42 -05:00
|
|
|
<template>
|
2023-09-17 09:28:43 -05:00
|
|
|
<modals-modal v-model="show" :width="400" height="100%">
|
2021-11-02 19:44:42 -05:00
|
|
|
<template #outer>
|
2023-02-26 14:41:18 -06:00
|
|
|
<div class="absolute top-8 left-4 z-40">
|
2023-12-03 17:37:01 -06:00
|
|
|
<p class="text-white text-2xl truncate">{{ $strings.LabelYourBookmarks }}</p>
|
2021-11-02 19:44:42 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div class="w-full h-full overflow-hidden absolute top-0 left-0 flex items-center justify-center" @click="show = false">
|
2023-12-10 17:53:27 -06:00
|
|
|
<div ref="container" class="w-full rounded-lg bg-primary border border-border overflow-y-auto overflow-x-hidden" style="max-height: 80vh" @click.stop.prevent>
|
2021-11-02 19:44:42 -05:00
|
|
|
<div class="w-full h-full p-4" v-show="showBookmarkTitleInput">
|
|
|
|
<div class="flex mb-4 items-center">
|
|
|
|
<div class="w-9 h-9 flex items-center justify-center rounded-full hover:bg-white hover:bg-opacity-10 cursor-pointer" @click.stop="showBookmarkTitleInput = false">
|
|
|
|
<span class="material-icons text-3xl">arrow_back</span>
|
|
|
|
</div>
|
|
|
|
<p class="text-xl pl-2">{{ selectedBookmark ? 'Edit Bookmark' : 'New Bookmark' }}</p>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<p class="text-xl font-mono">
|
|
|
|
{{ this.$secondsToTimestamp(currentTime) }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ui-text-input-with-label v-model="newBookmarkTitle" label="Note" />
|
|
|
|
<div class="flex justify-end mt-6">
|
|
|
|
<ui-btn color="success" class="w-full" @click.stop="submitBookmark">{{ selectedBookmark ? 'Update' : 'Create' }}</ui-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="w-full h-full" v-show="!showBookmarkTitleInput">
|
|
|
|
<template v-for="bookmark in bookmarks">
|
|
|
|
<modals-bookmarks-bookmark-item :key="bookmark.id" :highlight="currentTime === bookmark.time" :bookmark="bookmark" @click="clickBookmark" @edit="editBookmark" @delete="deleteBookmark" />
|
|
|
|
</template>
|
|
|
|
<div v-if="!bookmarks.length" class="flex h-32 items-center justify-center">
|
2023-12-03 17:37:01 -06:00
|
|
|
<p class="text-xl">{{ $strings.MessageNoBookmarks }}</p>
|
2021-11-02 19:44:42 -05:00
|
|
|
</div>
|
2023-12-10 17:53:27 -06:00
|
|
|
<div v-show="canCreateBookmark" class="flex px-4 py-2 items-center text-center justify-between border-b border-fg/10 bg-success cursor-pointer text-white text-opacity-80" @click.stop="createBookmark">
|
2021-11-02 19:44:42 -05:00
|
|
|
<span class="material-icons">add</span>
|
2023-12-03 17:37:01 -06:00
|
|
|
<p class="text-base pl-2">{{ $strings.ButtonCreateBookmark }}</p>
|
2021-11-02 19:44:42 -05:00
|
|
|
<p class="text-sm font-mono">
|
|
|
|
{{ this.$secondsToTimestamp(currentTime) }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-23 14:19:56 -05:00
|
|
|
import { Dialog } from '@capacitor/dialog'
|
2022-12-08 00:28:28 -05:00
|
|
|
|
2021-11-02 19:44:42 -05:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: Boolean,
|
|
|
|
bookmarks: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
|
|
|
currentTime: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
2022-04-23 14:19:56 -05:00
|
|
|
libraryItemId: String
|
2021-11-02 19:44:42 -05:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedBookmark: null,
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canCreateBookmark() {
|
|
|
|
return !this.bookmarks.find((bm) => bm.time === this.currentTime)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
editBookmark(bm) {
|
|
|
|
this.selectedBookmark = bm
|
|
|
|
this.newBookmarkTitle = bm.title
|
|
|
|
this.showBookmarkTitleInput = true
|
|
|
|
},
|
2022-04-23 14:19:56 -05:00
|
|
|
async deleteBookmark(bm) {
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2022-04-23 14:19:56 -05:00
|
|
|
const { value } = await Dialog.confirm({
|
|
|
|
title: 'Remove Bookmark',
|
2023-12-03 17:37:01 -06:00
|
|
|
message: this.$strings.MessageConfirmRemoveBookmark
|
2022-04-23 14:19:56 -05:00
|
|
|
})
|
|
|
|
if (!value) return
|
|
|
|
|
2023-09-17 09:28:43 -05:00
|
|
|
this.$nativeHttp
|
|
|
|
.delete(`/api/me/item/${this.libraryItemId}/bookmark/${bm.time}`)
|
2022-04-23 14:19:56 -05:00
|
|
|
.then(() => {
|
2023-11-04 16:08:19 -05:00
|
|
|
this.$store.commit('user/deleteBookmark', { libraryItemId: this.libraryItemId, time: bm.time })
|
2022-04-23 14:19:56 -05:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2023-12-03 17:37:01 -06:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkRemoveFailed)
|
2022-04-23 14:19:56 -05:00
|
|
|
console.error(error)
|
|
|
|
})
|
2021-11-02 19:44:42 -05:00
|
|
|
},
|
2022-12-08 00:28:28 -05:00
|
|
|
async clickBookmark(bm) {
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2021-11-02 19:44:42 -05:00
|
|
|
this.$emit('select', bm)
|
|
|
|
},
|
2022-04-23 14:19:56 -05:00
|
|
|
submitUpdateBookmark(updatedBookmark) {
|
2023-09-17 09:28:43 -05:00
|
|
|
this.$nativeHttp
|
2023-11-04 16:08:19 -05:00
|
|
|
.patch(`/api/me/item/${this.libraryItemId}/bookmark`, updatedBookmark)
|
|
|
|
.then((bookmark) => {
|
|
|
|
this.$store.commit('user/updateBookmark', bookmark)
|
|
|
|
this.showBookmarkTitleInput = false
|
2022-04-23 14:19:56 -05:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2023-12-03 17:37:01 -06:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkUpdateFailed)
|
2022-04-23 14:19:56 -05:00
|
|
|
console.error(error)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
submitCreateBookmark() {
|
|
|
|
if (!this.newBookmarkTitle) {
|
|
|
|
this.newBookmarkTitle = this.$formatDate(Date.now(), 'MMM dd, yyyy HH:mm')
|
|
|
|
}
|
2023-09-17 09:28:43 -05:00
|
|
|
const bookmark = {
|
2022-04-23 14:19:56 -05:00
|
|
|
title: this.newBookmarkTitle,
|
|
|
|
time: Math.floor(this.currentTime)
|
|
|
|
}
|
2023-09-17 09:28:43 -05:00
|
|
|
this.$nativeHttp
|
|
|
|
.post(`/api/me/item/${this.libraryItemId}/bookmark`, bookmark)
|
2022-04-23 14:19:56 -05:00
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('Bookmark added')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2023-12-03 17:37:01 -06:00
|
|
|
this.$toast.error(this.$strings.ToastBookmarkCreateFailed)
|
2022-04-23 14:19:56 -05:00
|
|
|
console.error(error)
|
|
|
|
})
|
|
|
|
|
|
|
|
this.newBookmarkTitle = ''
|
|
|
|
this.showBookmarkTitleInput = false
|
|
|
|
|
|
|
|
this.show = false
|
|
|
|
},
|
2021-11-02 19:44:42 -05:00
|
|
|
createBookmark() {
|
|
|
|
this.selectedBookmark = null
|
|
|
|
this.newBookmarkTitle = this.$formatDate(Date.now(), 'MMM dd, yyyy HH:mm')
|
|
|
|
this.showBookmarkTitleInput = true
|
|
|
|
},
|
2022-12-08 00:28:28 -05:00
|
|
|
async submitBookmark() {
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2021-11-02 19:44:42 -05:00
|
|
|
if (this.selectedBookmark) {
|
2022-04-23 14:19:56 -05:00
|
|
|
var updatePayload = {
|
|
|
|
...this.selectedBookmark,
|
|
|
|
title: this.newBookmarkTitle
|
2021-11-02 19:44:42 -05:00
|
|
|
}
|
2022-04-23 14:19:56 -05:00
|
|
|
this.submitUpdateBookmark(updatePayload)
|
2021-11-02 19:44:42 -05:00
|
|
|
} else {
|
2022-04-23 14:19:56 -05:00
|
|
|
this.submitCreateBookmark()
|
2021-11-02 19:44:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|