@@ -43,8 +43,8 @@ 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: echo ' TODO: build project'
47+ command: echo ' TODO: start app' `
4848}
4949
5050// const IMAGES = {
@@ -75,6 +75,7 @@ export default function () {
7575 const { isDark } = useContext ( ThemeContext ) ;
7676
7777 const [ showAuthBanner , setShowAuthBanner ] = useState < { host : string } | undefined > ( undefined ) ;
78+ const [ buttonNewWorkspaceEnabled , setButtonNewWorkspaceEnabled ] = useState < boolean > ( true ) ;
7879
7980 useEffect ( ( ) => {
8081 // Disable editing while loading, or when the config comes from Git.
@@ -164,11 +165,10 @@ export default function () {
164165 } ) ;
165166 } ;
166167
167- const buildProject = async ( event : React . MouseEvent ) => {
168+ const buildProject = async ( ) => {
168169 if ( ! project ) {
169170 return ;
170171 }
171- // (event.target as HTMLButtonElement).disabled = true;
172172 setEditorMessage ( null ) ;
173173 if ( ! ! startPrebuildResult ) {
174174 setStartPrebuildResult ( undefined ) ;
@@ -209,6 +209,26 @@ export default function () {
209209
210210 useEffect ( ( ) => { document . title = 'Configure Project — Gitpod' } , [ ] ) ;
211211
212+ const onNewWorkspace = async ( ) => {
213+ setButtonNewWorkspaceEnabled ( false ) ;
214+ const redirectToNewWorkspace = ( ) => {
215+ // instead of `history.push` we want forcibly to redirect here in order to avoid a following redirect from `/` -> `/projects` (cf. App.tsx)
216+ const url = new URL ( window . location . toString ( ) ) ;
217+ url . pathname = "/" ;
218+ url . hash = project ?. cloneUrl ! ;
219+ window . location . href = url . toString ( ) ;
220+ }
221+
222+ if ( prebuildInstance ?. status . phase === "stopped" && ! prebuildInstance ?. status . conditions . failed && ! prebuildInstance ?. status . conditions . headlessTaskFailed ) {
223+ redirectToNewWorkspace ( ) ;
224+ return ;
225+ }
226+ if ( ! prebuildWasTriggered ) {
227+ await buildProject ( ) ;
228+ }
229+ redirectToNewWorkspace ( ) ;
230+ }
231+
212232 return < >
213233 < Header title = "Configuration" subtitle = "View and edit project configuration." />
214234 < div className = "app-container mt-8 flex space-x-4" >
@@ -257,14 +277,12 @@ export default function () {
257277 < 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" >
258278 { prebuildWasTriggered && < PrebuildInstanceStatus prebuildInstance = { prebuildInstance } /> }
259279 < 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 > }
263280 { ( prebuildWasTriggered && prebuildInstance ?. status . phase !== "stopped" )
264281 ? < button className = "danger flex items-center space-x-2" disabled = { prebuildWasCancelled || ( prebuildInstance ?. status . phase !== "initializing" && prebuildInstance ?. status . phase !== "running" ) } onClick = { cancelPrebuild } >
265282 < span > Cancel Prebuild</ span >
266283 </ button >
267- : < button disabled = { isDetecting } onClick = { buildProject } > Run Prebuild</ button > }
284+ : < button disabled = { isDetecting } className = "secondary" onClick = { buildProject } > Run Prebuild</ button > }
285+ < button disabled = { isDetecting && buttonNewWorkspaceEnabled } onClick = { onNewWorkspace } > New Workspace</ button >
268286 </ div >
269287 </ div >
270288 </ div >
0 commit comments