Skip to content

Commit fe49d20

Browse files
committed
feat(discord): update preview style + responsiveness
1 parent 645f261 commit fe49d20

4 files changed

Lines changed: 43 additions & 26 deletions

File tree

src/components/GuildDashboard/SpecialCategoryComponents/RssFeeds/FeedPreview.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Collapse, Paper, Typography } from "@mui/material";
1+
import { Box, Collapse, Paper, styled, Typography } from "@mui/material";
22
import { ComponentProps } from "react";
33

44
import { RssFeed, RssFeedParsedEntry } from "../../../../repository/types/api";
@@ -12,25 +12,40 @@ interface FeedPreviewButtonProps {
1212
}
1313
export default function FeedPreview({ isOpen, feed, data, isLoading }: FeedPreviewButtonProps) {
1414
return (
15-
<Collapse in={isOpen}>
15+
<StyledCollapse in={isOpen}>
1616
<Box>
1717
{isLoading && (<Typography color="textSecondary">Fetching the latest data...</Typography>)}
1818
{(!isLoading && !data) && (<Typography color="error">Oops, something went wrong while fetching your feed.</Typography>)}
1919
{(!isLoading && data) && <InnerFeedPreview feed={feed} data={data} />}
2020
</Box>
21-
</Collapse>
21+
</StyledCollapse>
2222
);
2323
}
2424

2525
function InnerFeedPreview({ feed, data }: { feed: RssFeed; data: RssFeedParsedEntry }) {
2626
const discordMessage = useBuildDiscordMessageFromFeed({ feed, feedData: data });
2727
return (
28-
<Paper elevation={3} sx={{ px: 2, py: 1 }}>
28+
<PreviewPaperContainer elevation={3}>
2929
<DiscordMessagePreview {...discordMessage} />
30-
</Paper>
30+
</PreviewPaperContainer>
3131
);
3232
}
3333

34+
const StyledCollapse = styled(Collapse)(({ theme }) => ({
35+
[theme.breakpoints.down("sm")]: {
36+
marginLeft: theme.spacing(-2),
37+
marginRight: theme.spacing(-2),
38+
},
39+
}));
40+
41+
const PreviewPaperContainer = styled(Paper)(({ theme }) => ({
42+
padding: theme.spacing(1, 2),
43+
44+
[theme.breakpoints.down("sm")]: {
45+
padding: theme.spacing(1, 0),
46+
},
47+
}));
48+
3449

