@@ -6,14 +6,9 @@ import {
66 MenuGroup ,
77 MenuItem ,
88} from '@wordpress/components' ;
9- import { moreVertical , upload , link } from '@wordpress/icons' ;
10- import { Icon } from '@wordpress/icons' ;
11- import { GitHubIcon } from '../../github/github' ;
9+ import { moreVertical } from '@wordpress/icons' ;
1210import { useDispatch } from 'react-redux' ;
13- import { useState , useEffect , useRef } from 'react' ;
14- import { usePlaygroundClient } from '../../lib/use-playground-client' ;
15- import { importWordPressFiles } from '@wp-playground/client' ;
16- import { logger } from '@php-wasm/logger' ;
11+ import { useState } from 'react' ;
1712import {
1813 setActiveSite ,
1914 useActiveSite ,
@@ -77,101 +72,17 @@ export function SavedPlaygroundsOverlay({
7772 onClose,
7873 initialViewMode = 'main' ,
7974} : SavedPlaygroundsOverlayProps ) {
80- const offline = useAppSelector ( ( state ) => state . ui . offline ) ;
8175 const storedSites = useAppSelector ( selectSortedSites ) . filter (
8276 ( site ) => site . metadata . storage !== 'none'
8377 ) ;
8478 const temporarySite = useAppSelector ( selectTemporarySite ) ;
8579 const activeSite = useActiveSite ( ) ;
8680 const dispatch = useAppDispatch ( ) ;
8781 const modalDispatch : PlaygroundDispatch = useDispatch ( ) ;
88- const playground = usePlaygroundClient ( ) ;
89- const zipFileInputRef = useRef < HTMLInputElement > ( null ) ;
9082
9183 const [ viewMode , setViewMode ] = useState < OverlayViewMode > ( initialViewMode ) ;
9284 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
9385 const [ selectedTag , setSelectedTag ] = useState < string | null > ( null ) ;
94- const [ pendingZipFile , setPendingZipFile ] = useState < File | null > ( null ) ;
95-
96- const isTemporarySite = activeSite ?. metadata . storage === 'none' ;
97-
98- useEffect ( ( ) => {
99- if ( ! pendingZipFile || ! isTemporarySite || ! playground ) {
100- return ;
101- }
102-
103- const doImport = async ( ) => {
104- try {
105- await importWordPressFiles ( playground , {
106- wordPressFilesZip : pendingZipFile ,
107- } ) ;
108- setTimeout ( async ( ) => {
109- await playground . goTo ( '/' ) ;
110- } , 200 ) ;
111- alert (
112- 'File imported! This Playground instance has been updated and will refresh shortly.'
113- ) ;
114- onClose ( ) ;
115- } catch ( error ) {
116- logger . error ( error ) ;
117- alert (
118- 'Unable to import file. Is it a valid WordPress Playground export?'
119- ) ;
120- } finally {
121- setPendingZipFile ( null ) ;
122- if ( zipFileInputRef . current ) {
123- zipFileInputRef . current . value = '' ;
124- }
125- }
126- } ;
127- doImport ( ) ;
128- } , [ pendingZipFile , isTemporarySite , playground , onClose ] ) ;
129-
130- function switchToTemporarySite ( ) {
131- if ( temporarySite ) {
132- dispatch ( setActiveSite ( temporarySite . slug ) ) ;
133- } else {
134- redirectTo ( PlaygroundRoute . newTemporarySite ( ) ) ;
135- }
136- }
137-
138- const handleImportZip = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
139- const file = e . target . files ?. [ 0 ] ;
140- if ( ! file ) return ;
141-
142- if ( ! isTemporarySite ) {
143- setPendingZipFile ( file ) ;
144- switchToTemporarySite ( ) ;
145- return ;
146- }
147-
148- if ( ! playground ) {
149- alert (
150- 'No active Playground to import into. Please create one first.'
151- ) ;
152- return ;
153- }
154-
155- try {
156- await importWordPressFiles ( playground , { wordPressFilesZip : file } ) ;
157- setTimeout ( async ( ) => {
158- await playground . goTo ( '/' ) ;
159- } , 200 ) ;
160- alert (
161- 'File imported! This Playground instance has been updated and will refresh shortly.'
162- ) ;
163- onClose ( ) ;
164- } catch ( error ) {
165- logger . error ( error ) ;
166- alert (
167- 'Unable to import file. Is it a valid WordPress Playground export?'
168- ) ;
169- }
170-
171- if ( zipFileInputRef . current ) {
172- zipFileInputRef . current . value = '' ;
173- }
174- } ;
17586
17687 const {
17788 data : blueprintsData ,
@@ -309,44 +220,6 @@ export function SavedPlaygroundsOverlay({
309220 } ,
310221 disabled : false ,
311222 } ,
312- ...( ! isInstallDisabledByQueryParam ( )
313- ? [
314- {
315- id : 'github' ,
316- title : 'From GitHub' ,
317- iconComponent : GitHubIcon ,
318- onClick : ( ) => {
319- if ( ! isTemporarySite ) {
320- switchToTemporarySite ( ) ;
321- }
322- modalDispatch (
323- setActiveModal ( modalSlugs . GITHUB_IMPORT )
324- ) ;
325- } ,
326- disabled : offline ,
327- } ,
328- {
329- id : 'blueprint-url' ,
330- title : 'Blueprint URL' ,
331- icon : link ,
332- onClick : ( ) => {
333- modalDispatch (
334- setActiveModal ( modalSlugs . BLUEPRINT_URL )
335- ) ;
336- } ,
337- disabled : offline ,
338- } ,
339- ]
340- : [ ] ) ,
341- {
342- id : 'zip' ,
343- title : 'Import .zip' ,
344- icon : upload ,
345- onClick : ( ) => {
346- zipFileInputRef . current ?. click ( ) ;
347- } ,
348- disabled : false ,
349- } ,
350223 ] ;
351224
352225 if ( viewMode === 'blueprints' ) {
@@ -523,13 +396,6 @@ export function SavedPlaygroundsOverlay({
523396
524397 return (
525398 < Overlay onClose = { onClose } >
526- < input
527- type = "file"
528- ref = { zipFileInputRef }
529- onChange = { handleImportZip }
530- accept = ".zip,application/zip"
531- style = { { display : 'none' } }
532- />
533399 < OverlayHeader onClose = { onClose } />
534400 < OverlayBody >
535401 < OverlaySection title = "Start a new Playground" >
@@ -542,11 +408,7 @@ export function SavedPlaygroundsOverlay({
542408 disabled = { option . disabled }
543409 >
544410 < span className = { css . creationIcon } >
545- { 'iconComponent' in option ? (
546- option . iconComponent
547- ) : (
548- < Icon icon = { option . icon } size = { 24 } />
549- ) }
411+ { option . iconComponent }
550412 </ span >
551413 < span className = { css . creationTitle } >
552414 { option . title }
@@ -564,7 +426,8 @@ export function SavedPlaygroundsOverlay({
564426 </ div >
565427 ) : blueprintsError ? (
566428 < p className = { css . emptyMessage } >
567- Unable to load blueprints. Check your connection.
429+ Unable to load blueprints. Check your
430+ connection.
568431 </ p >
569432 ) : (
570433 < div className = { css . blueprintsRow } >
@@ -583,7 +446,9 @@ export function SavedPlaygroundsOverlay({
583446 >
584447 { blueprint . screenshot_url ? (
585448 < img
586- src = { blueprint . screenshot_url }
449+ src = {
450+ blueprint . screenshot_url
451+ }
587452 alt = ""
588453 loading = "lazy"
589454 />
@@ -597,7 +462,11 @@ export function SavedPlaygroundsOverlay({
597462 </ div >
598463 ) }
599464 </ div >
600- < span className = { css . blueprintPreviewTitle } >
465+ < span
466+ className = {
467+ css . blueprintPreviewTitle
468+ }
469+ >
601470 { blueprint . title }
602471 </ span >
603472 </ button >
@@ -615,12 +484,13 @@ export function SavedPlaygroundsOverlay({
615484 < GridIcon size = { 50 } />
616485 </ div >
617486 < span className = { css . blueprintPreviewTitle } >
618- View all { allBlueprints . length } blueprints
619- </ span >
620- </ button >
621- </ div >
622- ) }
623- </ OverlaySection >
487+ View all { allBlueprints . length } { ' ' }
488+ blueprints
489+ </ span >
490+ </ button >
491+ </ div >
492+ ) }
493+ </ OverlaySection >
624494 ) }
625495
626496 < OverlaySection title = "Your Playgrounds" >
0 commit comments