77
88import { useState , useCallback , useMemo } from 'react'
99import { Link } from '@tanstack/react-router'
10- import JSZip from 'jszip'
10+
1111import {
1212 Copy ,
1313 Download ,
@@ -16,7 +16,6 @@ import {
1616 Rocket ,
1717 Check ,
1818 HelpCircle ,
19- Loader2 ,
2019 Search ,
2120 Github ,
2221} from 'lucide-react'
@@ -430,7 +429,6 @@ function BuildProjectDropdown({
430429 const [ showTemplateExport , setShowTemplateExport ] = useState ( false )
431430 const [ templateName , setTemplateName ] = useState ( '' )
432431 const [ templateDescription , setTemplateDescription ] = useState ( '' )
433- const [ isGeneratingZip , setIsGeneratingZip ] = useState ( false )
434432
435433 const copyToClipboard = async ( text : string , type : string ) => {
436434 await navigator . clipboard . writeText ( text )
@@ -458,30 +456,9 @@ function BuildProjectDropdown({
458456 return `${ window . location . origin } /api/builder/download?${ params . toString ( ) } `
459457 } , [ projectName , features , tailwind , featureOptions ] )
460458
461- const downloadZip = useCallback ( async ( ) => {
462- if ( ! compiledOutput ?. files ) return
463-
464- setIsGeneratingZip ( true )
465- try {
466- const zip = new JSZip ( )
467- const rootFolder = zip . folder ( projectName )
468- if ( ! rootFolder ) return
469-
470- for ( const [ filePath , content ] of Object . entries ( compiledOutput . files ) ) {
471- rootFolder . file ( filePath , content )
472- }
473-
474- const blob = await zip . generateAsync ( { type : 'blob' } )
475- const url = URL . createObjectURL ( blob )
476- const a = document . createElement ( 'a' )
477- a . href = url
478- a . download = `${ projectName } .zip`
479- a . click ( )
480- URL . revokeObjectURL ( url )
481- } finally {
482- setIsGeneratingZip ( false )
483- }
484- } , [ compiledOutput ?. files , projectName ] )
459+ const downloadZip = useCallback ( ( ) => {
460+ window . location . href = getDownloadUrl ( )
461+ } , [ getDownloadUrl ] )
485462
486463 const generateTemplateJson = ( ) => {
487464 const template = {
@@ -540,14 +517,10 @@ function BuildProjectDropdown({
540517 variant = "primary"
541518 className = "flex-1 flex items-center justify-center gap-2"
542519 onClick = { downloadZip }
543- disabled = { ! compiledOutput ?. files || isGeneratingZip }
520+ disabled = { ! compiledOutput ?. files }
544521 >
545- { isGeneratingZip ? (
546- < Loader2 className = "w-4 h-4 animate-spin" />
547- ) : (
548- < Download className = "w-4 h-4" />
549- ) }
550- { isGeneratingZip ? 'Generating...' : 'Download ZIP' }
522+ < Download className = "w-4 h-4" />
523+ Download ZIP
551524 </ Button >
552525 < Button
553526 variant = "ghost"
0 commit comments