11import { useState } from "react" ;
2- import { v4 as uuidv4 } from ' uuid' ;
2+ import { v4 as uuidv4 } from " uuid" ;
33import { Layout , Typography } from "antd" ;
44import { getJobStatus , addRecipe } from "./utils/firebase" ;
55import { getFirebaseRecipe , jsonToString } from "./utils/recipeLoader" ;
@@ -8,11 +8,10 @@ import { FIRESTORE_FIELDS } from "./constants/firebase";
88import { SIMULARIUM_EMBED_URL } from "./constants/urls" ;
99import PackingInput from "./components/PackingInput" ;
1010import Viewer from "./components/Viewer" ;
11- import ErrorLogs from "./components/ErrorLogs" ;
1211import StatusBar from "./components/StatusBar" ;
1312import "./App.css" ;
1413
15- const { Header, Content } = Layout ;
14+ const { Header, Content, Sider , Footer } = Layout ;
1615const { Link } = Typography ;
1716
1817function App ( ) {
@@ -29,12 +28,27 @@ function App() {
2928 return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
3029 }
3130
32- const recipeHasChanged = async ( recipeId : string , recipeString : string ) : Promise < boolean > => {
31+ const resetState = ( ) => {
32+ setJobId ( "" ) ;
33+ setJobStatus ( "" ) ;
34+ setJobLogs ( "" ) ;
35+ setResultUrl ( "" ) ;
36+ setRunTime ( 0 ) ;
37+ } ;
38+
39+ const recipeHasChanged = async (
40+ recipeId : string ,
41+ recipeString : string
42+ ) : Promise < boolean > => {
3343 const originalRecipe = await getFirebaseRecipe ( recipeId ) ;
3444 return ! ( jsonToString ( originalRecipe ) == recipeString ) ;
35- }
45+ } ;
3646
37- const recipeToFirebase = ( recipe : string , path : string , id : string ) : object => {
47+ const recipeToFirebase = (
48+ recipe : string ,
49+ path : string ,
50+ id : string
51+ ) : object => {
3852 const recipeJson = JSON . parse ( recipe ) ;
3953 if ( recipeJson . bounding_box ) {
4054 const flattened_array = Object . assign ( { } , recipeJson . bounding_box ) ;
@@ -44,26 +58,37 @@ function App() {
4458 recipeJson [ FIRESTORE_FIELDS . NAME ] = id ;
4559 recipeJson [ FIRESTORE_FIELDS . TIMESTAMP ] = Date . now ( ) ;
4660 return recipeJson ;
47- }
61+ } ;
4862
49- const submitRecipe = async ( recipeId : string , configId : string , recipeString : string ) => {
50- setResultUrl ( "" ) ;
51- setRunTime ( 0 ) ;
63+ const submitRecipe = async (
64+ recipeId : string ,
65+ configId : string ,
66+ recipeString : string
67+ ) => {
68+ resetState ( ) ;
5269 let firebaseRecipe = "firebase:recipes/" + recipeId ;
53- const firebaseConfig = configId ? "firebase:configs/" + configId : undefined ;
54- const recipeChanged : boolean = await recipeHasChanged ( recipeId , recipeString ) ;
70+ const firebaseConfig = configId
71+ ? "firebase:configs/" + configId
72+ : undefined ;
73+ const recipeChanged : boolean = await recipeHasChanged (
74+ recipeId ,
75+ recipeString
76+ ) ;
5577 if ( recipeChanged ) {
5678 const recipeId = uuidv4 ( ) ;
5779 firebaseRecipe = "firebase:recipes_edited/" + recipeId ;
58- const recipeJson = recipeToFirebase ( recipeString , firebaseRecipe , recipeId ) ;
80+ const recipeJson = recipeToFirebase (
81+ recipeString ,
82+ firebaseRecipe ,
83+ recipeId
84+ ) ;
5985 try {
6086 await addRecipe ( recipeId , recipeJson ) ;
6187 } catch ( e ) {
6288 setJobStatus ( JOB_STATUS . FAILED ) ;
6389 setJobLogs ( String ( e ) ) ;
6490 return ;
6591 }
66-
6792 }
6893 const url = getSubmitPackingUrl ( firebaseRecipe , firebaseConfig ) ;
6994 const request : RequestInfo = new Request ( url , { method : "POST" } ) ;
@@ -81,18 +106,29 @@ function App() {
81106 }
82107 } ;
83108
84- const startPacking = async ( recipeId : string , configId : string , recipeString : string ) => {
85- await submitRecipe ( recipeId , configId , recipeString )
86- . then ( ( jobIdFromSubmit ) => checkStatus ( jobIdFromSubmit ) ) ;
87- }
109+ const startPacking = async (
110+ recipeId : string ,
111+ configId : string ,
112+ recipeString : string
113+ ) => {
114+ await submitRecipe ( recipeId , configId , recipeString ) . then (
115+ ( jobIdFromSubmit ) => checkStatus ( jobIdFromSubmit )
116+ ) ;
117+ } ;
88118
89119 const checkStatus = async ( jobIdFromSubmit : string ) => {
90120 const id = jobIdFromSubmit || jobId ;
91121 let localJobStatus = await getJobStatus ( id ) ;
92- while ( localJobStatus ?. status !== JOB_STATUS . DONE && localJobStatus ?. status !== JOB_STATUS . FAILED ) {
122+ while (
123+ localJobStatus ?. status !== JOB_STATUS . DONE &&
124+ localJobStatus ?. status !== JOB_STATUS . FAILED
125+ ) {
93126 await sleep ( 500 ) ;
94127 const newJobStatus = await getJobStatus ( id ) ;
95- if ( newJobStatus && localJobStatus ?. status !== newJobStatus . status ) {
128+ if (
129+ newJobStatus &&
130+ localJobStatus ?. status !== newJobStatus . status
131+ ) {
96132 localJobStatus = newJobStatus ;
97133 setJobStatus ( newJobStatus . status ) ;
98134 }
@@ -107,22 +143,39 @@ function App() {
107143 }
108144 } ;
109145
110- const showLogs = jobStatus == JOB_STATUS . FAILED ;
111-
112146 return (
113- < div className = "app-container" >
114- < Header className = "header" style = { { justifyContent : "space-between" } } >
147+ < Layout className = "app-container" >
148+ < Header
149+ className = "header"
150+ style = { { justifyContent : "space-between" } }
151+ >
115152 < h2 className = "header-title" > cellPACK demo</ h2 >
116- < Link href = "https://github.com/mesoscope/cellpack" className = "header-link" > GitHub</ Link >
153+ < Link
154+ href = "https://github.com/mesoscope/cellpack"
155+ className = "header-link"
156+ >
157+ GitHub
158+ </ Link >
117159 </ Header >
118- < Content className = "content-container" >
119- < PackingInput startPacking = { startPacking } />
120- { jobStatus && < StatusBar jobStatus = { jobStatus } runTime = { runTime } jobId = { jobId } outputDir = { outputDir } /> }
121- { showLogs && < ErrorLogs errorLogs = { jobLogs } /> }
122- </ Content >
123- { resultUrl && < Viewer resultUrl = { resultUrl } /> }
124- </ div >
160+ < Layout >
161+ < Sider width = "35%" theme = "light" className = "sider" >
162+ < PackingInput startPacking = { startPacking } />
163+ </ Sider >
164+ < Content className = "content-container" >
165+ < Viewer resultUrl = { resultUrl } />
166+ </ Content >
167+ </ Layout >
168+ < Footer className = "footer" >
169+ < StatusBar
170+ jobStatus = { jobStatus }
171+ runTime = { runTime }
172+ jobId = { jobId }
173+ errorLogs = { jobLogs }
174+ outputDir = { outputDir }
175+ />
176+ </ Footer >
177+ </ Layout >
125178 ) ;
126179}
127180
128- export default App ;
181+ export default App ;
0 commit comments