From 02bbf78dcd093a0fe91b1d40a32ac660e017a51c Mon Sep 17 00:00:00 2001 From: bree Date: Mon, 5 Jul 2021 04:32:05 -0400 Subject: [PATCH 1/3] Fix: attachment scaling and better image scaling - attachment scaling now works for all forms of attachments - switched to grid based action bar - added onLoad class so image proportions are "trimmed" once the image has loaded to avoid moving the view around before loading - this may be possible to remove at some point --- .../attachments/Attachment.module.scss | 94 ++++++++++++------- .../messaging/attachments/Attachment.tsx | 8 +- .../attachments/AttachmentActions.tsx | 47 ++++------ 3 files changed, 89 insertions(+), 60 deletions(-) diff --git a/src/components/common/messaging/attachments/Attachment.module.scss b/src/components/common/messaging/attachments/Attachment.module.scss index 5aa89744..8b5529d4 100644 --- a/src/components/common/messaging/attachments/Attachment.module.scss +++ b/src/components/common/messaging/attachments/Attachment.module.scss @@ -1,14 +1,13 @@ .attachment { + display: grid; + grid-auto-columns: min(100%, 480px); + grid-auto-flow: row dense; + + width: max-content; + border-radius: 6px; margin: .125rem 0 .125rem; - height: auto; - - max-height: 640px; - max-width: min(480px, 100%); - - object-fit: contain; - &[data-spoiler="true"] { filter: blur(30px); pointer-events: none; @@ -20,6 +19,16 @@ &.image { cursor: pointer; + + max-height: 640px; + max-width: min(480px, 100%); + + object-fit: contain; + + &.loaded { + width: auto; + height: auto; + } } &.video { @@ -29,8 +38,15 @@ } video { - width: 100%; border-radius: 0 0 6px 6px; + + max-height: 640px; + max-width: min(480px, 100%); + } + + video.loaded { + width: auto; + height: auto; } } @@ -59,11 +75,12 @@ } &.text { - display: flex; - overflow: hidden; + width: 100%; max-width: 800px; + overflow: hidden; + grid-auto-columns: unset; + border-radius: 6px; - flex-direction: column; .textContent { height: 140px; @@ -92,35 +109,48 @@ } } +.actions.imageAction { + grid-template: + "name icon download" auto + "size icon download" auto + / minmax(20px, 1fr) min-content min-content; +} + .actions { - gap: 8px; - padding: 8px; - display: flex; - overflow: none; - max-width: 100%; + display: grid; + grid-template: + "icon name download" auto + "icon size download" auto + / min-content minmax(20px, 1fr) min-content; + align-items: center; - flex-direction: row; + column-gap: 8px; + + width: 100%; + padding: 8px; + overflow: none; + color: var(--foreground); background: var(--secondary-background); - > svg { - flex-shrink: 0; + span { + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; } - .info { - display: flex; - flex-direction: column; - flex-grow: 1; + .filesize { + grid-area: size; - > span { - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - } + font-size: 10px; + color: var(--secondary-foreground); + } - .filesize { - font-size: 10px; - color: var(--secondary-foreground); - } + .downloadIcon { + grid-area: download; + } + + .iconType { + grid-area: icon; } } diff --git a/src/components/common/messaging/attachments/Attachment.tsx b/src/components/common/messaging/attachments/Attachment.tsx index 15c42536..2ef979a2 100644 --- a/src/components/common/messaging/attachments/Attachment.tsx +++ b/src/components/common/messaging/attachments/Attachment.tsx @@ -21,6 +21,7 @@ export default function Attachment({ attachment, hasContent }: Props) { const { openScreen } = useIntermediate(); const { filename, metadata } = attachment; const [ spoiler, setSpoiler ] = useState(filename.startsWith("SPOILER_")); + const [ loaded, setLoaded ] = useState(false) const url = client.generateFileURL(attachment, { width: MAX_ATTACHMENT_WIDTH * 1.5 }, true); @@ -44,7 +45,7 @@ export default function Attachment({ attachment, hasContent }: Props) { height={metadata.height} data-spoiler={spoiler} data-has-content={hasContent} - className={classNames(styles.attachment, styles.image)} + className={classNames(styles.attachment, styles.image, loaded && styles.loaded)} onClick={() => openScreen({ id: "image_viewer", attachment }) } @@ -52,6 +53,7 @@ export default function Attachment({ attachment, hasContent }: Props) { ev.button === 1 && window.open(url, "_blank") } + onLoad={() => setLoaded(true)} /> ); @@ -85,11 +87,15 @@ export default function Attachment({ attachment, hasContent }: Props) {