Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(new-channels): better media sizing (#1987)

teo02f04a53ccc9
diff --git a/js/app/packages/channel/Message/Attachments.tsx b/js/app/packages/channel/Message/Attachments.tsx
index fcd8603673..3484cdda5a 100644
--- a/js/app/packages/channel/Message/Attachments.tsx
+++ b/js/app/packages/channel/Message/Attachments.tsx
@@ -1,7 +1,4 @@
-import { ImageGalleryPreview } from '@core/component/ImageGalleryPreview';
-import { ImagePreview } from '@core/component/ImagePreview';
import { ItemPreview } from '@core/component/ItemPreview';
-import { VideoPreview } from '@core/component/VideoPreview';
import {
isStaticAttachmentType,
STATIC_IMAGE,
@@ -12,6 +9,7 @@ import type { ApiMessageAttachment } from '@service-storage/generated/schemas/ap
import { cn } from '@ui/utils/classname';
import { createMemo, For, Match, Show, Switch } from 'solid-js';
import { useMessage } from './context';
+import { MediaPreview } from './MediaPreview';
type AttachmentsProps = {
class?: string;
@@ -85,7 +83,7 @@ export function Attachments(props: AttachmentsProps) {
<Show when={buckets().videoAttachments.length > 0}>
<For each={buckets().videoAttachments}>
{(attachment) => (
- <VideoPreview id={attachment.entity_id} variant="dynamic" />
+ <MediaPreview kind="video" id={attachment.entity_id} />
)}
</For>
</Show>
@@ -94,16 +92,16 @@ export function Attachments(props: AttachmentsProps) {
<div class="flex not-first:mt-2">
<Switch>
<Match when={buckets().imageAttachments.length === 1}>
- <ImagePreview
+ <MediaPreview
+ kind="single-image"
image={imagePreviewData()[0]!}
- variant="dynamic"
/>
</Match>
<Match when={buckets().imageAttachments.length > 1}>
- <ImageGalleryPreview
+ <MediaPreview
+ kind="image-gallery"
images={imagePreviewData()}
attachmentIds={imageAttachmentIds()}
- variant="dynamic"
/>
</Match>
</Switch>
diff --git a/js/app/packages/channel/Message/MediaPreview.tsx b/js/app/packages/channel/Message/MediaPreview.tsx
new file mode 100644
index 0000000000..628e760209
--- /dev/null
+++ b/js/app/packages/channel/Message/MediaPreview.tsx
@@ -0,0 +1,111 @@
+import { ImageGalleryPreview } from '@core/component/ImageGalleryPreview';
+import { ImagePreview } from '@core/component/ImagePreview';
+import { VideoPreview } from '@core/component/VideoPreview';
+import { matches } from '@core/util/match';
+import { cn } from '@ui/utils/classname';
+import { Match, Switch } from 'solid-js';
+
+type ImageAttachment = {
+ id: string;
+};
+
+type SingleImageMediaPreviewProps = {
+ kind: 'single-image';
+ image: ImageAttachment;
+ class?: string;
+};
+
+type ImageGalleryMediaPreviewProps = {
+ kind: 'image-gallery';
+ images: ImageAttachment[];
+ attachmentIds: string[];
+ class?: string;
+};
+
+type VideoMediaPreviewProps = {
+ kind: 'video';
+ id: string;
+ class?: string;
+};
+
+export type MediaPreviewProps =
+ | SingleImageMediaPreviewProps
+ | ImageGalleryMediaPreviewProps
+ | VideoMediaPreviewProps;
+
+function isSingleImageMediaPreview(
+ props: MediaPreviewProps
+): props is SingleImageMediaPreviewProps {
+ return props.kind === 'single-image';
+}
+
+function isImageGalleryMediaPreview(
+ props: MediaPreviewProps
+): props is ImageGalleryMediaPreviewProps {
+ return props.kind === 'image-gallery';
+}
+
+function isVideoMediaPreview(
+ props: MediaPreviewProps
+): props is VideoMediaPreviewProps {
+ return props.kind === 'video';
+}
+
+function SingleImagePreview(props: SingleImageMediaPreviewProps) {
+ return (
+ <div
+ class={cn('w-full max-w-[400px] min-w-0', props.class)}
+ data-message-media-preview="single-image"
+ >
+ <ImagePreview image={props.image} variant="dynamic" />
+ </div>
+ );
+}
+
+function ImageGalleryMediaPreview(props: ImageGalleryMediaPreviewProps) {
+ return (
+ <div
+ class={cn('w-full max-w-[412px] min-w-0', props.class)}
+ data-message-media-preview="image-gallery"
+ >
+ <ImageGalleryPreview
+ images={props.images}
+ attachmentIds={props.attachmentIds}
+ variant="dynamic"
+ wrapperClass="flex flex-row flex-wrap gap-2"
+ />
+ </div>
+ );
+}
+
+function VideoMediaPreview(props: VideoMediaPreviewProps) {
+ return (
+ <div
+ class={cn(
+ 'w-full max-w-[400px] min-w-0 [&>div]:max-w-full [&_video]:block [&_video]:max-w-full [&_video]:max-h-[500px]',
+ props.class
+ )}
+ data-message-media-preview="video"
+ >
+ <VideoPreview id={props.id} variant="dynamic" />
+ </div>
+ );
+}
+
+export function MediaPreview(props: MediaPreviewProps) {
+ return (
+ <Switch>
+ <Match when={matches(props, isSingleImageMediaPreview)}>
+ {(singleImageProps) => <SingleImagePreview {...singleImageProps()} />}
+ </Match>
+ <Match when={matches(props, isImageGalleryMediaPreview)}>
+ {(imageGalleryProps) => (
+ <ImageGalleryMediaPreview {...imageGalleryProps()} />
+ )}
+ </Match>
+ <Match when={matches(props, isVideoMediaPreview)}>
+ {(videoProps) => <VideoMediaPreview {...videoProps()} />}
+ </Match>
+ </Switch>
+ );
+}
diff --git a/js/app/packages/channel/Message/Message.ts b/js/app/packages/channel/Message/Message.ts
index cf5449860e..95885b609a 100644
--- a/js/app/packages/channel/Message/Message.ts
+++ b/js/app/packages/channel/Message/Message.ts
@@ -13,6 +13,7 @@ import { EditedIndicator } from './EditedIndicator';
import { HoverActions } from './HoverActions';
import { MessageFlag } from './MessageFlag';
import { ActionMenu } from './ActionMenu';
+import { MediaPreview } from './MediaPreview';
export const Message = {
Root,
@@ -30,4 +31,5 @@ export const Message = {
HoverActions,
MessageFlag,
ActionMenu,
+ MediaPreview,
};
diff --git a/js/app/packages/channel/Message/index.ts b/js/app/packages/channel/Message/index.ts
index effaaa59ec..0ddbb7e83f 100644
--- a/js/app/packages/channel/Message/index.ts
+++ b/js/app/packages/channel/Message/index.ts
@@ -8,6 +8,7 @@ export { Message } from './Message';
export { ChannelMessage } from './ChannelMessage';
export { Attachments, partitionMessageAttachments } from './Attachments';
+export { MediaPreview } from './MediaPreview';
export { DateDivider } from './DateDivider';
export { NewDivider } from './NewDivider';
export { MessageFlag } from './MessageFlag';