Hola Chicos , Yo he refactor el ./src/components/Games/GameVideoPlayer.vue file , para mejorar la UX .
<script setup>
import { ref, onMounted, watch } from 'vue';
const props = defineProps({
video: {
type: String,
required: true,
},
})
const videoRef = ref(null);
watch(
() => props.video,
() => {
// Forzamos al elemento de video a recargar la fuente
if (videoRef.value) {
videoRef.value.load();
}
}
);
onMounted(() => {
if (videoRef.value) {
// Intenta cargar si ya está disponible en el DOM
videoRef.value.load();
}
});
</script>
<template>
<div class="game-video-player">
<video controls ref="videoRef">
<source :src="video" type="video/mp4" />
</video>
<p v-if="!video" style="color: red;">No video available</p>
</div>
</template>
<style scoped>
.game-video-player {
max-width: 100%;
overflow: hidden;
}
video {
width: 100%;
height: auto;
}
</style>
tambien he actualizado el ./src/components/Games/GameModal.vue :
<script setup>
const gameVideo = computed(() => {
return modalStore?.state?.game?.videosUrls?.tablet ?? null;
});
const handleKeydown = (event) => {
// Solo actualizo si el modal está visible y la tecla es 'Escape'
if (modalStore.state.show && event.key === 'Escape') {
modalStore.closeModal();
}
};
// Se añade el event listener cuando el componente (GameModal) se monta
onMounted(() => {
document.addEventListener('keydown', handleKeydown);
});
// Se elimina el event listener cuando el componente (GameModal) se desmonta
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown);
});
</script>
junto con <templates>
<template>
<div class="game-modal" v-if="modalStore.state.show">
<div class="game-modal__backdrop" @click="modalStore.closeModal" />
<div class="game-modal__content">
<h3 class="game-modal__title">{{ modalStore?.state?.game?.title || 'Video del Juego' }}</h3>
<GameVideoPlayer v-if="gameVideo" :video="gameVideo" />
<p v-else style="text-align: center; color: #e74c3c;">
No se encontró URL de video válida (videoUrls.tablet).
</p>
<button @click="modalStore.closeModal" class="game-modal__close-button">Close</button>
</div>
</div>
</template>