1- import React , { useState } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import Input from './Input' ;
33import CopyButton from './CopyButton' ;
44import Embedded from './Embedded' ;
5- import { XIcon } from '@primer/octicons-react' ;
5+ import { SyncIcon , XIcon } from '@primer/octicons-react' ;
66
77function TabButton ( { children, active, onClick, disabled } ) {
88 return (
@@ -24,30 +24,41 @@ function TabButton({ children, active, onClick, disabled }) {
2424
2525const possiblePanes = [ 'markup' , 'preview' , 'query' , 'result' ] ;
2626
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+ }
2939
30- const width = 850 ;
31- const height = 300 ;
40+ dispatch ( { type : 'SAVE' } ) ;
41+ } , [ dirty , gistId , dispatch ] ) ;
42+
43+ const [ panes , setPanes ] = useState ( [ 'preview' , 'result' ] ) ;
3244
3345 const embedUrl =
3446 [ location . origin , 'embed' , gistId , gistVersion ] . filter ( Boolean ) . join ( '/' ) +
3547 `?panes=${ panes . join ( ',' ) } ` ;
3648
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>` ;
3850 const canAddPane = panes . length < 3 ;
3951
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+
4059 return (
4160 < div className = "settings text-sm pb-2" >
4261 < 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-
5162 < section className = "flex flex-col space-y-4" >
5263 < div className = "flex items-center justify-between" >
5364 < h3 className = "text-sm font-bold" > Configure</ h3 >
@@ -98,35 +109,51 @@ function Embed({ dirty, gistId, gistVersion }) {
98109 ) ) }
99110 </ div >
100111
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+ ) }
107121 </ div >
108122 </ div >
109123 </ section >
110124
111- < section className = "flex flex-col space-y-4" style = { { width } } >
125+ < section className = "flex flex-col space-y-4" style = { styles . section } >
112126 < h3 className = "text-sm font-bold" > Copy & Paste </ h3 >
113127
114128 < label className = "text-xs" >
115129 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+ ) }
120143 </ label >
121144
122145 < label className = "text-xs" >
123146 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+ ) }
130157 </ label >
131158 </ section >
132159 </ div >
0 commit comments