Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/platform/assets/components/MediaAssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"
class="absolute inset-0"
@download="handleDownload"
@video-playing-state-changed="isVideoPlaying = $event"
@video-controls-changed="showVideoControls = $event"
@image-loaded="handleImageLoaded"
/>

Expand Down Expand Up @@ -243,9 +241,6 @@ const emit = defineEmits<{
'context-menu': [event: MouseEvent, asset: AssetItem]
}>()

const isVideoPlaying = ref(false)
const showVideoControls = ref(false)

// Store actual image dimensions
const imageDimensions = ref<{ width: number; height: number } | undefined>()

Expand Down Expand Up @@ -299,9 +294,7 @@ const adaptedAsset = computed(() => {

provide(MediaAssetKey, {
asset: toRef(() => adaptedAsset.value),
context: toRef(() => ({ type: assetType.value })),
isVideoPlaying,
showVideoControls
context: toRef(() => ({ type: assetType.value }))
})

const formattedDuration = computed(() => {
Expand Down
21 changes: 11 additions & 10 deletions src/platform/assets/components/MediaVideoTop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,32 @@ describe('MediaVideoTop', () => {
expect(container.querySelector('source')).not.toBeInTheDocument()
})

it('emits playback events and hides paused overlay while playing', async () => {
it('shows native controls only while playing and hovered', async () => {
const user = userEvent.setup()
const { container, emitted } = render(MediaVideoTop, {
const { container } = render(MediaVideoTop, {
props: {
asset: createVideoAsset('https://example.com/thumb.jpg')
}
})

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <video> has no ARIA role in happy-dom
const video = container.querySelector('video')!
expect(video).toBeInTheDocument()
// eslint-disable-next-line testing-library/no-node-access -- root wrapper has no role
const wrapper = container.firstElementChild!

await fireEvent.play(video)
expect(emitted()['videoPlayingStateChanged']?.at(-1)).toEqual([true])
expect(video.controls).toBe(false)

// eslint-disable-next-line testing-library/no-node-access -- root wrapper has no role
await user.hover(container.firstElementChild!)
await user.hover(wrapper)
expect(video.controls).toBe(true)

// eslint-disable-next-line testing-library/no-node-access -- root wrapper has no role
await user.unhover(container.firstElementChild!)
await fireEvent.pause(video)
expect(video.controls).toBe(false)

await fireEvent.pause(video)
expect(emitted()['videoPlayingStateChanged']?.at(-1)).toEqual([false])
await fireEvent.play(video)
expect(video.controls).toBe(true)

await user.unhover(wrapper)
expect(video.controls).toBe(false)
})

Expand Down
17 changes: 1 addition & 16 deletions src/platform/assets/components/MediaVideoTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</template>

<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { computed, ref } from 'vue'

import type { AssetMeta } from '../schemas/mediaAssetSchema'

Expand All @@ -38,11 +38,6 @@ const { asset, showNativeControls = true } = defineProps<{
showNativeControls?: boolean
}>()

const emit = defineEmits<{
videoPlayingStateChanged: [isPlaying: boolean]
videoControlsChanged: [showControls: boolean]
}>()

const videoElement = ref<HTMLVideoElement | null>(null)
const isHovered = ref(false)
const isPlaying = ref(false)
Expand All @@ -52,22 +47,12 @@ const shouldShowControls = computed(
() => showNativeControls && isPlaying.value && isHovered.value
)

watch(shouldShowControls, (controlsVisible) => {
emit('videoControlsChanged', controlsVisible)
})

onMounted(() => {
emit('videoControlsChanged', shouldShowControls.value)
})

const onVideoPlay = () => {
isPlaying.value = true
emit('videoPlayingStateChanged', true)
}

const onVideoPause = () => {
isPlaying.value = false
emit('videoPlayingStateChanged', false)
}

async function onVideoClick(event: MouseEvent) {
Expand Down
4 changes: 1 addition & 3 deletions src/platform/assets/composables/useMediaAssetActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ function mountMediaActions(asset?: AssetMeta) {
setup() {
provide(MediaAssetKey, {
asset: ref(asset),
context: ref({ type: 'input' as const }),
isVideoPlaying: ref(false),
showVideoControls: ref(false)
context: ref({ type: 'input' as const })
})
return () => h(ChildComponent)
}
Expand Down
2 changes: 0 additions & 2 deletions src/platform/assets/schemas/mediaAssetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export type AssetContext = z.infer<typeof zAssetContextSchema>
interface MediaAssetProviderValue {
asset: Ref<AssetMeta | undefined>
context: Ref<AssetContext>
isVideoPlaying: Ref<boolean>
showVideoControls: Ref<boolean>
}

export const MediaAssetKey: InjectionKey<MediaAssetProviderValue> =
Expand Down
Loading