@@ -7,15 +7,15 @@ import { Button } from "antd";
7
7
const CopyPasteControls = ( ) => {
8
8
console . log ( "CopyPasteControls" ) ;
9
9
10
- const state = useRootStore ( ( state ) => state ) ;
11
10
const setStateFromClipboard = useRootStore ( ( state ) => state . setStateFromClipboard ) ;
11
+ const copyStateToClipboard = useRootStore ( ( state ) => state . copyStateToClipboard ) ;
12
12
13
13
const handlePasteError = ( error : Error ) => {
14
14
alert ( "Sorry - couldn't parse pasted selection" ) ;
15
15
console . error ( "Pasting state failed" , error ) ;
16
16
} ;
17
17
18
- const handlePaste = useCallback (
18
+ const pasteStateFromText = useCallback (
19
19
( text : string ) => {
20
20
try {
21
21
const parsedState = JSON . parse ( text ) ;
@@ -32,10 +32,10 @@ const CopyPasteControls = () => {
32
32
event . preventDefault ( ) ;
33
33
const text = event . clipboardData ?. getData ( "text/plain" ) ;
34
34
if ( text ) {
35
- handlePaste ( text ) ;
35
+ pasteStateFromText ( text ) ;
36
36
}
37
37
} ,
38
- [ handlePaste ]
38
+ [ pasteStateFromText ]
39
39
) ;
40
40
41
41
useEffect ( ( ) => {
@@ -45,37 +45,24 @@ const CopyPasteControls = () => {
45
45
} ;
46
46
} , [ handleClipboardPaste ] ) ;
47
47
48
- const copy = ( ) => {
49
- const serializedState = {
50
- frameworks : state . frameworks . filter ( ( f ) => state . selectedFrameworks . has ( f ) ) . map ( ( f ) => f . dir ) ,
51
- benchmarks : state . benchmarks . filter ( ( f ) => state . selectedBenchmarks . has ( f ) ) . map ( ( f ) => f . id ) ,
52
- displayMode : state . displayMode ,
53
- } ;
54
-
55
- const json = JSON . stringify ( serializedState ) ;
56
-
57
- try {
58
- navigator . clipboard . writeText ( json ) ;
59
- window . location . hash = btoa ( json ) ;
60
- } catch ( error ) {
61
- console . error ( "Copying state failed" , error ) ;
62
- }
63
- } ;
64
-
65
48
const handlePasteFromClipboard = useCallback ( async ( ) => {
66
49
try {
67
50
const text = await navigator . clipboard . readText ( ) ;
68
- handlePaste ( text ) ;
51
+ pasteStateFromText ( text ) ;
69
52
} catch ( error ) {
70
53
handlePasteError ( error as Error ) ;
71
54
}
72
- } , [ handlePaste ] ) ;
55
+ } , [ pasteStateFromText ] ) ;
73
56
74
57
return (
75
58
< div className = "copy-paste-panel" >
76
59
< div > Copy/paste current selection</ div >
77
60
< div className = "copy-paste-panel__buttons" >
78
- < Button onClick = { copy } icon = { < CopyIcon size = { 20 } /> } aria-label = "Copy selected frameworks and benchmarks" />
61
+ < Button
62
+ onClick = { copyStateToClipboard }
63
+ icon = { < CopyIcon size = { 20 } /> }
64
+ aria-label = "Copy selected frameworks and benchmarks"
65
+ />
79
66
< Button
80
67
onClick = { handlePasteFromClipboard }
81
68
icon = { < ClipboardPasteIcon size = { 20 } /> }
0 commit comments