1- import React , { useEffect , useMemo , useState } from 'react'
1+ import React , { useMemo } from 'react'
22import { CopyIcon , FileCodeIcon } from '@primer/octicons-react'
33import copy from 'copy-to-clipboard'
44import { format , formatDistance , fromUnixTime } from 'date-fns'
55import { useAtom } from 'jotai'
66import { useRouter } from 'next/router'
77import toast from 'react-hot-toast'
88
9- import { CommitSummary , CommonPageDiffItem , DiffItem } from '@gitmono/types'
9+ import { CommitSummary , CommonPageDiffItem , CommonResultVecMuiTreeNode , DiffItem } from '@gitmono/types'
1010import { LoadingSpinner } from '@gitmono/ui'
1111
1212import { formatAssignees } from '@/components/CodeView/CommitsView'
1313import { commitPath } from '@/components/CodeView/CommitsView/items'
1414import FileDiff from '@/components/DiffView/FileDiff'
1515import { MemberHoverAvatarList } from '@/components/Issues/MemberHoverAvatarList'
1616import { useScope } from '@/contexts/scope'
17- import { useGetCommitsDetail } from '@/hooks/commits/useGetCommitsDetail'
17+ import { useGetCommitsMuiTree } from '@/hooks/commits/useGetCommitsMuiTree'
18+ import { usePostCommitsFilesChanged } from '@/hooks/commits/usePostCommitsFilesChanged'
1819
1920interface CommitDetailData {
2021 commit : CommitSummary
@@ -26,44 +27,42 @@ export const CommitsDetailView: React.FC = () => {
2627 const { sha } = router . query
2728 const { scope } = useScope ( )
2829
29- const { mutate : commitDetail , isPending : isLoadingCommitDetail } = useGetCommitsDetail ( )
30-
3130 const [ commitPathValue , _setCommitPath ] = useAtom ( commitPath )
32- const [ commitsDetail , setCommitsDetail ] = useState < CommitDetailData > ( )
3331
34- useEffect ( ( ) => {
35- if ( ! sha || ! commitPathValue ) return
32+ const commitSha = Array . isArray ( sha ) ? sha [ 0 ] : ( sha ?? '' )
3633
37- commitDetail (
38- {
39- data : {
40- path : commitPathValue ,
41- sha : Array . isArray ( sha ) ? sha [ 0 ] : ( sha ?? '' )
42- }
43- } ,
44- {
45- onSuccess : ( response ) => {
46- const data = response . data
34+ const commitParams = useMemo ( ( ) => {
35+ if ( ! commitSha || ! commitPathValue ) return null
36+ return {
37+ path : commitPathValue ,
38+ sha : commitSha
39+ }
40+ } , [ commitPathValue , commitSha ] )
4741
48- if ( data ) {
49- setCommitsDetail ( data )
50- }
51- }
52- }
53- )
54- } , [ sha , commitDetail , commitPathValue ] )
42+ const { data : filesChangedRes , isLoading : isLoadingFilesChanged } = usePostCommitsFilesChanged ( commitParams , {
43+ page : 1 ,
44+ per_page : 100
45+ } )
46+
47+ const { data : treeResponse , isLoading : treeIsLoading } = useGetCommitsMuiTree ( commitParams )
48+
49+ const commitsDetail : CommitDetailData | undefined = useMemo ( ( ) => {
50+ if ( ! filesChangedRes ?. data ) return undefined
51+ return {
52+ commit : filesChangedRes . data . commit ,
53+ diffs : filesChangedRes . data . page . items as DiffItem [ ]
54+ }
55+ } , [ filesChangedRes ] )
5556
56- // Convert diffs to CommonPageDiffItem format
5757 const fileChangeData : CommonPageDiffItem | undefined = useMemo ( ( ) => {
5858 if ( ! commitsDetail ?. diffs ) return undefined
5959
6060 return {
6161 items : commitsDetail . diffs ,
62- total : commitsDetail . diffs . length
62+ total : filesChangedRes ?. data ?. page . total ?? commitsDetail . diffs . length
6363 }
64- } , [ commitsDetail ] )
64+ } , [ commitsDetail , filesChangedRes ] )
6565
66- // Calculate total stats
6766 const stats = useMemo ( ( ) => {
6867 if ( ! commitsDetail ?. diffs ) return { additions : 0 , deletions : 0 , files : 0 }
6968
@@ -89,10 +88,9 @@ export const CommitsDetailView: React.FC = () => {
8988 }
9089 } , [ commitsDetail ] )
9190
92- const commitSha = Array . isArray ( sha ) ? sha [ 0 ] : ( sha ?? '' )
9391 const commitDate = commitsDetail ?. commit . date ? fromUnixTime ( parseInt ( commitsDetail . commit . date , 10 ) ) : null
9492
95- if ( isLoadingCommitDetail && ! commitsDetail ) {
93+ if ( isLoadingFilesChanged && ! commitsDetail ) {
9694 return (
9795 < div className = 'flex h-[400px] items-center justify-center' >
9896 < LoadingSpinner />
@@ -147,21 +145,27 @@ export const CommitsDetailView: React.FC = () => {
147145 </ div >
148146
149147 { commitDate && (
150- < span className = 'inline-flex items-center rounded-full border border-gray-300 bg-gray-50 px-2 py-0.5 text-[11px] font-medium text-gray-700' >
151- GPG Verified{ /*{item.Verified}*/ }
148+ < span
149+ className = { `inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium ${
150+ commitsDetail . commit . gpg_status === 'Verified'
151+ ? 'border-green-600 text-green-600'
152+ : commitsDetail . commit . gpg_status === 'Unverified'
153+ ? 'border-yellow-600 text-yellow-600'
154+ : 'border-gray-600 text-gray-600'
155+ } `}
156+ >
157+ { commitsDetail . commit . gpg_status }
152158 </ span >
153159 ) }
154160 </ div >
155161 </ div >
156162
157- { /* File Stats */ }
158163 { fileChangeData && (
159164 < div className = 'flex flex-col px-5' >
160165 < div className = 'justify-center rounded-lg border border-gray-200' >
161166 < div className = 'border-b px-4 py-2 text-gray-900' > { commitsDetail . commit . short_message } </ div >
162167
163168 < div className = 'flex items-center justify-between px-4 py-2 text-sm' >
164- { /* Left side: File stats */ }
165169 < div className = 'flex items-center gap-4' >
166170 < div className = 'flex items-center gap-2' >
167171 < span className = 'font-medium text-gray-700' > { stats . files } </ span >
@@ -177,7 +181,6 @@ export const CommitsDetailView: React.FC = () => {
177181 </ div >
178182 </ div >
179183
180- { /* Right side: Parent commits and current commit */ }
181184 < div className = 'flex items-center gap-2 text-sm text-gray-600' >
182185 { commitsDetail . commit . parents && commitsDetail . commit . parents . length > 0 ? (
183186 < >
@@ -240,13 +243,9 @@ export const CommitsDetailView: React.FC = () => {
240243 { fileChangeData ? (
241244 < FileDiff
242245 fileChangeData = { fileChangeData }
243- fileChangeIsLoading = { isLoadingCommitDetail }
244- treeData = { {
245- data : [ ] ,
246- err_message : '' ,
247- req_result : true
248- } }
249- treeIsLoading = { false }
246+ fileChangeIsLoading = { isLoadingFilesChanged }
247+ treeData = { treeResponse ?. data as CommonResultVecMuiTreeNode [ 'data' ] }
248+ treeIsLoading = { treeIsLoading }
250249 />
251250 ) : (
252251 < div className = 'flex h-[200px] items-center justify-center text-gray-500' > No file changes</ div >
0 commit comments