File tree 3 files changed +56
-2
lines changed
3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react'
2
+ import { Chess } from 'chess.ts'
3
+
4
+ import { Move } from 'src/types'
5
+
6
+ interface Props {
7
+ moves : Move [ ]
8
+ }
9
+
10
+ export const ExportGame : React . FC < Props > = ( { moves } ) => {
11
+ const [ pgn , setPgn ] = useState ( '' )
12
+
13
+ useEffect ( ( ) => {
14
+ const chess = new Chess ( )
15
+ moves . forEach ( ( move ) => {
16
+ if ( move . san ) {
17
+ chess . move ( move . san )
18
+ }
19
+ } )
20
+ setPgn ( chess . pgn ( ) )
21
+ } , [ moves ] )
22
+
23
+ const copy = ( content : string ) => {
24
+ navigator . clipboard . writeText ( content )
25
+ }
26
+
27
+ return (
28
+ < div className = "flex flex-row items-center justify-center gap-2" >
29
+ < div className = "flex h-10 items-center overflow-hidden rounded border border-primary/10 bg-background-1" >
30
+ < div className = "flex w-[500px] items-center justify-start bg-background-1 px-4" >
31
+ < p className = "whitespace-nowrap text-sm text-secondary" >
32
+ { moves [ moves . length - 1 ] . board }
33
+ </ p >
34
+ </ div >
35
+ < button
36
+ onClick = { ( ) => copy ( moves [ moves . length - 1 ] . board ) }
37
+ className = "flex h-10 w-10 min-w-10 items-center justify-center border-l border-primary/10 bg-background-2 transition duration-200 hover:bg-background-3"
38
+ >
39
+ < span className = "material-symbols-outlined text-xl" >
40
+ content_copy
41
+ </ span >
42
+ </ button >
43
+ </ div >
44
+ < button
45
+ onClick = { ( ) => copy ( pgn ) }
46
+ className = "flex h-10 items-center justify-center rounded border border-primary/10 bg-background-2 px-4 py-1 transition duration-300 hover:bg-background-3"
47
+ >
48
+ Copy PGN
49
+ </ button >
50
+ </ div >
51
+ )
52
+ }
Original file line number Diff line number Diff line change 1
1
export * from './GameInfo'
2
+ export * from './ExportGame'
2
3
export * from './ContinueAgainstMaia'
Original file line number Diff line number Diff line change 9
9
WindowSizeContext ,
10
10
} from 'src/contexts'
11
11
import { GameBoard , MovesContainer , BoardController } from 'src/components'
12
- import { GameInfo } from '../Core'
12
+ import { GameInfo , ExportGame } from '../Core'
13
13
import { GameClock } from '../GameClock'
14
14
import { useGameController } from 'src/hooks'
15
15
import { StatsDisplay } from '../StatsDisplay'
@@ -159,7 +159,7 @@ export const GameplayInterface: React.FC<Props> = (
159
159
const desktopLayout = (
160
160
< >
161
161
< div className = "flex h-full flex-1 flex-col justify-center gap-1" >
162
- < div className = "mt-2 flex w-full flex-row items-center justify-center gap-1" >
162
+ < div className = "flex w-full flex-row items-center justify-center gap-1" >
163
163
< div
164
164
style = { {
165
165
maxWidth : 'min(20vw, 100vw - 75vh)' ,
@@ -219,6 +219,7 @@ export const GameplayInterface: React.FC<Props> = (
219
219
) : null }
220
220
</ div >
221
221
</ div >
222
+ < ExportGame moves = { game . moves . slice ( 0 , controller . currentIndex + 1 ) } />
222
223
</ div >
223
224
</ >
224
225
)
You can’t perform that action at this time.
0 commit comments