Skip to content

Commit cb216fd

Browse files
committed
Merge remote-tracking branch 'origin' into feat/message-editing
2 parents 244e90d + 076313b commit cb216fd

File tree

9 files changed

+50
-15
lines changed

9 files changed

+50
-15
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/MessageAuthor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function MessageAuthor({
101101
<Styles.MessageAuthor
102102
clickable={userOnClick !== undefined}
103103
{...props}
104-
onClick={() => userOnClick?.(author)}
104+
onClick={(e) => userOnClick?.(author, e.currentTarget)}
105105
>
106106
<Styles.Username style={{ color: dominantRoleColor }}>
107107
{displayName}
@@ -114,7 +114,7 @@ function MessageAuthor({
114114
<Styles.MessageAuthor
115115
clickable={userOnClick !== undefined}
116116
{...props}
117-
onClick={() => userOnClick?.(author)}
117+
onClick={(e) => userOnClick?.(author, e.currentTarget)}
118118
>
119119
<Styles.AnimatedAvatarTrigger
120120
data-is-animated={animatedAvatarUrl !== undefined}

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",

src/core/ConfigContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type Config<SvgConfig extends PartialSvgConfig> = {
5555
// Click handlers
5656
currentUser(): APIUser | null;
5757
seeThreadOnClick?(messageId: Snowflake, thread: APIChannel): void;
58-
userOnClick?(user: APIUser): void;
58+
userOnClick?(user: APIUser, element: EventTarget & HTMLSpanElement): void;
5959
roleMentionOnClick?(role: APIRole): void;
6060
channelMentionOnClick?(channel: APIChannel): void;
6161
openPinnedMessagesOnClick?(channel: APIChannel): void;

src/markdown/render/elements/mentions/userMention.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function UserMention({ userId }: UserMentionProps) {
1818

1919
return (
2020
<Styles.Mention
21-
onClick={() => {
22-
if (user !== null) userOnClick?.(user);
21+
onClick={(e) => {
22+
if (user !== null) userOnClick?.(user, e.currentTarget);
2323
}}
2424
canBeClicked={userOnClick !== undefined}
2525
>

src/stories/Wrapper.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,17 @@ const Wrapper: Decorator = (Story) => {
398398
seeThreadOnClick={(messageId, thread) =>
399399
alert(`See Thread "${thread.name}" clicked on message ${messageId}`)
400400
}
401-
userOnClick={(user) => alert(`User "${getDisplayName(user)}" clicked!`)}
401+
userOnClick={(user, el) => {
402+
const elPos = el.getBoundingClientRect();
403+
404+
return alert(
405+
`User "${getDisplayName(
406+
user
407+
)}" clicked! \nClicked Position: X - ${Math.floor(
408+
elPos.left
409+
)} Y - ${Math.floor(elPos.top)}`
410+
);
411+
}}
402412
roleMentionOnClick={(role) =>
403413
alert(`Role "${role.name}" mention clicked!`)
404414
}

0 commit comments

Comments
 (0)