add darkmode and progress bar
parent
27ab4c870d
commit
4f7b922428
@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<div class="form-check form-switch">
|
||||
<label class="custom-control-label" for="darkSwitch">
|
||||
<slot :state="sliderState" />
|
||||
</label>
|
||||
<input v-model="sliderState" type="checkbox" class="form-check-input" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { themeConfig } from '@/main';
|
||||
|
||||
const sliderState = ref(themeConfig.getTheme() === 'dark');
|
||||
|
||||
watch(sliderState, (state) => {
|
||||
themeConfig.setTheme(state ? 'dark' : 'light');
|
||||
});
|
||||
|
||||
themeConfig.themeChangeHandlers.push((newTheme) => {
|
||||
sliderState.value = newTheme === 'dark';
|
||||
});
|
||||
</script>
|
@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import { defineProps, watch, ref } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
seconds: Number,
|
||||
});
|
||||
|
||||
const getHmsFromSeconds = (d: number) => ({
|
||||
hours: Math.floor(d / 3600),
|
||||
minutes: Math.floor(d % 3600 / 60),
|
||||
seconds: Math.floor(d % 3600 % 60),
|
||||
});
|
||||
|
||||
const getLeadingZero = (a: number, digits: number) =>
|
||||
('0'.repeat(digits) + a.toString())
|
||||
.substr(- digits);
|
||||
|
||||
const hms = ref(getHmsFromSeconds(props.seconds as number));
|
||||
|
||||
watch(() => props.seconds, (to) => {
|
||||
hms.value = getHmsFromSeconds(to as number);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-if="hms.hours" class="hours">{{ getLeadingZero(hms.hours, 2) }}:</span>
|
||||
<span class="minutes">{{ getLeadingZero(hms.minutes, 2) }}:</span>
|
||||
<span class="seconds">{{ getLeadingZero(hms.seconds, 2) }}</span>
|
||||
</template>
|
||||
|
@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { defineProps, ref, watch, onBeforeUnmount } from "vue";
|
||||
import TimeFormatter from "@/components/TimeFormatter.vue";
|
||||
|
||||
const props = defineProps({
|
||||
duration: Number,
|
||||
progress: Number,
|
||||
isPlaying: Boolean,
|
||||
});
|
||||
|
||||
const estimatedProgress = ref(props.progress as number);
|
||||
|
||||
const updateInterval = setInterval(() => {
|
||||
if (props.isPlaying) estimatedProgress.value += 1000;
|
||||
}, 1000);
|
||||
|
||||
watch(() => props.progress, (to) => {
|
||||
estimatedProgress.value = to as number;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearInterval(updateInterval);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="progress my-2">
|
||||
<div
|
||||
class="progress-bar"
|
||||
role="progressbar"
|
||||
:style="{
|
||||
width: `${ estimatedProgress / duration * 100 }%`
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
<div class="row my-2">
|
||||
<div class="col">
|
||||
<TimeFormatter :seconds="estimatedProgress / 1000"/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<TimeFormatter :seconds="duration / 1000"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.progress {
|
||||
height: 0.5rem;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue