Skip to content

Commit

Permalink
refactor: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Fernández <[email protected]>
  • Loading branch information
ferferga committed Sep 12, 2024
1 parent ff0a5ff commit 75cea0d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions frontend/src/components/Playback/SubtitleTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{ $t('subtitlePreviewText') }}
</template>
<JSafeHtml
v-else-if="currentSubtitle !== undefined"
v-else-if="!isNil(currentSubtitle?.sub)"
:html="currentSubtitle.sub.text" />
</span>
</div>
Expand Down Expand Up @@ -39,22 +39,30 @@ const { preview } = defineProps<{
* to find the next one
*/
const predicate = (d: Dialogue) => d.start <= playbackManager.currentTime && d.end >= playbackManager.currentTime;
const findSubtitle = (dialogue: ParsedSubtitleTrack['dialogue'], start = 0) =>
dialogue.slice(start).findIndex(d => predicate(d));
const findSubtitle = (dialogue: ParsedSubtitleTrack['dialogue'], start = 0) => {
const index = dialogue.slice(start).findIndex(d => predicate(d));
return index === -1 ? undefined : index;
};
const dialogue = computed(() => playerElement.currentExternalSubtitleTrack?.parsed?.dialogue);
const currentSubtitle = computed<{ index: number; sub: Dialogue } | undefined>((previous) => {
const currentSubtitle = computed<{ index: number; sub?: Dialogue | undefined } | undefined>((previous) => {
if (!isNil(dialogue.value)) {
const hasPrevious = !isNil(previous);
const isNext = hasPrevious && predicate(dialogue.value[previous.index + 1]);
const nextIndex = hasPrevious ? previous.index + 1 : 0;
const isNext = hasPrevious && predicate(dialogue.value[nextIndex]);
const isCurrent = hasPrevious && predicate(dialogue.value[previous.index]);
if (isCurrent) {
return previous;
} else {
const newIndex = isNext ? previous.index + 1 : findSubtitle(dialogue.value);
const newIndex = isNext ? nextIndex : findSubtitle(dialogue.value, nextIndex);
return { index: newIndex, sub: dialogue.value[newIndex] };
if (!isNil(newIndex)) {
return { index: newIndex, sub: dialogue.value[newIndex] };
} else if (hasPrevious) {
return { index: previous.index };
}
}
}
});
Expand Down Expand Up @@ -92,8 +100,7 @@ const subtitleStyle = computed<StyleValue>(() => {
<style scoped>
.stroked {
--webkit-text-stroke-color: black;
--webkit-text-stroke-width: 7px;
-webkit-text-stroke: 7px black;
text-shadow: 2px 2px 15px black;
paint-order: stroke fill;
}
Expand Down

0 comments on commit 75cea0d

Please sign in to comment.