1
1
import { CodeRevision , GameMapRevision } from '@codecharacter-2022/client' ;
2
- import { useState } from 'react' ;
3
- import {
4
- VerticalTimeline ,
5
- VerticalTimelineElement ,
6
- } from 'react-vertical-timeline-component' ;
2
+ import React , { useState } from 'react' ;
3
+ import { VerticalTimelineElement } from 'react-vertical-timeline-component' ;
7
4
import 'react-vertical-timeline-component/style.min.css' ;
8
5
import './CommitHistory.css' ;
6
+ import { faCheckCircle } from '@fortawesome/free-solid-svg-icons' ;
7
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
8
+ import { IconProp } from '@fortawesome/fontawesome-svg-core' ;
9
+ import styles from '../HistoryMain/History.module.css' ;
10
+ import { useAppDispatch } from '../../../store/hooks' ;
11
+ import {
12
+ codeCommitIDChanged ,
13
+ codeCommitNameChanged ,
14
+ isSelfMatchModalOpened ,
15
+ mapCommitIDChanged ,
16
+ mapCommitNameChanged ,
17
+ } from '../../../store/SelfMatchMakeModal/SelfMatchModal' ;
9
18
10
19
type PropsType = {
11
20
commitID : ( commitID : string ) => void ;
12
21
commitHistoryDetails : CodeRevision [ ] | GameMapRevision [ ] ;
22
+ BigButton : string ;
13
23
} ;
14
24
15
25
export default function CommitHistory ( props : PropsType ) : JSX . Element {
@@ -18,8 +28,96 @@ export default function CommitHistory(props: PropsType): JSX.Element {
18
28
color : '#fff' ,
19
29
} ;
20
30
31
+ const dispatch = useAppDispatch ( ) ;
21
32
const [ commitNumber , setCommitNumber ] = useState ( '0' ) ;
22
33
34
+ function handleCommitSelect ( e : React . MouseEvent < HTMLDivElement > ) {
35
+ // Since the button has an icon, event
36
+ // target doesnt give the button element
37
+ // when clicked on the icon. Hence we get the
38
+ // parent if clicked on icon
39
+ const target = e . target as HTMLDivElement ;
40
+ if ( target . getAttribute ( 'data-uuid' ) === null ) {
41
+ if (
42
+ ( target . parentNode as HTMLButtonElement ) ?. getAttribute ( 'data-uuid' ) !==
43
+ null
44
+ ) {
45
+ if ( props . BigButton === 'Code' ) {
46
+ dispatch (
47
+ codeCommitNameChanged (
48
+ ( target . parentNode as HTMLButtonElement ) ?. getAttribute (
49
+ 'data-name' ,
50
+ ) || '' ,
51
+ ) ,
52
+ ) ;
53
+ dispatch (
54
+ codeCommitIDChanged (
55
+ ( target . parentNode as HTMLButtonElement ) ?. getAttribute (
56
+ 'data-uuid' ,
57
+ ) || '' ,
58
+ ) ,
59
+ ) ;
60
+ } else {
61
+ dispatch (
62
+ mapCommitNameChanged (
63
+ ( target . parentNode as HTMLButtonElement ) ?. getAttribute (
64
+ 'data-name' ,
65
+ ) || '' ,
66
+ ) ,
67
+ ) ;
68
+ dispatch (
69
+ mapCommitIDChanged (
70
+ ( target . parentNode as HTMLButtonElement ) ?. getAttribute (
71
+ 'data-uuid' ,
72
+ ) || '' ,
73
+ ) ,
74
+ ) ;
75
+ }
76
+ } else {
77
+ if ( props . BigButton === 'Code' ) {
78
+ dispatch (
79
+ codeCommitNameChanged (
80
+ (
81
+ target . parentNode ?. parentNode as HTMLButtonElement
82
+ ) ?. getAttribute ( 'data-name' ) || '' ,
83
+ ) ,
84
+ ) ;
85
+ dispatch (
86
+ codeCommitIDChanged (
87
+ (
88
+ target . parentNode ?. parentNode as HTMLButtonElement
89
+ ) ?. getAttribute ( 'data-uuid' ) || '' ,
90
+ ) ,
91
+ ) ;
92
+ } else {
93
+ dispatch (
94
+ mapCommitNameChanged (
95
+ (
96
+ target . parentNode ?. parentNode as HTMLButtonElement
97
+ ) ?. getAttribute ( 'data-name' ) || '' ,
98
+ ) ,
99
+ ) ;
100
+ dispatch (
101
+ mapCommitIDChanged (
102
+ (
103
+ target . parentNode ?. parentNode as HTMLButtonElement
104
+ ) ?. getAttribute ( 'data-uuid' ) || '' ,
105
+ ) ,
106
+ ) ;
107
+ }
108
+ }
109
+ } else {
110
+ if ( props . BigButton === 'Code' ) {
111
+ dispatch ( codeCommitNameChanged ( target . getAttribute ( 'data-name' ) || '' ) ) ;
112
+ dispatch ( codeCommitIDChanged ( target . getAttribute ( 'data-uuid' ) || '' ) ) ;
113
+ } else {
114
+ dispatch ( mapCommitNameChanged ( target . getAttribute ( 'data-name' ) || '' ) ) ;
115
+ dispatch ( mapCommitIDChanged ( target . getAttribute ( 'data-uuid' ) || '' ) ) ;
116
+ }
117
+ }
118
+
119
+ dispatch ( isSelfMatchModalOpened ( true ) ) ;
120
+ }
23
121
const parseTimeFormat = ( machineTime : string ) => {
24
122
const commitTimestamp = new Date ( machineTime ) ;
25
123
const datePart = commitTimestamp . toDateString ( ) . substring ( 4 , 10 ) ;
@@ -30,37 +128,49 @@ export default function CommitHistory(props: PropsType): JSX.Element {
30
128
return (
31
129
< div >
32
130
{ props . commitHistoryDetails && props . commitHistoryDetails . length > 0 ? (
33
- < VerticalTimeline layout = { '1-column' } animate = { true } >
34
- { props . commitHistoryDetails . map ( ( eachCommit , index ) => {
35
- return (
36
- < VerticalTimelineElement
37
- key = { eachCommit . id . toString ( ) }
38
- className = "vertical-timeline-element--work"
39
- contentStyle = { { background : '#242a3c' , color : '#fff' } }
40
- contentArrowStyle = { {
41
- borderRight : '7px solid rgb(33, 150, 243)' ,
42
- } }
43
- date = { parseTimeFormat ( eachCommit . createdAt . toString ( ) ) }
44
- iconStyle = {
45
- commitNumber == eachCommit . id
46
- ? CircleIcon
47
- : { background : 'rgb(33, 150, 243)' , color : '#fff' }
48
- }
49
- onTimelineElementClick = { ( ) => {
50
- setCommitNumber ( eachCommit . id ) ;
51
- props . commitID ( eachCommit . id ) ;
52
- } }
131
+ props . commitHistoryDetails . map ( ( eachCommit , index ) => {
132
+ return (
133
+ < VerticalTimelineElement
134
+ key = { eachCommit . id . toString ( ) }
135
+ className = "vertical-timeline-element--work"
136
+ contentStyle = { { background : '#242a3c' , color : '#fff' } }
137
+ contentArrowStyle = { {
138
+ borderRight : '7px solid rgb(33, 150, 243)' ,
139
+ } }
140
+ date = { parseTimeFormat ( eachCommit . createdAt . toString ( ) ) }
141
+ iconStyle = {
142
+ commitNumber == eachCommit . id
143
+ ? CircleIcon
144
+ : { background : 'rgb(33, 150, 243)' , color : '#fff' }
145
+ }
146
+ onTimelineElementClick = { ( ) => {
147
+ setCommitNumber ( eachCommit . id ) ;
148
+ props . commitID ( eachCommit . id ) ;
149
+ } }
150
+ >
151
+ < h3 className = "vertical-timeline-element-title" >
152
+ { `Commit - ${ index + 1 } ` }
153
+ </ h3 >
154
+ < h6 className = "vertical-timeline-element-subtitle" >
155
+ { eachCommit . message }
156
+ </ h6 >
157
+ < div
158
+ className = "vertical-timeline-element-subtitle flex d-flex justify-content-end"
159
+ onClick = { e => handleCommitSelect ( e ) }
53
160
>
54
- < h3 className = "vertical-timeline-element-title" >
55
- { `Commit - ${ index + 1 } ` }
56
- </ h3 >
57
- < h6 className = "vertical-timeline-element-subtitle" >
58
- { eachCommit . message }
59
- </ h6 >
60
- </ VerticalTimelineElement >
61
- ) ;
62
- } ) }
63
- </ VerticalTimeline >
161
+ < button
162
+ className = { styles . selectBtn }
163
+ data-name = { eachCommit . message }
164
+ data-uuid = { eachCommit . id }
165
+ >
166
+ { ' ' }
167
+ < FontAwesomeIcon icon = { faCheckCircle as IconProp } /> { ' ' }
168
+ < b > Select</ b > { ' ' }
169
+ </ button >
170
+ </ div >
171
+ </ VerticalTimelineElement >
172
+ ) ;
173
+ } )
64
174
) : (
65
175
< h1 className = "noCommitStyle" > No Commits available</ h1 >
66
176
) }
0 commit comments