Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 0591124

Browse files
add colour preview to article explanation (#752)
* add colour preview to article explanation * add safe checks
1 parent d941558 commit 0591124

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

client/src/pages/ArticleResponse/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ const ArticleResponse = ({ recordId, threadId }: Props) => {
121121
typeof children[0] === 'string' ? children[0].replace(/\n$/, '') : '';
122122
const lines =
123123
matchLines?.[1].split('-').map((l) => Number(l.slice(1))) || [];
124+
const colorPreview =
125+
children[0] &&
126+
children.length === 1 &&
127+
typeof children[0] === 'string' &&
128+
/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(children[0]) ? (
129+
<span
130+
className="w-3 h-3 inline-block"
131+
style={{ backgroundColor: children[0] }}
132+
/>
133+
) : null;
124134
return !inline && matchLang?.[1] && typeof children[0] === 'string' ? (
125135
matchPath?.[1] ? (
126136
<CodeWithBreadcrumbs
@@ -134,6 +144,13 @@ const ArticleResponse = ({ recordId, threadId }: Props) => {
134144
) : (
135145
<NewCode code={code} language={matchLang[1]} />
136146
)
147+
) : colorPreview ? (
148+
<span className="inline-flex gap-1.5 items-center">
149+
{colorPreview}
150+
<code {...props} className={className}>
151+
{children}
152+
</code>
153+
</span>
137154
) : (
138155
<code {...props} className={className}>
139156
{children}

client/src/pages/Repository/RepositoryOverview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const RepositoryOverview = ({ syncState, repository }: Props) => {
5959
}, [repository.files, selectedBranch]);
6060

6161
useEffect(() => {
62-
if (!readmeData) {
62+
if (!readmeData?.data?.[0]?.data?.contents) {
6363
return;
6464
}
6565
setReadme({

0 commit comments

Comments
 (0)