11'use client'
22
3- import React , { useEffect , useMemo , useState } from 'react'
3+ import React , { useMemo } from 'react'
44import { Theme } from '@radix-ui/themes'
55import { Flex , Layout } from 'antd'
66import { useParams } from 'next/navigation'
@@ -16,6 +16,8 @@ import { AppLayout } from '@/components/Layout/AppLayout'
1616import AuthAppProviders from '@/components/Providers/AuthAppProviders'
1717import { useGetTreeCommitInfo } from '@/hooks/useGetTreeCommitInfo'
1818import { useGetTreePathCanClone } from '@/hooks/useGetTreePathCanClone'
19+ import CommitHistory from '@/components/CodeView/CommitHistory'
20+ import { useGetBlob } from '@/hooks/useGetBlob'
1921
2022function 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-
126108TreeDetailPage . getProviders = (
127109 page :
128110 | string
0 commit comments