1- import { useEffect , useState } from 'react'
2- import { IconArrowDown , IconArrowRight , IconLogoLoading } from '../icons'
1+ import { DragEvent , useEffect , useState } from 'react'
2+ import { IconArrowDown , IconArrowRight , IconLogoLoading , IconUpload } from '../icons'
33import githubStore , { GithubRelease , GithubAsset } from '../../store/githubStore'
44import ReleaseList from '../ReleaseList'
55import RunPreppedApp from './RunPreppedApp'
@@ -11,6 +11,7 @@ interface responseData {
1111 final : boolean
1212 error ?: string
1313}
14+
1415interface returnData {
1516 appId : string
1617 appName : string
@@ -29,6 +30,7 @@ const Web = (): JSX.Element => {
2930 const [ repoReleases , setRepoReleases ] = useState < RepoReleases [ ] > ( [ ] )
3031 const [ openRepoUrl , setOpenRepoUrl ] = useState < string | null > ( null )
3132 const [ openReleaseId , setOpenReleaseId ] = useState < number | null > ( null )
33+ const [ dragActive , setDragActive ] = useState ( false )
3234 const [ loading , setLoading ] = useState ( false )
3335 const [ appData , setAppData ] = useState < returnData | null > ( null )
3436 const [ error , setError ] = useState < string | null > ( null )
@@ -122,6 +124,45 @@ const Web = (): JSX.Element => {
122124 setAppData ( null )
123125 }
124126
127+ const handleDrop = async ( event : DragEvent < HTMLDivElement > ) : Promise < void > => {
128+ event . preventDefault ( )
129+ setDragActive ( false )
130+ setLoading ( true )
131+ console . log ( 'App Dropped' )
132+
133+ const files = Array . from ( event . dataTransfer . files )
134+ for ( const file of files ) {
135+ if ( file . name . endsWith ( '.zip' ) ) {
136+ await handleZipFile ( file . path )
137+ }
138+ }
139+ }
140+ async function handleZipFile ( zipFilePath : string ) : Promise < void > {
141+ try {
142+ // Notify the main process to handle the zip file
143+ window . electron . ipcRenderer . send ( 'handle-zip' , zipFilePath )
144+ handleLogging ( )
145+ window . electron . ipcRenderer . once ( 'zip-name' , ( _event , response : responseData ) => {
146+ console . log ( 'Received appId:' , response )
147+ if ( response . status ) {
148+ setAppData ( response . data )
149+ }
150+ setLoading ( false )
151+ } )
152+ } catch ( error ) {
153+ console . error ( 'Error handling zip file:' , error )
154+ }
155+ }
156+
157+ const handleClick = async ( ) : Promise < void > => {
158+ const file = await window . electron . selectZipFile ( )
159+ if ( file ) {
160+ setLoading ( true )
161+ await handleZipFile ( file . path )
162+ console . log ( file . name )
163+ }
164+ }
165+
125166 return (
126167 < div className = "pt-5 flex flex-col justify-around items-center" >
127168 { ! appData ?. appId ? (
@@ -161,6 +202,22 @@ const Web = (): JSX.Element => {
161202 ) : (
162203 < Loading message = { 'Fetching Releases' } />
163204 ) }
205+ { ! loading && (
206+ < div className = "w-full flex flex-col items-center justify-center mt-5" >
207+ < h1 className = "text-2xl font-semibold font-geist my-2" > Local Apps</ h1 >
208+ < div
209+ className = { `p-10 rounded-3xl flex flex-col items-center hover:bg-zinc-800 border-2 sm:w-30 md:w-96 md:text-2xl 2xl:w-auto 2xl:text-3xl border-zinc-200 transition-colors ${ dragActive ? 'drag-active' : '' } ` }
210+ onDrop = { handleDrop }
211+ onDragOver = { ( e ) => e . preventDefault ( ) }
212+ onDragEnter = { ( ) => setDragActive ( true ) }
213+ onDragLeave = { ( ) => setDragActive ( false ) }
214+ onClick = { handleClick }
215+ >
216+ < IconUpload iconSize = { 100 } />
217+ < p > Drop App.zip File Here</ p >
218+ </ div >
219+ </ div >
220+ ) }
164221 </ div >
165222 ) : (
166223 < RunPreppedApp appData = { appData } handleAddAndRunApp = { handleAddAndRunApp } />
0 commit comments