1
- import React , { useState } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import Input from './Input' ;
3
3
import CopyButton from './CopyButton' ;
4
4
import Embedded from './Embedded' ;
5
- import { XIcon } from '@primer/octicons-react' ;
5
+ import { SyncIcon , XIcon } from '@primer/octicons-react' ;
6
6
7
7
function TabButton ( { children, active, onClick, disabled } ) {
8
8
return (
@@ -24,30 +24,41 @@ function TabButton({ children, active, onClick, disabled }) {
24
24
25
25
const possiblePanes = [ 'markup' , 'preview' , 'query' , 'result' ] ;
26
26
27
- function Embed ( { dirty, gistId, gistVersion } ) {
28
- const [ panes , setPanes ] = useState ( [ 'preview' , 'result' ] ) ;
27
+ const styles = {
28
+ section : { width : 850 } ,
29
+ frame : { width : 850 , height : 375 } ,
30
+ } ;
31
+
32
+ // TODO: make the preview frame height match the end result, and let
33
+ // the user modify the frame height
34
+ function Embed ( { dispatch, dirty, gistId, gistVersion } ) {
35
+ useEffect ( ( ) => {
36
+ if ( ! dirty ) {
37
+ return ;
38
+ }
29
39
30
- const width = 850 ;
31
- const height = 300 ;
40
+ dispatch ( { type : 'SAVE' } ) ;
41
+ } , [ dirty , gistId , dispatch ] ) ;
42
+
43
+ const [ panes , setPanes ] = useState ( [ 'preview' , 'result' ] ) ;
32
44
33
45
const embedUrl =
34
46
[ location . origin , 'embed' , gistId , gistVersion ] . filter ( Boolean ) . join ( '/' ) +
35
47
`?panes=${ panes . join ( ',' ) } ` ;
36
48
37
- const embedCode = `<iframe src="${ embedUrl } " height="${ height } " width="100%" scrolling="no" frameBorder="0" allowTransparency="true" title="Testing Playground" style="overflow: hidden; display: block; width: 100%"></iframe>` ;
49
+ const embedCode = `<iframe src="${ embedUrl } " height="450 " width="100%" scrolling="no" frameBorder="0" allowTransparency="true" title="Testing Playground" style="overflow: hidden; display: block; width: 100%"></iframe>` ;
38
50
const canAddPane = panes . length < 3 ;
39
51
52
+ const loader = (
53
+ < div className = "flex space-x-4 items-center border rounded w-full py-2 px-3 bg-white text-gray-800 leading-tight" >
54
+ < SyncIcon size = { 12 } className = "spinner" />
55
+ < span > one sec...</ span >
56
+ </ div >
57
+ ) ;
58
+
40
59
return (
41
60
< div className = "settings text-sm pb-2" >
42
61
< div className = "space-y-6" >
43
- { dirty && (
44
- < section className = "bg-blue-100 p-2 text-xs rounded my-2 text-blue-800" >
45
- Please note that this playground has
46
- < strong > unsaved changes </ strong > . The embed
47
- < strong > will not include </ strong > your latest changes!
48
- </ section >
49
- ) }
50
-
51
62
< section className = "flex flex-col space-y-4" >
52
63
< div className = "flex items-center justify-between" >
53
64
< h3 className = "text-sm font-bold" > Configure</ h3 >
@@ -98,35 +109,51 @@ function Embed({ dirty, gistId, gistVersion }) {
98
109
) ) }
99
110
</ div >
100
111
101
- < div style = { { width, height } } >
102
- < Embedded
103
- panes = { panes }
104
- gistId = { gistId }
105
- gistVersion = { gistVersion }
106
- />
112
+ < div style = { styles . frame } >
113
+ { dirty ? null : (
114
+ < Embedded
115
+ panes = { panes }
116
+ gistId = { gistId }
117
+ gistVersion = { gistVersion }
118
+ height = { styles . frame . height }
119
+ />
120
+ ) }
107
121
</ div >
108
122
</ div >
109
123
</ section >
110
124
111
- < section className = "flex flex-col space-y-4" style = { { width } } >
125
+ < section className = "flex flex-col space-y-4" style = { styles . section } >
112
126
< h3 className = "text-sm font-bold" > Copy & Paste </ h3 >
113
127
114
128
< label className = "text-xs" >
115
129
embed link:
116
- < div className = "flex space-x-4" >
117
- < Input value = { embedUrl } onChange = { ( ) => { } } readOnly name = "url" />
118
- < CopyButton text = { embedUrl } />
119
- </ div >
130
+ { dirty ? (
131
+ loader
132
+ ) : (
133
+ < div className = "flex space-x-4" >
134
+ < Input
135
+ value = { embedUrl }
136
+ onChange = { ( ) => { } }
137
+ readOnly
138
+ name = "url"
139
+ />
140
+ < CopyButton text = { embedUrl } />
141
+ </ div >
142
+ ) }
120
143
</ label >
121
144
122
145
< label className = "text-xs" >
123
146
embed code:
124
- < div className = "w-full flex space-x-4" >
125
- < code className = "p-4 rounded bg-gray-200 text-gray-800 font-mono text-xs" >
126
- { embedCode }
127
- </ code >
128
- < CopyButton text = { embedCode } />
129
- </ div >
147
+ { dirty ? (
148
+ loader
149
+ ) : (
150
+ < div className = "w-full flex space-x-4" >
151
+ < code className = "p-4 rounded bg-gray-200 text-gray-800 font-mono text-xs" >
152
+ { embedCode }
153
+ </ code >
154
+ < CopyButton text = { embedCode } />
155
+ </ div >
156
+ ) }
130
157
</ label >
131
158
</ section >
132
159
</ div >
0 commit comments