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: add support for video thumbnail preview in the attachment library #6265

Merged
merged 3 commits into from
Jul 10, 2024
Merged
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
33 changes: 19 additions & 14 deletions ui/console-src/modules/contents/attachments/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ import AttachmentGroupList from "./components/AttachmentGroupList.vue";
import AttachmentListItem from "./components/AttachmentListItem.vue";
import AttachmentPoliciesModal from "./components/AttachmentPoliciesModal.vue";
import AttachmentUploadModal from "./components/AttachmentUploadModal.vue";
import AttachmentLoading from "./components/AttachmentLoading.vue";
import AttachmentError from "./components/AttachmentError.vue";
import { useAttachmentControl } from "./composables/use-attachment";
import { useFetchAttachmentGroup } from "./composables/use-attachment-group";
import { useFetchAttachmentPolicy } from "./composables/use-attachment-policy";
import LazyVideo from "@/components/video/LazyVideo.vue";

const { t } = useI18n();

Expand Down Expand Up @@ -526,24 +529,26 @@ onMounted(() => {
classes="pointer-events-none object-cover group-hover:opacity-75 transform-gpu"
>
<template #loading>
<div
class="flex h-full items-center justify-center object-cover"
>
<span class="text-xs text-gray-400">
{{ $t("core.common.status.loading") }}...
</span>
</div>
<AttachmentLoading />
</template>
<template #error>
<div
class="flex h-full items-center justify-center object-cover"
>
<span class="text-xs text-red-400">
{{ $t("core.common.status.loading_error") }}
</span>
</div>
<AttachmentError />
</template>
</LazyImage>
<LazyVideo
v-else-if="
attachment?.spec.mediaType?.startsWith('video/')
"
:src="attachment.status?.permalink"
LonelySnowman marked this conversation as resolved.
Show resolved Hide resolved
classes="object-cover group-hover:opacity-75"
>
<template #loading>
<AttachmentLoading />
</template>
<template #error>
<AttachmentError />
</template>
</LazyVideo>
<AttachmentFileTypeIcon
v-else
:file-name="attachment.spec.displayName"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div class="flex h-full items-center justify-center object-cover">
<span class="text-xs text-red-400">
{{ $t("core.common.status.loading_error") }}
</span>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div class="flex h-full items-center justify-center object-cover">
<span class="text-xs text-gray-400">
{{ $t("core.common.status.loading") }}...
</span>
</div>
</template>
47 changes: 47 additions & 0 deletions ui/src/components/video/LazyVideo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts" setup>
import { onMounted, ref } from "vue";

const props = withDefaults(
defineProps<{
src: string;
classes?: string | string[];
}>(),
{
src: "",
classes: "",
}
);

const isLoading = ref(false);
const error = ref(false);

const loadVideo = async () => {
const video = document.createElement("video");
video.src = props.src;
return new Promise((resolve, reject) => {
video.onloadedmetadata = () => resolve(video);
video.onerror = (err) => reject(err);
});
};

onMounted(async () => {
isLoading.value = true;
try {
await loadVideo();
} catch (e) {
error.value = true;
} finally {
isLoading.value = false;
}
isLoading.value = false;
});
</script>
<template>
<template v-if="isLoading">
<slot name="loading"> loading... </slot>
</template>
<template v-else-if="error">
<slot name="error"> error </slot>
</template>
<video v-else :src="src" preload="metadata" :class="classes" />
</template>
Loading