Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat(media): preview PDFs in the lightbox dialog

Paulo Castellano1206448f17f8
diff --git a/resources/js/components/ImagePreviewDialog.vue b/resources/js/components/ImagePreviewDialog.vue
index e93a7078e..4e57d7c3b 100644
--- a/resources/js/components/ImagePreviewDialog.vue
+++ b/resources/js/components/ImagePreviewDialog.vue
@@ -3,13 +3,14 @@ import { IconChevronLeft, IconChevronRight } from '@tabler/icons-vue';
import { computed, onUnmounted, ref, watch } from 'vue';
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
+import { MediaType } from '@/lib/mediaType';
-interface MediaItem {
+interface PreviewItem {
url: string;
- type: 'image' | 'video';
+ type: MediaType;
}
-const items = ref<MediaItem[]>([]);
+const items = ref<PreviewItem[]>([]);
const index = ref<number | null>(null);
const isOpen = computed({
@@ -27,12 +28,12 @@ const hasPrev = computed(() => safeIndex.value > 0);
const hasNext = computed(() => safeIndex.value < items.value.length - 1);
const showNav = computed(() => items.value.length > 1);
-const open = (url: string, type: 'image' | 'video' = 'image') => {
+const open = (url: string, type: MediaType = MediaType.Image) => {
items.value = [{ url, type }];
index.value = 0;
};
-const openCollection = (collection: MediaItem[], startIndex = 0) => {
+const openCollection = (collection: PreviewItem[], startIndex = 0) => {
if (collection.length === 0) return;
items.value = [...collection];
index.value = Math.max(0, Math.min(startIndex, collection.length - 1));
@@ -106,6 +107,15 @@ defineExpose({ open, openCollection, close });
@click.stop
/>
+ <iframe
+ v-else-if="currentItem && currentItem.type === 'document'"
+ :key="currentItem.url"
+ :src="currentItem.url"
+ title="PDF preview"
+ class="h-[85vh] w-full rounded-2xl bg-white"
+ @click.stop
+ />
+
<button
v-if="showNav && hasPrev"
type="button"
diff --git a/resources/js/components/assets/GalleryBrowser.vue b/resources/js/components/assets/GalleryBrowser.vue
index 7455b8451..ba603dd5d 100644
--- a/resources/js/components/assets/GalleryBrowser.vue
+++ b/resources/js/components/assets/GalleryBrowser.vue
@@ -14,7 +14,7 @@ import { Skeleton } from '@/components/ui/skeleton';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import debounce from '@/debounce';
-import { acceptAttribute, isDocument, isVideo, type MediaType } from '@/lib/mediaType';
+import { acceptAttribute, classify, isDocument, isVideo, MediaType } from '@/lib/mediaType';
import { destroy as assetsDestroy, search as assetsSearch, storeChunked as assetsStoreChunked, storeFromUrl } from '@/routes/app/assets';
import { search as giphySearch, trending as giphyTrending } from '@/routes/app/assets/giphy';
import { search as unsplashSearch, trending as unsplashTrending } from '@/routes/app/assets/unsplash';
@@ -95,17 +95,11 @@ const handleAssetClick = (asset: AssetMedia) => {
toggleSelect(asset);
return;
}
- // PDFs can't render in the image lightbox — open them in a new tab.
- if (isDocument(asset)) {
- window.open(asset.url, '_blank', 'noopener');
- return;
- }
- const previewable = uploads.value.filter((a) => !isDocument(a));
- const items = previewable.map((a) => ({
+ const items = uploads.value.map((a) => ({
url: a.url,
- type: isVideo(a) ? ('video' as const) : ('image' as const),
+ type: classify(a) ?? MediaType.Image,
}));
- const idx = previewable.findIndex((a) => a.id === asset.id);
+ const idx = uploads.value.findIndex((a) => a.id === asset.id);
lightbox.value?.openCollection(items, idx);
};
diff --git a/resources/js/components/posts/editor/PostEditorComposer.vue b/resources/js/components/posts/editor/PostEditorComposer.vue
index 368ae1781..b6d4538f2 100644
--- a/resources/js/components/posts/editor/PostEditorComposer.vue
+++ b/resources/js/components/posts/editor/PostEditorComposer.vue
@@ -23,7 +23,7 @@ import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { formatBytes } from '@/composables/useMedia';
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
-import { isDocument, isVideo } from '@/lib/mediaType';
+import { classify, isDocument, isVideo, MediaType } from '@/lib/mediaType';
import type { MediaItem } from '@/types/media';
interface Signature {
@@ -75,19 +75,12 @@ const mediaThumbRefs = ref<HTMLElement[]>([]);
const lightbox = ref<InstanceType<typeof ImagePreviewDialog> | null>(null);
const openPreview = (item: MediaItem) => {
- // PDFs can't render in the image lightbox — open them in a new tab.
- if (isDocument(item)) {
- window.open(item.url, '_blank', 'noopener');
- return;
- }
-
- const previewable = media.value.filter((m) => !isDocument(m));
- const idx = previewable.findIndex((m) => m.id === item.id);
+ const idx = media.value.findIndex((m) => m.id === item.id);
if (idx < 0) return;
lightbox.value?.openCollection(
- previewable.map((m) => ({
+ media.value.map((m) => ({
url: m.url,
- type: isVideo(m) ? 'video' as const : 'image' as const,
+ type: classify(m) ?? MediaType.Image,
})),
idx,
);
diff --git a/resources/js/pages/posts/Show.vue b/resources/js/pages/posts/Show.vue
index c78261e78..9a92ae444 100644
--- a/resources/js/pages/posts/Show.vue
+++ b/resources/js/pages/posts/Show.vue
@@ -17,7 +17,7 @@ import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo
import { getPlatformStatusConfig, getPostStatusConfig } from '@/composables/usePostStatus';
import dayjs from '@/dayjs';
import AppLayout from '@/layouts/AppLayout.vue';
-import { isDocument as isDocumentItem, isVideo as isVideoItem } from '@/lib/mediaType';
+import { classify, isDocument as isDocumentItem, isVideo as isVideoItem, MediaType } from '@/lib/mediaType';
import { index as postsIndex } from '@/routes/app/posts';
import type { MediaItem } from '@/types/media';
import { PostPlatformStatus, PostStatus } from '@/types/post';
@@ -89,20 +89,11 @@ const formatDateTime = (date: string | null): string =>
const lightbox = ref<InstanceType<typeof ImagePreviewDialog> | null>(null);
const openLightbox = (i: number) => {
- const item = props.post.media[i];
- // PDFs can't render in the image lightbox — open them in a new tab.
- if (item && isDocumentItem(item)) {
- window.open(item.url, '_blank', 'noopener');
- return;
- }
-
- const previewable = props.post.media.filter((m) => !isDocumentItem(m));
- const collection = previewable.map((m) => ({
+ const collection = props.post.media.map((m) => ({
url: m.url,
- type: isVideoItem(m) ? ('video' as const) : ('image' as const),
+ type: classify(m) ?? MediaType.Image,
}));
- const idx = previewable.findIndex((m) => m.id === item?.id);
- lightbox.value?.openCollection(collection, idx < 0 ? 0 : idx);
+ lightbox.value?.openCollection(collection, i);
};
usePostEcho(props.post.id, '.post.platform.status.updated', () => {