Skip to content

Commit 9ecaca8

Browse files
authored
Add page scrolling, display README files, and show commit history. (#1138)
* feat: The function implementation of tree component * fix: fix eslint * feat: Add page scrolling, display README files, and show commit history. * fix: fix conflicts * fix: fix eslint
1 parent 9dffcf4 commit 9ecaca8

File tree

8 files changed

+100
-96
lines changed

8 files changed

+100
-96
lines changed

moon/apps/web/components/CodeView/CodeTable.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { useMemo } from 'react'
66
import { DocumentIcon, FolderIcon } from '@heroicons/react/20/solid'
77
import { formatDistance, fromUnixTime } from 'date-fns'
88
import { usePathname, useRouter } from 'next/navigation'
9-
import Markdown from 'react-markdown'
10-
11-
import styles from './CodeTable.module.css'
129
import RTable from './Table'
1310
import { columnsType, DirectoryType } from './Table/type'
11+
import Markdown from 'react-markdown'
1412

1513
export interface DataType {
1614
oid: string
@@ -20,11 +18,19 @@ export interface DataType {
2018
date: number
2119
}
2220

23-
const CodeTable = ({ directory, readmeContent, loading }: any) => {
21+
const CodeTable = ({ directory, loading, readmeContent}: any) => {
2422
const router = useRouter()
2523
const pathname = usePathname()
2624
let real_path = pathname?.replace('/tree', '')
2725

26+
const markdownContentStyle = {
27+
margin:' 0 auto',
28+
marginTop: 20,
29+
border: '1px solid rgba(0, 0, 0, 0.112)',
30+
padding: '2%',
31+
borderRadius: '0.5rem',
32+
}
33+
2834
const columns = useMemo<columnsType<DirectoryType>[]>(
2935
() => [
3036
{
@@ -102,9 +108,8 @@ const CodeTable = ({ directory, readmeContent, loading }: any) => {
102108
onClick={handleRowClick}
103109
loading={loading}
104110
/>
105-
106-
{readmeContent && (
107-
<div className={styles.markdownContent}>
111+
{readmeContent && (
112+
<div style={markdownContentStyle}>
108113
<div className='markdown-body'>
109114
<Markdown>{readmeContent}</Markdown>
110115
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
const CommitDetails = () => {
4+
5+
return (
6+
<div>
7+
CommitDetails <br/>
8+
CommitDetails <br/>
9+
CommitDetails <br/>
10+
CommitDetails <br/>
11+
CommitDetails <br/>
12+
</div>
13+
);
14+
};
15+
16+
export default CommitDetails;

moon/apps/web/components/CodeView/CommitHistory.tsx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Card, Flex } from '@radix-ui/themes'
2-
import { Avatar, Button, ClockIcon } from '@gitmono/ui'
1+
import { Flex } from '@radix-ui/themes'
2+
import { Avatar, Button, ClockIcon, EyeIcon } from '@gitmono/ui'
33
import { MemberHovercard } from '@/components/InlinePost/MemberHovercard'
4+
import CommitDetails from './CommitDetails'
5+
import { useState } from 'react'
46

57
interface UserInfo {
68
avatar_url: string
@@ -14,10 +16,23 @@ export interface CommitInfo {
1416
date: string
1517
}
1618

17-
export default function CommitHistory({ info }: { info: CommitInfo }) {
19+
const CommitHyStyle = {
20+
width: '100%',
21+
background: '#fff',
22+
border: '1px solid #d1d9e0',
23+
borderRadius: 8
24+
}
25+
26+
export default function CommitHistory({ flag, info }: {flag:string, info: CommitInfo }) {
27+
const [Expand,setExpand] = useState(false)
28+
const ExpandDetails =()=>{
29+
setExpand(!Expand)
30+
}
31+
1832
return (
19-
<Card style={{ width: '100%', background: '#fff', border: '1px solid #d1d9e0', borderRadius: 8 }}>
20-
<Flex align='center' className='p-2'>
33+
<>
34+
<div style={CommitHyStyle}>
35+
<Flex align='center' className='p-1'>
2136
<MemberHovercard username={info.user.name} role='member'>
2237
<Flex align='center'>
2338
<Avatar src={info.user.avatar_url} />
@@ -29,6 +44,19 @@ export default function CommitHistory({ info }: { info: CommitInfo }) {
2944
<span className='text-gray-500 text-sm'>
3045
{info.message}
3146
</span>
47+
{
48+
flag === 'contents' &&
49+
<Flex>
50+
<Button
51+
size='sm'
52+
variant='plain'
53+
className='p-0 ml-1'
54+
tooltip='Open commit details'
55+
onClick={ExpandDetails}>
56+
<EyeIcon size={24} />
57+
</Button>
58+
</Flex>
59+
}
3260

3361
<span className='text-gray-400 text-xs ml-auto mr-3'>
3462
{info.hash} · {info.date}
@@ -44,6 +72,8 @@ export default function CommitHistory({ info }: { info: CommitInfo }) {
4472
</Flex>
4573
</Button>
4674
</Flex>
47-
</Card>
75+
</div>
76+
{Expand &&<CommitDetails/>}
77+
</>
4878
)
4979
}

moon/apps/web/components/CodeView/TreeView/CloneTabs.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'
22
import { Button, Input, Popover, Space, Tabs, TabsProps } from 'antd'
33
import copy from 'copy-to-clipboard'
44
import { usePathname } from 'next/navigation'
5-
65
import { CheckIcon, CopyIcon, DownloadIcon } from '@gitmono/ui/Icons'
6+
import {LEGACY_API_URL} from '@gitmono/config'
77

88
const CloneTabs = ({ endpoint }: any) => {
99
const pathname = usePathname()
@@ -16,13 +16,13 @@ const CloneTabs = ({ endpoint }: any) => {
1616
}
1717

1818
useEffect(() => {
19-
if (endpoint) {
20-
const url = new URL(endpoint)
19+
if (LEGACY_API_URL) {
20+
const url = new URL(LEGACY_API_URL)
2121

2222
if (active_tab === '1') {
23-
setText(`${url.href}${pathname?.replace('/tree/', '')}.git`)
23+
setText(`${url.href}${pathname?.replace('/myorganization/code/tree/', '')}.git`)
2424
} else {
25-
setText(`ssh://git@${url.host}${pathname?.replace('/tree', '')}.git`)
25+
setText(`ssh://git@${url.host}${pathname?.replace('/myorganization/code/tree', '')}.git`)
2626
}
2727
}
2828
}, [pathname, active_tab, endpoint])

moon/apps/web/components/CodeView/TreeView/RepoTree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function CustomLabel({ icon: Icon, children, ...other }: CustomLabelProps) {
6161
{Icon && (
6262
<Box component={Icon} className="labelIcon" color="inherit" sx={{ mr: 1, fontSize: '1.2rem' }} />
6363
)}
64-
<TreeItemLabel>{children}</TreeItemLabel>
64+
<TreeItemLabel sx={{fontSize: '14px'}}>{children}</TreeItemLabel>
6565
</TreeItemLabel>
6666
);
6767
}
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,22 @@
11
'use client'
22

3-
import { useCallback, useEffect, useMemo, useState } from 'react'
3+
import { useMemo } from 'react'
44

55
import { CommonResultVecTreeCommitItem } from '@gitmono/types/generated'
66

77
import { useGetTreeCommitInfo } from '@/hooks/useGetTreeCommitInfo'
88

99
import SpinnerTable from './TableWithLoading'
10+
import { useGetBlob } from '@/hooks/useGetBlob'
1011

1112
export default function CodeView() {
1213
const { data: TreeCommitInfo } = useGetTreeCommitInfo('/')
1314

1415
type DirectoryType = NonNullable<CommonResultVecTreeCommitItem['data']>
1516
const directory: DirectoryType = useMemo(() => TreeCommitInfo?.data ?? [], [TreeCommitInfo])
1617

17-
const [readmeContent, setReadmeContent] = useState('')
18+
const reqPath = `/README.md`
19+
const {data: readmeContent} = useGetBlob({path:reqPath})
1820

19-
const fetchData = useCallback(async () => {
20-
if (directory.length === 0) return
21-
22-
try {
23-
const content = await getReadmeContent('/', directory)
24-
25-
setReadmeContent(content)
26-
} catch (error) {
27-
// console.error('Error fetching data:', error);
28-
}
29-
}, [directory])
30-
31-
useEffect(() => {
32-
fetchData()
33-
}, [fetchData])
34-
35-
return <SpinnerTable isLoading={!TreeCommitInfo} datasource={directory} content={readmeContent} />
36-
}
37-
38-
async function getReadmeContent(pathname: string, directory: any) {
39-
let readmeContent = ''
40-
41-
for (const project of directory || []) {
42-
if (project.name === 'README.md' && project.content_type === 'file') {
43-
const res = await fetch(`/api/blob?path=${pathname}/README.md`)
44-
const response = await res.json()
45-
46-
readmeContent = response.data.data
47-
break
48-
}
49-
}
50-
return readmeContent
21+
return <SpinnerTable isLoading={!TreeCommitInfo} datasource={directory} content={readmeContent?.data} />
5122
}

moon/apps/web/pages/[org]/code/blob/[...path].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function BlobPage() {
9494
<BreadCrumb path={path} />
9595
</Layout>
9696
<Layout className='m-2'>
97-
<CommitHistory info={commitInfo}/>
97+
<CommitHistory flag={'details'} info={commitInfo}/>
9898
</Layout>
9999
<Flex gap='middle' wrap>
100100
<Layout style={codeStyle}>

moon/apps/web/pages/[org]/code/tree/[...path]/index.tsx

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import React, { useEffect, useMemo, useState } from 'react'
3+
import React, { useMemo } from 'react'
44
import { Theme } from '@radix-ui/themes'
55
import { Flex, Layout } from 'antd'
66
import { useParams } from 'next/navigation'
@@ -16,6 +16,8 @@ import { AppLayout } from '@/components/Layout/AppLayout'
1616
import AuthAppProviders from '@/components/Providers/AuthAppProviders'
1717
import { useGetTreeCommitInfo } from '@/hooks/useGetTreeCommitInfo'
1818
import { useGetTreePathCanClone } from '@/hooks/useGetTreePathCanClone'
19+
import CommitHistory from '@/components/CodeView/CommitHistory'
20+
import { useGetBlob } from '@/hooks/useGetBlob'
1921

2022
function TreeDetailPage() {
2123
const params = useParams()
@@ -28,26 +30,22 @@ function TreeDetailPage() {
2830
const directory: DirectoryType = useMemo(() => TreeCommitInfo?.data ?? [], [TreeCommitInfo])
2931

3032
const { data: canClone } = useGetTreePathCanClone({ path: new_path })
31-
const [readmeContent, setReadmeContent] = useState('')
32-
const [endpoint, setEndPoint] = useState('')
3333

34-
useEffect(() => {
35-
const fetchData = async () => {
36-
try {
37-
const readmeContent = await getReadmeContent(new_path, directory)
34+
const reqPath = `${new_path}/README.md`
35+
const {data: readmeContent}=useGetBlob({path:reqPath})
3836

39-
setReadmeContent(readmeContent)
40-
const endpoint = await getEndpoint()
4137

42-
setEndPoint(endpoint)
43-
} catch (error) {
44-
// eslint-disable-next-line no-console
45-
console.error('Error fetching data:', error)
46-
}
47-
}
38+
const commitInfo = {
39+
user: {
40+
avatar_url: 'https://avatars.githubusercontent.com/u/112836202?v=4&size=40',
41+
name: 'yetianxing2014'
42+
},
43+
message: '[feat(libra)]: 为 config 命令添加 --default参数 (#1119)',
44+
hash: '5fe4235',
45+
date: '3 months ago'
46+
}
47+
4848

49-
fetchData()
50-
}, [new_path, directory])
5149

5250
const treeStyle = {
5351
borderRadius: 8,
@@ -61,6 +59,7 @@ function TreeDetailPage() {
6159
borderRadius: 8,
6260
overflow: 'hidden',
6361
width: 'calc(80% - 8px)',
62+
height:'100%',
6463
background: '#fff'
6564
}
6665

@@ -73,7 +72,7 @@ function TreeDetailPage() {
7372
}
7473

7574
return (
76-
<div className='relative m-2 h-screen overflow-hidden'>
75+
<div className='relative m-2 h-screen overflow-auto'>
7776
{!TreeCommitInfo ? (
7877
<div className='align-center container absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 justify-center'>
7978
<LoadingSpinner />
@@ -84,7 +83,7 @@ function TreeDetailPage() {
8483
<BreadCrumb path={path} />
8584
{canClone?.data && (
8685
<Flex justify={'flex-end'}>
87-
<CloneTabs endpoint={endpoint} />
86+
<CloneTabs/>
8887
</Flex>
8988
)}
9089
</Layout>
@@ -93,36 +92,19 @@ function TreeDetailPage() {
9392
<RepoTree directory={directory} />
9493
</Layout>
9594
<Layout style={codeStyle}>
96-
<CodeTable directory={directory} loading={!TreeCommitInfo} readmeContent={readmeContent} />
95+
{
96+
commitInfo && <Layout>
97+
<CommitHistory flag={'contents'} info={commitInfo}/>
98+
</Layout>
99+
}
100+
<CodeTable directory={directory} loading={!TreeCommitInfo} readmeContent={readmeContent?.data}/>
97101
</Layout>
98102
</Flex>
99103
)}
100104
</div>
101105
)
102106
}
103107

104-
async function getReadmeContent(pathname: string, directory: any) {
105-
let readmeContent = ''
106-
107-
for (const project of directory || []) {
108-
if (project.name === 'README.md' && project.content_type === 'file') {
109-
const res = await fetch(`/api/blob?path=${pathname}/README.md`)
110-
const response = await res.json()
111-
112-
readmeContent = response.data.data
113-
break
114-
}
115-
}
116-
return readmeContent
117-
}
118-
119-
async function getEndpoint() {
120-
const res = await fetch(`/host`)
121-
const response = await res.json()
122-
123-
return response.endpoint
124-
}
125-
126108
TreeDetailPage.getProviders = (
127109
page:
128110
| string

0 commit comments

Comments
 (0)