Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow time entry for custom durations; show time elapsed and remaining during video playback #3661

Merged
merged 12 commits into from
Dec 9, 2024
34 changes: 6 additions & 28 deletions src/components/dialog/DialogAudioBible.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,14 @@ import type {
} from 'src/types';

import { whenever } from '@vueuse/core';
import { storeToRefs } from 'pinia';
import { errorCatcher } from 'src/helpers/error-catcher';
import {
downloadAdditionalRemoteVideo,
getAudioBibleMedia,
} from 'src/helpers/jw-media';
import { useCurrentStateStore } from 'src/stores/current-state';
import { useJwStore } from 'src/stores/jw';
import { timeToSeconds } from 'src/utils/time';
import { computed, ref, watch } from 'vue';

// Stores
const currentStateStore = useCurrentStateStore();
const { currentCongregation, selectedDate } = storeToRefs(currentStateStore);
const jwStore = useJwStore();
const { customDurations } = storeToRefs(jwStore);

// Props
const props = defineProps<{
section: MediaSection | undefined;
Expand Down Expand Up @@ -337,11 +329,6 @@ const addSelectedVerses = async () => {
const startVerseNumber = chosenVerses.value[0];
const endVerseNumber = chosenVerses.value[1] || startVerseNumber;

const timeToSeconds = (time: string) => {
const [h, m, s] = time.split(':').map(parseFloat);
return (h ?? 0) * 3600 + (m ?? 0) * 60 + (s ?? 0);
};

const min = timeToSeconds(
selectedChapterMedia.value.map((item) =>
item.markers.markers.find(
Expand All @@ -359,7 +346,7 @@ const addSelectedVerses = async () => {
? timeToSeconds(endVerse.startTime) + timeToSeconds(endVerse.duration)
: 0;

const uniqueId = await downloadAdditionalRemoteVideo(
await downloadAdditionalRemoteVideo(
selectedChapterMedia.value,
undefined,
false,
Expand All @@ -371,21 +358,12 @@ const addSelectedVerses = async () => {
.filter((verse, index, self) => self.indexOf(verse) === index)
.join('-'),
props.section,
{
max,
min,
},
);

if (
uniqueId &&
min &&
max &&
selectedDate.value &&
currentCongregation.value
) {
const congregation = (customDurations.value[currentCongregation.value] ??=
{});
const dateDurations = (congregation[selectedDate.value] ??= {});
dateDurations[uniqueId] = { max, min };
}

resetBibleBook(true, true);

loading.value = false;
Expand Down
Loading
Loading