Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | import {
ChatBubbleOutline,
ChevronRight,
Forum,
Place,
Schedule,
} from "@mui/icons-material";
import { Skeleton, styled } from "@mui/material";
import getContentSummary from "features/communities/getContentSummary";
import { useTranslation } from "i18n";
import { DASHBOARD, GLOBAL } from "i18n/namespaces";
import Link from "next/link";
import { Discussion } from "proto/discussions_pb";
import { routeToDiscussion } from "routes";
import { timestamp2Date } from "utils/date";
import { timeAgo } from "utils/timeAgo";
type DiscussionSummary = Pick<
Discussion.AsObject,
| "discussionId"
| "slug"
| "title"
| "ownerTitle"
| "created"
| "thread"
| "content"
>;
interface DiscussionListRowProps {
discussion: DiscussionSummary;
}
export const DiscussionListContainer = styled("div")({});
const RowLink = styled(Link)({
display: "flex",
alignItems: "center",
gap: "14px",
padding: "10px 14px 10px 0",
textDecoration: "none",
color: "inherit",
borderRadius: "8px",
"&:hover": {
backgroundColor: "var(--mui-palette-grey-50)",
},
});
const IconChip = styled("div")({
width: 40,
height: 40,
flexShrink: 0,
borderRadius: "5px",
display: "flex",
alignItems: "center",
justifyContent: "center",
color: "var(--mui-palette-primary-main)",
});
const ContentWrapper = styled("div")({
flex: 1,
minWidth: 0,
});
const RowTitle = styled("div")({
fontSize: "14px",
fontWeight: 600,
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
});
const ContentTeaser = styled("div")({
fontSize: "12px",
color: "var(--mui-palette-text-secondary)",
marginTop: "2px",
overflow: "hidden",
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
lineHeight: 1.4,
});
const MetaLine = styled("div")({
display: "flex",
alignItems: "center",
gap: "6px",
marginTop: "4px",
fontSize: "11px",
color: "var(--mui-palette-text-disabled)",
overflow: "hidden",
whiteSpace: "nowrap",
});
const MetaDot = styled("span")({
flexShrink: 0,
});
const MetaText = styled("span")({
overflow: "hidden",
textOverflow: "ellipsis",
flexShrink: 1,
minWidth: 0,
});
const SkeletonRow = styled("div")({
display: "flex",
alignItems: "center",
gap: "14px",
padding: "10px 14px 10px 0",
});
export function DiscussionListRowSkeleton() {
return (
<SkeletonRow>
<Skeleton
variant="rectangular"
width={40}
height={40}
sx={{ borderRadius: "5px", flexShrink: 0 }}
/>
<div style={{ flex: 1, minWidth: 0 }}>
<Skeleton width="55%" height={20} />
<Skeleton width="90%" height={14} sx={{ marginTop: "4px" }} />
<Skeleton width="70%" height={14} sx={{ marginTop: "2px" }} />
<Skeleton width="60%" height={14} sx={{ marginTop: "4px" }} />
</div>
</SkeletonRow>
);
}
export default function DiscussionListRow({
discussion,
}: DiscussionListRowProps) {
const {
t,
i18n: { language: locale },
} = useTranslation([DASHBOARD, GLOBAL]);
const createdDate = discussion.created
? timestamp2Date(discussion.created)
: new Date();
const timeStr = timeAgo({ since: createdDate, t, locale });
const commentCount = discussion.thread?.numResponses ?? 0;
const teaser = getContentSummary({
originalContent: discussion.content?.replace(/\n/g, " "),
maxLength: 300,
});
return (
<RowLink href={routeToDiscussion(discussion.discussionId, discussion.slug)}>
<IconChip>
<Forum sx={{ fontSize: "18px" }} />
</IconChip>
<ContentWrapper>
<RowTitle>{discussion.title}</RowTitle>
{teaser && <ContentTeaser>{teaser}</ContentTeaser>}
<MetaLine>
<Place sx={{ fontSize: "11px", flexShrink: 0 }} />
<MetaText>{discussion.ownerTitle}</MetaText>
<MetaDot>·</MetaDot>
<Schedule sx={{ fontSize: "11px", flexShrink: 0 }} />
<span style={{ flexShrink: 0 }}>{timeStr}</span>
<MetaDot>·</MetaDot>
<ChatBubbleOutline sx={{ fontSize: "11px", flexShrink: 0 }} />
<span style={{ flexShrink: 0 }}>
{t("dashboard:discussions.replies_count_label", {
count: commentCount,
})}
</span>
</MetaLine>
</ContentWrapper>
<ChevronRight
sx={{
fontSize: "16px",
color: "var(--mui-palette-text-secondary)",
flexShrink: 0,
}}
/>
</RowLink>
);
}
|