More things
This commit is contained in:
57
frontend/app/components/windows/MediaViewerWindow.vue
Normal file
57
frontend/app/components/windows/MediaViewerWindow.vue
Normal file
@@ -0,0 +1,57 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { SetupHandle, SetSize, ResetPosition, Top } from '@/services/Windows';
|
||||
import { getBaseUrl } from '~/services/Server';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
|
||||
// One media file of the note tree, shown in a window of its own: an image fills it, a sound and a
|
||||
// video play in it, and anything else (a PDF, a document) is offered as a link to open.
|
||||
const props = defineProps(['data']);
|
||||
const id = props.data.id;
|
||||
const media = props.data.media;
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
|
||||
const url = computed(() => media?.file ? `${getBaseUrl()}/public/${media.file}` : '');
|
||||
const kind = computed(() => {
|
||||
const type = media?.mimeType ?? '';
|
||||
if (type.startsWith('image/')) return 'image';
|
||||
if (type.startsWith('audio/')) return 'audio';
|
||||
if (type.startsWith('video/')) return 'video';
|
||||
return 'file';
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
Top(wrapper);
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, {
|
||||
width: Math.max(420, Math.min(900, window.innerWidth - 24)),
|
||||
height: Math.max(320, Math.min(700, window.innerHeight - 32))
|
||||
});
|
||||
ResetPosition(id, 'center');
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper media-window" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle" />
|
||||
|
||||
<div class="media-body">
|
||||
<img v-if="kind === 'image'" class="media-image" :src="url" :alt="media?.name">
|
||||
<audio v-else-if="kind === 'audio'" :src="url" controls></audio>
|
||||
<video v-else-if="kind === 'video'" :src="url" controls></video>
|
||||
<a v-else class="media-file" :href="url" target="_blank" rel="noopener">{{ media?.name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.media-window { min-width: 320px; min-height: 0; }
|
||||
.media-body {
|
||||
flex: 1; min-height: 0; box-sizing: border-box; padding: 10px;
|
||||
display: flex; align-items: center; justify-content: center; overflow: auto;
|
||||
}
|
||||
.media-image { max-width: 100%; max-height: 100%; object-fit: contain; }
|
||||
audio, video { max-width: 100%; }
|
||||
.media-file { color: var(--color-link); word-break: break-word; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user