3550
type DiscordMessageInput = ComponentProps<typeof DiscordMessagePreview>;
3651
function useBuildDiscordMessageFromFeed({ feed, feedData }: { feed: RssFeed; feedData: RssFeedParsedEntry }): DiscordMessageInput {

src/components/common/DiscordMarkdown.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ function getRenderer() {
251251

252252
const MarkdownRenderer = ({ markdown }: { markdown: string }) => {
253253
const tokens = md.parse(markdown, {});
254-
console.debug(tokens);
255254
return <div>{renderTokens(tokens, 0)}</div>;
256255
};
257256

@@ -260,10 +259,11 @@ function getRenderer() {
260259

261260
const BlueMention = styled.span({
262261
display: "inline-flex",
263-
borderRadius: "5px",
262+
borderRadius: "3px",
264263
padding: "0 2px",
265-
color: "#c9cdfb",
266-
backgroundColor: "#5865f24c",
264+
color: "#a9baff",
265+
backgroundColor: "#5865f23d",
266+
fontWeight: 500,
267267
});
268268

269269
const DiscordP = styled.p({
@@ -296,35 +296,36 @@ const DiscordH3 = styled.div({
296296

297297
const DiscordSubtext = styled.small({
298298
display: "block",
299-
color: "#949ba4",
299+
color: "#94959c",
300300
lineHeight: "1.1rem",
301301
fontSize: ".8125rem",
302302
});
303303

304304
const FakeLink = styled.span({
305-
color: "#00abfa",
305+
color: "#5197ed",
306306
"&:hover": {
307307
textDecoration: "underline",
308308
},
309309
});
310310

311311
const InlineCode = styled.code({
312-
backgroundColor: "#2b2d31",
313-
border: "1px solid #1e1f22",
312+
backgroundColor: "#5865f214",
313+
border: "1px solid #97979f33",
314314
borderRadius: 4,
315315
padding: "0 .2em",
316316
fontSize: "0.85rem",
317317
lineHeight: "1.125rem",
318318
});
319319

320320
const CodeBlock = styled.pre({
321-
backgroundColor: "#2b2d31",
322-
border: "1px solid #1e1f22",
323-
borderRadius: 5,
321+
backgroundColor: "#5865f214",
322+
border: "1px solid #97979f33",
323+
borderRadius: 4,
324324
marginTop: "6px",
325325
padding: ".5em",
326326
fontSize: "0.875rem",
327327
lineHeight: "1.125rem",
328+
whiteSpace: "pre-wrap",
328329
});
329330

330331
const DiscordOl = styled.ol({

src/components/common/DiscordMessagePreview.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function DiscordMessagePreview(props: DiscordMessagePreviewProps)
5050

5151
return (
5252
<ThemeProvider theme={overrideTheme}>
53-
<Stack direction="column" position="relative" py="0.125rem" pl="72px" pr="48px" minHeight="2.75rem">
53+
<Stack direction="column" position="relative" py="0.125rem" pl="72px" pr="24px" minHeight="2.75rem" overflow="hidden">
5454
<MessageAuthorAndContent {...props} />
5555
{props.embed && <MessageEmbed embed={props.embed} />}
5656
</Stack>
@@ -67,6 +67,7 @@ function MessageAuthorAndContent(props: Pick<DiscordMessagePreviewProps, "conten
6767
alt="Axobot avatar"
6868
style={{
6969
userSelect: "none",
70+
WebkitUserSelect: "none",
7071
position: "absolute",
7172
left: "16px",
7273
marginTop: "calc(4px - 0.125rem)",
@@ -78,7 +79,7 @@ function MessageAuthorAndContent(props: Pick<DiscordMessagePreviewProps, "conten
7879
<Typography variant="h3" fontSize="1rem" lineHeight="1.375rem" pb="1px">
7980
<MessageAuthorAndTimestamp timestamp={props.timestamp} />
8081
</Typography>
81-
<Stack whiteSpace="pre-wrap" color="#dbdee1">
82+
<Stack whiteSpace="pre-wrap" color="#efeff0">
8283
<DiscordMarkdown text={props.content?.trim()} />
8384
</Stack>
8485
</Box>
@@ -113,10 +114,10 @@ function MessageEmbed({ embed }: { embed: Exclude<DiscordMessagePreviewProps["em
113114
}, [embed.timestamp]);
114115

115116
return (
116-
<Box display="grid" maxWidth="516px" my=".125rem" borderRadius="4px" borderLeft={`4px solid ${hexEmbedColor}`} bgcolor="#2b2d31">
117+
<Box display="grid" maxWidth="516px" my=".125rem" borderRadius="4px" borderLeft={`4px solid ${hexEmbedColor}`} bgcolor="#242429">
117118
<Box sx={{
118119
overflow: "hidden",
119-
padding: ".5rem 1rem 1rem .75rem",
120+
padding: ".125rem 1rem 1rem .75rem",
120121
display: "grid",
121122
gridTemplateColumns: "auto",
122123
gridTemplateRows: embed.thumbnail ? "auto min-content" : "auto",
@@ -139,7 +140,7 @@ function MessageEmbed({ embed }: { embed: Exclude<DiscordMessagePreviewProps["em
139140
</Stack>
140141
)}
141142
{embed.title && (
142-
<Typography component="div" mt="8px" lineHeight="1.375rem" fontWeight={700} color="#f2f3f5" gridColumn="1 / 1">
143+
<Typography component="div" mt="8px" lineHeight="1.375rem" fontWeight={600} color="#e3e3e6" gridColumn="1 / 1">
143144
{embed.url
144145
? (
145146
<DiscordLink href={embed.url} target="_blank">{embed.title}</DiscordLink>
@@ -150,25 +151,25 @@ function MessageEmbed({ embed }: { embed: Exclude<DiscordMessagePreviewProps["em
150151
</Typography>
151152
)}
152153
{embed.description && (
153-
<Typography component="div" mt="8px" fontSize="0.875rem" lineHeight="1.125rem" fontWeight={400} color="#dbdee1" whiteSpace="pre-wrap" gridColumn="1 / 1">
154+
<Typography component="div" mt="8px" fontSize="0.875rem" lineHeight="1.125rem" fontWeight={400} color="#efeff0" whiteSpace="pre-wrap" gridColumn="1 / 1">
154155
<DiscordMarkdown text={embed.description?.trim()} />
155156
</Typography>
156157
)}
157158
{embed.image && (
158159
<Box mt="16px" maxWidth="400px" maxHeight="225px">
159-
<img style={{ userSelect: "none", maxWidth: "100%", maxHeight: "100%", borderRadius: "4px" }} alt="Image" src={embed.image}></img>
160+
<img style={{ userSelect: "none", WebkitUserSelect: "none", maxWidth: "100%", maxHeight: "100%", borderRadius: "4px" }} alt="Image" src={embed.image}></img>
160161
</Box>
161162
)}
162163
{(embed.footer || embed.timestamp) && (
163-
<Typography component="span" mt="8px" fontSize="0.75rem" lineHeight="1rem" fontWeight={500} color="#dbdee1" gridColumn="1 / 1">
164+
<Typography component="span" mt="8px" fontSize="0.75rem" lineHeight="1rem" fontWeight={500} color="#efeff0" gridColumn="1 / 1">
164165
{embed.footer?.text}
165166
{embed.footer && timestamp && " • "}
166167
{timestamp}
167168
</Typography>
168169
)}
169170
{embed.thumbnail && (
170171
<Box gridRow="1 / 8" gridColumn="2 / 2" ml="16px" mt="8px" flexShrink={0} justifySelf="end">
171-
<img style={{ userSelect: "none", maxWidth: "80px", maxHeight: "80px", borderRadius: "4px" }} alt="Thumbnail" src={embed.thumbnail}></img>
172+
<img style={{ userSelect: "none", WebkitUserSelect: "none", maxWidth: "80px", maxHeight: "80px", borderRadius: "4px" }} alt="Thumbnail" src={embed.thumbnail}></img>
172173
</Box>
173174
)}
174175
</Box>

src/components/common/DiscordTimestamp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function Timestamp({ timestamp, format }: TimestampProps) {
1717
return (
1818
<span style={{
1919
display: "inline-flex",
20-
backgroundColor: "#4e50587a",
20+
backgroundColor: "#97979f1f",
2121
borderRadius: 3,
2222
padding: "0 2px",
2323
}}

0 commit comments

Comments
 (0)