From 8ccf1abf180e04de14cc044678cb07ccbd26a260 Mon Sep 17 00:00:00 2001 From: Yume <2839681263@qq.com> Date: Thu, 12 Jun 2025 23:36:10 +0800 Subject: [PATCH] feat(UI): add CommitHistory component and integrate into CodeView --- .../CodeView/BlobView/CodeContent.module.css | 4 +- .../CodeView/BlobView/CodeContent.tsx | 85 +++++++++++-------- .../web/components/CodeView/CommitHistory.tsx | 49 +++++++++++ .../web/pages/[org]/code/blob/[...path].tsx | 32 +++++-- 4 files changed, 124 insertions(+), 46 deletions(-) create mode 100644 moon/apps/web/components/CodeView/CommitHistory.tsx diff --git a/moon/apps/web/components/CodeView/BlobView/CodeContent.module.css b/moon/apps/web/components/CodeView/BlobView/CodeContent.module.css index d4d5382a9..de3da1b51 100644 --- a/moon/apps/web/components/CodeView/BlobView/CodeContent.module.css +++ b/moon/apps/web/components/CodeView/BlobView/CodeContent.module.css @@ -1,8 +1,8 @@ - .codeLineNumber { margin-left: 4px; margin-right: 25px; - text-align: center; + align-items: center; + align-self: center; user-select: none; } diff --git a/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx b/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx index d6e486553..983cf9582 100644 --- a/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx +++ b/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx @@ -1,14 +1,13 @@ -'use client' -import 'github-markdown-css/github-markdown-light.css' +'use client'; -import { useEffect, useRef, useState } from 'react' -import { ListIcon } from '@gitmono/ui' -import { Button, Dropdown, MenuProps, message} from 'antd' -import { Highlight, themes } from 'prism-react-renderer' +import { useEffect, useRef, useState } from 'react'; +import { Button, Dropdown, MenuProps, message } from 'antd'; +import { Highlight, themes } from 'prism-react-renderer'; +import { DotsHorizontal } from '@gitmono/ui'; -import styles from './CodeContent.module.css' +import 'github-markdown-css/github-markdown-light.css'; +import styles from './CodeContent.module.css'; -// @ts-ignore const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string[] }) => { const [lfs, setLfs] = useState(false) const [selectedLine, setSelectedLine] = useState(null) @@ -18,6 +17,18 @@ const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string { label: 'Copy line', key: '1' + }, + { + label: 'Copy permalink', + key: '2' + }, + { + label: 'View file in GitHub.dev', + key: '3' + }, + { + label: 'View file in different branch/tag', + key: '4' } ] } @@ -175,36 +186,38 @@ const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string style={{ backgroundColor: selectedLine === i ? '#f0f7ff' : 'transparent' }} + className='flex h-6 items-center' > -
- - {selectedLine === i ? - { - if(props.key === '1') { - handleCopyLine(line.map(i=>i.content).join('')) - } + + {selectedLine === i ? + { + if(props.key === '1') { + handleCopyLine(line.map(i=>i.content).join('')) } - }} - className='bg-gray-100 border rounded border-gray-200 justify-center' - - > -
+ } + }} + className='bg-gray-100 border rounded border-gray-200' + > + + + + ) +} diff --git a/moon/apps/web/pages/[org]/code/blob/[...path].tsx b/moon/apps/web/pages/[org]/code/blob/[...path].tsx index 750fa2716..600da3460 100644 --- a/moon/apps/web/pages/[org]/code/blob/[...path].tsx +++ b/moon/apps/web/pages/[org]/code/blob/[...path].tsx @@ -7,13 +7,14 @@ import AuthAppProviders from '@/components/Providers/AuthAppProviders' import { useGetBlob } from '@/hooks/useGetBlob' import { useRouter } from 'next/router' import { CommentSection } from '@/components/CodeView/BlobView/CommentSection' +import CommitHistory, { CommitInfo } from '@/components/CodeView/CommitHistory' const codeStyle = { borderRadius: 8, width: 'calc(85% - 8px)', background: '#fff', border: '1px solid #d1d9e0', - margin: '0 10px' + margin: '0 8px' } interface Comment { @@ -67,6 +68,16 @@ function BlobPage() { ] } ] + const commitInfo: CommitInfo = { + user: { + avatar_url: 'https://avatars.githubusercontent.com/u/112836202?v=4&size=40', + name: 'yetianxing2014' + }, + message: 'feat: migrate campsite to mega', + hash: '5fe4235', + date: '3 months ago' + } + const handleAddComment = (__content: string, __lineNumber?: number) => { //wait for complete } @@ -78,17 +89,22 @@ function BlobPage() { return (
- + - - - - - {/* @ts-ignore */} - + + + + + + + + {/* @ts-ignore */} + + +
)