-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathReleaseCodeBox.tsx
More file actions
54 lines (44 loc) · 2 KB
/
ReleaseCodeBox.tsx
File metadata and controls
54 lines (44 loc) · 2 KB
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
'use client';
import { useTranslations } from 'next-intl';
import { useContext, useEffect, useState } from 'react';
import type { FC } from 'react';
import CodeBox from '@/components/Common/CodeBox';
import { ReleaseContext } from '@/providers/releaseProvider';
import { getShiki, highlightToHtml } from '@/util/getHighlighter';
import { getNodeDownloadSnippet } from '@/util/getNodeDownloadSnippet';
// We cannot do top-level awaits on utilities or code that is imported by client-only components
// hence we only declare a Promise and let it be fulfilled by the first call to the function
const memoizedShiki = getShiki();
const ReleaseCodeBox: FC = () => {
const { platform, os, release } = useContext(ReleaseContext);
const [code, setCode] = useState('');
const t = useTranslations();
useEffect(() => {
const updatedCode = getNodeDownloadSnippet(release, os)[platform];
// Docker and NVM support downloading tags/versions by their full release number
// but usually we should recommend users to download "major" versions
// since our Downlooad Buttons get the latest minor of a major, it does make sense
// to request installation of a major via a package manager
memoizedShiki
.then(shiki => highlightToHtml(shiki)(updatedCode, 'bash'))
.then(setCode);
// Only react when the specific release number changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [release.versionWithPrefix, os, platform]);
const codeLanguage = os === 'WIN' ? 'PowerShell' : 'Bash';
return (
<div className="mb-2 mt-6 flex flex-col gap-2">
{code && (
<CodeBox language={codeLanguage}>
<code dangerouslySetInnerHTML={{ __html: code }} />
</CodeBox>
)}
<span className="text-center text-xs text-neutral-800 dark:text-neutral-200">
{t('layouts.download.codeBox.communityWarning')}
<br />
<b>{t('layouts.download.codeBox.communityWarningReport')}</b>
</span>
</div>
);
};
export default ReleaseCodeBox;