tweak mention display

This commit is contained in:
hmacr committed 2025-04-02 15:58:32 +05:30
1 parent 0b1fb7fb2e
commit e1a12fd78b
6 files changed
+109 -12

No files matched your search

@@ -1,9 +1,9 @@
import * as React from "react";
import { Trans } from "react-i18next";
import { IssueStatusIcon } from "@shared/components/IssueStatusIcon";
import { UnfurlResourceType, UnfurlResponse } from "@shared/types";
import { Avatar } from "~/components/Avatar";
import Flex from "~/components/Flex";
import { IssueStatusIcon } from "../Icons/IssueStatusIcon";
import Text from "../Text";
import Time from "../Time";
import {
@@ -1,9 +1,9 @@
import * as React from "react";
import { Trans } from "react-i18next";
import { PullRequestIcon } from "@shared/components/PullRequestIcon";
import { UnfurlResourceType, UnfurlResponse } from "@shared/types";
import { Avatar } from "~/components/Avatar";
import Flex from "~/components/Flex";
import { PullRequestIcon } from "../Icons/PullRequestIcon";
import Text from "../Text";
import Time from "../Time";
import {
+73
View File
@@ -0,0 +1,73 @@
import styled, { css } from "styled-components";
import { ellipsis } from "../styles";
type Props = {
/** The type of text to render */
type?: "secondary" | "tertiary" | "danger";
/** The size of the text */
size?: "xlarge" | "large" | "medium" | "small" | "xsmall";
/** The direction of the text (defaults to ltr) */
dir?: "ltr" | "rtl" | "auto";
/** Whether the text should be selectable (defaults to false) */
selectable?: boolean;
/** The font weight of the text */
weight?: "xbold" | "bold" | "normal";
/** Whether the text should be italic */
italic?: boolean;
/** Whether the text should be truncated with an ellipsis */
ellipsis?: boolean;
/** Whether the text should be monospaced */
monospace?: boolean;
};
/**
* Use this component for all interface text that should not be selectable
* by the user, this is the majority of UI text explainers, notes, headings.
*/
const Text = styled.span<Props>`
margin-top: 0;
text-align: ${(props) => (props.dir ? props.dir : "inherit")};
color: ${(props) =>
props.type === "secondary"
? props.theme.textSecondary
: props.type === "tertiary"
? props.theme.textTertiary
: props.type === "danger"
? props.theme.brand.red
: props.theme.text};
font-size: ${(props) =>
props.size === "xlarge"
? "26px"
: props.size === "large"
? "18px"
: props.size === "medium"
? "16px"
: props.size === "small"
? "14px"
: props.size === "xsmall"
? "13px"
: "inherit"};
${(props) =>
props.weight &&
css`
font-weight: ${props.weight === "xbold"
? 600
: props.weight === "bold"
? 500
: props.weight === "normal"
? 400
: "inherit"};
`}
font-style: ${(props) => (props.italic ? "italic" : "normal")};
font-family: ${(props) =>
props.monospace ? props.theme.fontFamilyMono : "inherit"};
white-space: normal;
user-select: ${(props) => (props.selectable ? "text" : "none")};
${(props) => props.ellipsis && ellipsis()}
`;
export default Text;
+34 -10
View File
@@ -9,8 +9,12 @@ import { Node } from "prosemirror-model";
import * as React from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import Flex from "../../components/Flex";
import Icon from "../../components/Icon";
import { IssueStatusIcon } from "../../components/IssueStatusIcon";
import { PullRequestIcon } from "../../components/PullRequestIcon";
import Spinner from "../../components/Spinner";
import Text from "../../components/Text";
import useStores from "../../hooks/useStores";
import theme from "../../styles/theme";
import type { UnfurlResourceType, UnfurlResponse } from "../../types";
@@ -116,7 +120,7 @@ export const MentionCollection = observer(function MentionCollection_(
export const MentionIssue = (props: ComponentProps) => {
const { unfurls } = useStores();
const [data, setData] =
const [issue, setIssue] =
React.useState<UnfurlResponse[UnfurlResourceType.Issue]>();
const [loaded, setLoaded] = React.useState(false);
@@ -125,7 +129,7 @@ export const MentionIssue = (props: ComponentProps) => {
React.useEffect(() => {
const fetchIssue = async () => {
setData(await unfurls.fetch(attrs.href));
setIssue(await unfurls.fetch(attrs.href));
setLoaded(true);
};
@@ -136,7 +140,7 @@ export const MentionIssue = (props: ComponentProps) => {
return <MentionLoading className={className} />;
}
if (!data) {
if (!issue) {
return <MentionError className={className} />;
}
@@ -150,14 +154,24 @@ export const MentionIssue = (props: ComponentProps) => {
target="_blank"
rel="noopener noreferrer"
>
{data.title}
<Flex align="center" gap={6}>
<IssueStatusIcon
size={14}
status={issue.state.name}
color={issue.state.color}
/>
<Flex align="center" gap={4}>
<Text>{issue.title}</Text>
<Text type="tertiary">{issue.id}</Text>
</Flex>
</Flex>
</a>
);
};
export const MentionPullRequest = (props: ComponentProps) => {
const { unfurls } = useStores();
const [data, setData] =
const [pullRequest, setPullRequest] =
React.useState<UnfurlResponse[UnfurlResourceType.PR]>();
const [loaded, setLoaded] = React.useState(false);
@@ -166,7 +180,7 @@ export const MentionPullRequest = (props: ComponentProps) => {
React.useEffect(() => {
const fetchPR = async () => {
setData(await unfurls.fetch(attrs.href));
setPullRequest(await unfurls.fetch(attrs.href));
setLoaded(true);
};
@@ -177,7 +191,7 @@ export const MentionPullRequest = (props: ComponentProps) => {
return <MentionLoading className={className} />;
}
if (!data) {
if (!pullRequest) {
return <MentionError className={className} />;
}
@@ -191,7 +205,17 @@ export const MentionPullRequest = (props: ComponentProps) => {
target="_blank"
rel="noopener noreferrer"
>
{data.title}
<Flex align="center" gap={6}>
<PullRequestIcon
size={14}
status={pullRequest.state.name}
color={pullRequest.state.color}
/>
<Flex align="center" gap={4}>
<Text>{pullRequest.title}</Text>
<Text type="tertiary">{pullRequest.id}</Text>
</Flex>
</Flex>
</a>
);
};
@@ -202,7 +226,7 @@ const MentionLoading = ({ className }: { className: string }) => {
return (
<span className={className}>
<Spinner />
{`${t("Loading")}…`}
<Text type="tertiary">{`${t("Loading")}…`}</Text>
</span>
);
};
@@ -213,7 +237,7 @@ const MentionError = ({ className }: { className: string }) => {
return (
<span className={className}>
<WarningIcon color={theme.danger} />
{`${t("Error loading data")}`}
<Text type="secondary">{`${t("Error loading data")}`}</Text>
</span>
);
};