Skip to content

Commit

Permalink
[MS] FileControlsPlayback component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ironicbay committed Jan 3, 2025
1 parent 9aee723 commit db3823e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
30 changes: 30 additions & 0 deletions client/src/components/viewers/controls/FileControlsPlayback.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS -->

<template>
<file-controls-group>
<file-controls-button
:class="{ 'flip-horizontal-ion-icon': ended }"
:icon="playbackIcon"
/>
</file-controls-group>
</template>

<script setup lang="ts">
import { refresh, play, pause } from 'ionicons/icons';
import { FileControlsButton, FileControlsGroup } from '@/components/viewers';
import { computed } from 'vue';

const props = defineProps<{
ended: boolean;
paused: boolean;
}>();

const playbackIcon = computed((): string => {
if (props.ended) {
return refresh;
}
return props.paused ? play : pause;
});
</script>

<style scoped lang="scss"></style>
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getVolumeIcon(): string {
display: flex;

&-slider {
margin-right: 0.5rem;
margin-right: 1rem;
opacity: 1;
width: 5rem;
display: flex;
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/viewers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FileControlsButton from '@/components/viewers/controls/FileControlsButton
import FileControlsGroup from '@/components/viewers/controls/FileControlsGroup.vue';
import FileControlsInput from '@/components/viewers/controls/FileControlsInput.vue';
import FileControlsPagination from '@/components/viewers/controls/FileControlsPagination.vue';
import FileControlsPlayback from '@/components/viewers/controls/FileControlsPlayback.vue';
import FileControlsVolume from '@/components/viewers/controls/FileControlsVolume.vue';
import FileControlsZoom from '@/components/viewers/controls/FileControlsZoom.vue';

Expand All @@ -14,6 +15,7 @@ export {
FileControlsGroup,
FileControlsInput,
FileControlsPagination,
FileControlsPlayback,
FileControlsVolume,
FileControlsZoom,
};
30 changes: 8 additions & 22 deletions client/src/views/viewers/AudioViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
</template>
<template #controls>
<file-controls>
<!-- Disabled till we add an illustration in the viewer -->
<!-- <file-controls-button
:class="{'flip-horizontal-ion-icon': ended}"
:icon="getPlaybackIcon()"
<file-controls-playback
:paused="paused"
:ended="ended"
@click="togglePlayback"
/> -->
/>
<file-controls-volume @on-volume-change="updateVolume" />
</file-controls>
</template>
</file-viewer-wrapper>
</template>

<script setup lang="ts">
// import { refresh, play, pause, volumeHigh, volumeLow, volumeMedium, volumeMute } from 'ionicons/icons';
import { FileControls, FileControlsPlayback, FileControlsVolume } from '@/components/viewers';
import { onMounted, ref } from 'vue';
import { FileViewerWrapper } from '@/views/viewers';
import { FileContentInfo } from '@/views/viewers/utils';
import { FileControls, FileControlsVolume } from '@/components/viewers';

const props = defineProps<{
contentInfo: FileContentInfo;
Expand All @@ -50,9 +48,9 @@ onMounted(async () => {
src.value = URL.createObjectURL(new Blob([props.contentInfo.data], { type: props.contentInfo.mimeType }));
});

// function togglePlayback(): void {
// audioElement.value.paused ? audioElement.value.play() : audioElement.value.pause();
// }
function togglePlayback(): void {
audioElement.value.paused ? audioElement.value.play() : audioElement.value.pause();
}

function updateMediaData(event: Event): void {
paused.value = (event.target as HTMLAudioElement).paused;
Expand All @@ -62,18 +60,6 @@ function updateMediaData(event: Event): void {
function updateVolume(value: number): void {
audioElement.value.volume = value;
}

// function getPlaybackIcon(): string {
// if (ended.value) {
// return refresh;
// }
// switch (paused.value) {
// case true:
// return play;
// case false:
// return pause;
// }
// }
</script>

<style scoped lang="scss"></style>
22 changes: 5 additions & 17 deletions client/src/views/viewers/VideoViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</template>
<template #controls>
<file-controls>
<file-controls-button
:class="{ 'flip-horizontal-ion-icon': ended }"
:icon="getPlaybackIcon()"
<file-controls-playback
:paused="paused"
:ended="ended"
@click="togglePlayback"
/>
<file-controls-volume @on-volume-change="updateVolume" />
Expand All @@ -37,10 +37,10 @@
</template>

<script setup lang="ts">
import { refresh, play, pause, scan } from 'ionicons/icons';
import { scan } from 'ionicons/icons';
import { onMounted, ref } from 'vue';
import { FileContentInfo } from '@/views/viewers/utils';
import { FileControls, FileControlsButton, FileControlsVolume } from '@/components/viewers';
import { FileControls, FileControlsButton, FileControlsPlayback, FileControlsVolume } from '@/components/viewers';
import { FileViewerWrapper } from '@/views/viewers';

const props = defineProps<{
Expand Down Expand Up @@ -72,18 +72,6 @@ function updateMediaData(event: Event): void {
paused.value = (event.target as HTMLVideoElement).paused;
ended.value = (event.target as HTMLVideoElement).ended;
}

function getPlaybackIcon(): string {
if (ended.value) {
return refresh;
}
switch (paused.value) {
case true:
return play;
case false:
return pause;
}
}
</script>

<style scoped lang="scss">
Expand Down
6 changes: 3 additions & 3 deletions client/tests/e2e/specs/file_viewers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ msTest('Audio viewer', async ({ documents }) => {
await expectMedia(audio).toHaveCurrentTime(0.0);

// Volume control
const volumeButton = bottomBar.locator('.file-controls-button');
const volumeButton = bottomBar.locator('.file-controls-button').nth(1);
const volumeSlider = bottomBar.locator('.slider');
await expectMedia(audio).toHaveVolume(1);
await volumeSlider.click();
await expectMedia(audio).toHaveVolume(0.49);
await expectMedia(audio).toHaveVolume(0.48);
await volumeButton.click();
await expectMedia(audio).toHaveVolume(0);
await volumeButton.click();
await expectMedia(audio).toHaveVolume(0.49);
await expectMedia(audio).toHaveVolume(0.48);
});

msTest('Video viewer', async ({ documents }) => {
Expand Down

0 comments on commit db3823e

Please sign in to comment.