@@ -43,8 +43,10 @@ const TASKS = {
4343 - init: pip install -r requirements.txt
4444 command: python main.py` ,
4545 Other : `tasks:
46- - init: # TODO: install dependencies, build project
47- command: # TODO: start app`
46+ - init: |
47+ echo 'TODO: build project'
48+ command: |
49+ echo 'TODO: start app'`
4850}
4951
5052// const IMAGES = {
@@ -75,6 +77,7 @@ export default function () {
7577 const { isDark } = useContext ( ThemeContext ) ;
7678
7779 const [ showAuthBanner , setShowAuthBanner ] = useState < { host : string } | undefined > ( undefined ) ;
80+ const [ buttonNewWorkspaceEnabled , setButtonNewWorkspaceEnabled ] = useState < boolean > ( true ) ;
7881
7982 useEffect ( ( ) => {
8083 // Disable editing while loading, or when the config comes from Git.
@@ -164,11 +167,10 @@ export default function () {
164167 } ) ;
165168 } ;
166169
167- const buildProject = async ( event : React . MouseEvent ) => {
170+ const buildProject = async ( ) => {
168171 if ( ! project ) {
169172 return ;
170173 }
171- // (event.target as HTMLButtonElement).disabled = true;
172174 setEditorMessage ( null ) ;
173175 if ( ! ! startPrebuildResult ) {
174176 setStartPrebuildResult ( undefined ) ;
@@ -209,6 +211,26 @@ export default function () {
209211
210212 useEffect ( ( ) => { document . title = 'Configure Project — Gitpod' } , [ ] ) ;
211213
214+ const onNewWorkspace = async ( ) => {
215+ setButtonNewWorkspaceEnabled ( false ) ;
216+ const redirectToNewWorkspace = ( ) => {
217+ // instead of `history.push` we want forcibly to redirect here in order to avoid a following redirect from `/` -> `/projects` (cf. App.tsx)
218+ const url = new URL ( window . location . toString ( ) ) ;
219+ url . pathname = "/" ;
220+ url . hash = project ?. cloneUrl ! ;
221+ window . location . href = url . toString ( ) ;
222+ }
223+
224+ if ( prebuildInstance ?. status . phase === "stopped" && ! prebuildInstance ?. status . conditions . failed && ! prebuildInstance ?. status . conditions . headlessTaskFailed ) {
225+ redirectToNewWorkspace ( ) ;
226+ return ;
227+ }
228+ if ( ! prebuildWasTriggered ) {
229+ await buildProject ( ) ;
230+ }
231+ redirectToNewWorkspace ( ) ;
232+ }
233+
212234 return < >
213235 < Header title = "Configuration" subtitle = "View and edit project configuration." />
214236 < div className = "app-container mt-8 flex space-x-4" >
@@ -257,14 +279,12 @@ export default function () {
257279 < div className = "h-20 px-6 bg-gray-50 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-600 flex space-x-2" >
258280 { prebuildWasTriggered && < PrebuildInstanceStatus prebuildInstance = { prebuildInstance } /> }
259281 < div className = "flex-grow" />
260- { ( ( ! isDetecting && isEditorDisabled ) || ( prebuildInstance ?. status . phase === "stopped" && ! prebuildInstance ?. status . conditions . failed && ! prebuildInstance ?. status . conditions . headlessTaskFailed ) )
261- ? < a className = "my-auto" href = { `/#${ project ?. cloneUrl } ` } > < button className = "secondary" > New Workspace</ button > </ a >
262- : < button disabled = { true } className = "secondary" > New Workspace</ button > }
263282 { ( prebuildWasTriggered && prebuildInstance ?. status . phase !== "stopped" )
264283 ? < button className = "danger flex items-center space-x-2" disabled = { prebuildWasCancelled || ( prebuildInstance ?. status . phase !== "initializing" && prebuildInstance ?. status . phase !== "running" ) } onClick = { cancelPrebuild } >
265284 < span > Cancel Prebuild</ span >
266285 </ button >
267- : < button disabled = { isDetecting } onClick = { buildProject } > Run Prebuild</ button > }
286+ : < button disabled = { isDetecting } className = "secondary" onClick = { buildProject } > Run Prebuild</ button > }
287+ < button disabled = { isDetecting && buttonNewWorkspaceEnabled } onClick = { onNewWorkspace } > New Workspace</ button >
268288 </ div >
269289 </ div >
270290 </ div >
0 commit comments