Skip to content

Commit 076313b

Browse files
tylergeorgesJohnyTheCarrotmason-rogers
authored
Fix message embed image resizing (#58)
* fix: video embeds' proxy_url was not checked for null (#52) * v2.3.1 * fix: fix reaction style inaccuracy * fix: embed thumbnail not resizing * refactor: remove commented code * Update src/Content/Embed/index.tsx --------- Co-authored-by: Tuur Martens <tuurmartens4@gmail.com> Co-authored-by: Mason Rogers <26467584+mason-rogers@users.noreply.github.com>
1 parent f79cf25 commit 076313b

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

src/Content/Attachment/style.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const ImageAttachment = styled.withConfig({
1212
displayName: "image-attachment",
1313
componentId: commonComponentId,
1414
})(LazyLoadImage, {
15+
maxWidth: "100%",
16+
height: "auto",
1517
variants: {
1618
clickable: {
1719
true: {
@@ -30,6 +32,8 @@ export const LazyImagePlaceholder = styled.withConfig({
3032
display: "flex",
3133
alignItems: "center",
3234
justifyContent: "center",
35+
maxWidth: "100%",
36+
height: "auto",
3337
});
3438

3539
export const VideoAttachmentContainer = styled.withConfig({

src/Content/Embed/EmbeddedImage.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ComponentProps } from "react";
33
import React from "react";
44
import { useConfig } from "../../core/ConfigContext";
55
import type { APIEmbedImage } from "discord-api-types/v10";
6+
import useSize from "src/Content/Attachment/useSize";
67

78
interface Props extends ComponentProps<typeof Styles.Image> {
89
embedImage: APIEmbedImage;
@@ -14,14 +15,22 @@ interface Props extends ComponentProps<typeof Styles.Image> {
1415
function EmbeddedImage({ width, height, embedImage, ...rest }: Props) {
1516
const { embedImageOnClick } = useConfig();
1617

18+
const { width: widthEmbed, height: heightEmbed } = useSize(
19+
width ?? 1,
20+
height ?? 1
21+
);
22+
23+
const actualWidth = widthEmbed ?? width;
24+
const actualHeight = heightEmbed ?? height;
25+
1726
return (
1827
<Styles.Image
1928
{...rest}
2029
src={embedImage.proxy_url ?? embedImage.url}
2130
clickable={embedImageOnClick !== undefined}
2231
onClick={() => embedImageOnClick?.(embedImage)}
23-
width={width}
24-
height={height}
32+
width={actualWidth}
33+
height={actualHeight}
2534
/>
2635
);
2736
}

src/Content/Embed/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import * as Styles from "./style";
55
import { colorIntToRgba } from "../../utils/colorIntToCss";
66
import moment from "moment";
77
import { LinkMarkdown, parseEmbedTitle } from "../../markdown/render";
8-
import useSize from "./useSize";
98
import EmbedVideo from "./EmbedVideo";
109
import React, { useMemo } from "react";
1110
import type { APIEmbed, APIEmbedImage } from "discord-api-types/v10";
1211
import { EmbedType } from "discord-api-types/v10";
1312
import EmbeddedImage from "./EmbeddedImage";
1413
import ExternalLink from "../../ExternalLink";
1514
import { error } from "../../utils/error";
15+
import useSize from "src/Content/Embed/useSize";
1616

1717
export interface EmbedProps {
1818
embed: APIEmbed;
@@ -38,7 +38,7 @@ function Embed({ embed, images }: EmbedProps) {
3838
? colorIntToRgba(embed.color)
3939
: undefined;
4040

41-
const { width: widthImage, height: heightImage } = useSize(
41+
const { width: widthImage } = useSize(
4242
embed.type,
4343
embed.image,
4444
"EmbedImage",
@@ -140,8 +140,11 @@ function Embed({ embed, images }: EmbedProps) {
140140
{(images === undefined || images?.length === 0) && embed.image && (
141141
<EmbeddedImage
142142
embedImage={embed.image}
143-
width={widthImage ?? undefined}
144-
height={heightImage ?? undefined}
143+
withMargin
144+
image={embed.image}
145+
width={embed.image.width}
146+
height={embed.image.height}
147+
type="EmbedImage"
145148
/>
146149
)}
147150
{images && images.length > 0 && (

src/Content/Embed/style.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const Embed = styled.withConfig({
2121
display: "flex",
2222
flexDirection: "column",
2323
maxWidth: 520,
24-
2524
variants: {
2625
thin: {
2726
true: {
@@ -35,9 +34,10 @@ export const ContentAndThumbnail = styled.withConfig({
3534
displayName: "embed-content-and-thumbnail",
3635
componentId: commonComponentId,
3736
})("div", {
38-
display: "flex",
37+
display: "grid",
38+
gridAutoColumns: "auto",
3939
gap: theme.space.xxl,
40-
40+
maxWidth: "100%",
4141
variants: {
4242
hasLargeThumbnail: {
4343
true: {
@@ -54,6 +54,8 @@ export const Content = styled.withConfig({
5454
})("div", {
5555
display: "grid",
5656
gap: theme.space.large,
57+
gridColumnStart: "1",
58+
gridColumnEnd: "1",
5759
});
5860

5961
export const Provider = styled.withConfig({
@@ -192,6 +194,10 @@ export const Image = styled.withConfig({
192194
componentId: commonComponentId,
193195
})("img", {
194196
borderRadius: 3,
197+
flexShrink: 0,
198+
gridColumnStart: "2",
199+
maxWidth: "100%",
200+
height: "auto",
195201

196202
variants: {
197203
clickable: {
@@ -279,6 +285,8 @@ export const MediaEmbed = styled.withConfig({
279285
})("img", {
280286
borderRadius: 3,
281287
cursor: "pointer",
288+
maxWidth: "100%",
289+
height: "auto",
282290
});
283291

284292
export const VideoIframe = styled.withConfig({

src/Message/Reactions/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const Reaction = styled.withConfig({
3939
display: "flex",
4040
flexDirection: "row",
4141
alignItems: "center",
42-
padding: `${theme.space.small} ${theme.space.medium}`,
42+
padding: `${theme.space.xs} ${theme.space.medium}`,
4343
borderRadius: 8,
4444
cursor: "not-allowed",
4545
backgroundColor: theme.colors.backgroundSecondary,

src/Stitches/stitches.config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const stitches = createStitches({
7474
messageLeftPadding: "72px",
7575
threadButton: "34px",
7676
messageTypeIcon: "16px",
77+
embedThumbnail: "80px",
7778
},
7879
borderWidths: {
7980
spines: "2px",

0 commit comments

Comments
 (0)