advplyr.audiobookshelf-app/components/modals/SleepTimerModal.vue

112 lines
4.5 KiB
Vue
Raw Normal View History

2021-10-30 13:31:21 -05:00
<template>
<modals-modal v-model="show" :width="200" height="100%">
<template #outer>
<div class="absolute top-5 left-4 z-40">
2021-10-30 13:31:21 -05:00
<p class="text-white text-2xl truncate">Sleep Timer</p>
</div>
</template>
2022-08-18 13:44:23 +02:00
<div class="w-full h-full overflow-hidden absolute top-0 left-0 flex items-center justify-center" @click="show = false; manualTimerModal = false">
2021-10-30 13:31:21 -05:00
<div class="w-full overflow-x-hidden overflow-y-auto bg-primary rounded-lg border border-white border-opacity-20" style="max-height: 75%" @click.stop>
2022-08-18 13:44:23 +02:00
<div v-show="manualTimerModal" class="px-2 py-4">
<div class="text-gray-50 select-none relative py-3 pl-9" @click="manualTimerModal = false">
<div class="absolute right-1 top-0 bottom-0 h-full flex items-center">
<span class="material-icons text-2xl">close</span>
</div>
</div>
<div class="flex my-2 justify-between">
<ui-btn @click="manualTimeoutMin--" class="w-9 h-9" :padding-x="0" small style="max-width: 36px"><span class="material-icons">remove</span></ui-btn>
<p class="text-2xl font-mono text-center">{{ manualTimeoutMin }} min</p>
<ui-btn @click="manualTimeoutMin++" class="w-9 h-9" :padding-x="0" small style="max-width: 36px"><span class="material-icons">add</span></ui-btn>
</div>
<ui-btn @click="clickedOption(manualTimeoutMin)" class="w-full">Set Timer</ui-btn>
</div>
<ul v-show="!manualTimerModal" v-if="!sleepTimerRunning" class="h-full w-full" role="listbox" aria-labelledby="listbox-label">
2021-10-30 13:31:21 -05:00
<template v-for="timeout in timeouts">
<li :key="timeout" class="text-gray-50 select-none relative py-4 cursor-pointer hover:bg-black-400" role="option" @click="clickedOption(timeout)">
2021-10-30 13:31:21 -05:00
<div class="flex items-center justify-center">
<span class="font-normal block truncate text-lg">{{ timeout }} min</span>
2021-10-30 13:31:21 -05:00
</div>
</li>
</template>
<li v-if="currentEndOfChapterTime" class="text-gray-50 select-none relative py-4 cursor-pointer hover:bg-black-400" role="option" @click="clickedChapterOption(timeout)">
<div class="flex items-center justify-center">
<span class="font-normal block truncate text-lg text-center">End of Chapter</span>
</div>
</li>
2022-08-18 13:44:23 +02:00
<li class="text-gray-50 select-none relative py-4 cursor-pointer hover:bg-black-400" role="option" @click="manualTimerModal = true">
<div class="flex items-center justify-center">
<span class="font-normal block truncate text-lg text-center">Manual sleep timer</span>
</div>
</li>
2021-10-30 13:31:21 -05:00
</ul>
<div v-else class="px-2 py-4">
<div class="flex my-2 justify-between">
<ui-btn @click="decreaseSleepTime" class="w-9 h-9" :padding-x="0" small style="max-width: 36px"><span class="material-icons">remove</span></ui-btn>
<p class="text-2xl font-mono text-center">{{ timeRemainingPretty }}</p>
<ui-btn @click="increaseSleepTime" class="w-9 h-9" :padding-x="0" small style="max-width: 36px"><span class="material-icons">add</span></ui-btn>
</div>
2021-10-30 13:31:21 -05:00
<ui-btn @click="cancelSleepTimer" class="w-full">Cancel Timer</ui-btn>
</div>
</div>
</div>
</modals-modal>
</template>
<script>
export default {
props: {
value: Boolean,
currentTime: Number,
sleepTimerRunning: Boolean,
currentEndOfChapterTime: Number
2021-10-30 13:31:21 -05:00
},
data() {
2022-08-18 13:44:23 +02:00
return {
manualTimerModal: null,
manualTimeoutMin: 0,
}
2021-10-30 13:31:21 -05:00
},
computed: {
show: {
get() {
return this.value
},
set(val) {
this.$emit('input', val)
}
},
timeouts() {
2022-08-18 13:44:23 +02:00
return [5, 10, 15, 30, 45, 60, 90]
2021-10-30 13:31:21 -05:00
},
timeRemainingPretty() {
return this.$secondsToTimestamp(this.currentTime)
2021-10-30 13:31:21 -05:00
}
},
methods: {
clickedChapterOption() {
this.show = false
this.$nextTick(() => this.$emit('change', { time: this.currentEndOfChapterTime * 1000, isChapterTime: true }))
},
2021-10-30 13:31:21 -05:00
clickedOption(timeoutMin) {
var timeout = timeoutMin * 1000 * 60
this.show = false
2022-08-18 13:44:23 +02:00
this.manualTimerModal = false
this.$nextTick(() => this.$emit('change', { time: timeout, isChapterTime: false }))
2021-10-30 13:31:21 -05:00
},
cancelSleepTimer() {
this.$emit('cancel')
this.show = false
},
increaseSleepTime() {
this.$emit('increase')
},
decreaseSleepTime() {
this.$emit('decrease')
2021-10-30 13:31:21 -05:00
}
},
mounted() {}
}
</script>