File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
site/src/pages/WorkspacePage Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { useMachine } from "@xstate/react"
3
3
import { AlertBanner } from "components/AlertBanner/AlertBanner"
4
4
import { ChooseOne , Cond } from "components/Conditionals/ChooseOne"
5
5
import { FC , useEffect } from "react"
6
- import { useParams } from "react-router-dom"
6
+ import { useLocation , useParams } from "react-router-dom"
7
7
import { Loader } from "components/Loader/Loader"
8
8
import { firstOrItem } from "util/array"
9
9
import { workspaceMachine } from "xServices/workspace/workspaceXService"
@@ -15,6 +15,7 @@ export const WorkspacePage: FC = () => {
15
15
useParams ( )
16
16
const username = firstOrItem ( usernameQueryParam , null )
17
17
const workspaceName = firstOrItem ( workspaceQueryParam , null )
18
+ const shouldRestartWorkspace = useLocation ( ) . state ?. shouldRestartWorkspace ?? false
18
19
const [ workspaceState , workspaceSend ] = useMachine ( workspaceMachine )
19
20
const {
20
21
workspace,
@@ -69,6 +70,7 @@ export const WorkspacePage: FC = () => {
69
70
workspaceState = { workspaceState }
70
71
quotaState = { quotaState }
71
72
workspaceSend = { workspaceSend }
73
+ shouldRestartWorkspace = { shouldRestartWorkspace }
72
74
/>
73
75
</ Cond >
74
76
< Cond >
Original file line number Diff line number Diff line change @@ -30,12 +30,14 @@ interface WorkspaceReadyPageProps {
30
30
workspaceState : StateFrom < typeof workspaceMachine >
31
31
quotaState : StateFrom < typeof quotaMachine >
32
32
workspaceSend : ( event : WorkspaceEvent ) => void
33
+ shouldRestartWorkspace : boolean
33
34
}
34
35
35
36
export const WorkspaceReadyPage = ( {
36
37
workspaceState,
37
38
quotaState,
38
39
workspaceSend,
40
+ shouldRestartWorkspace
39
41
} : WorkspaceReadyPageProps ) : JSX . Element => {
40
42
const [ bannerState , bannerSend ] = useActor (
41
43
workspaceState . children [ "scheduleBannerMachine" ] ,
@@ -71,6 +73,13 @@ export const WorkspaceReadyPage = ({
71
73
bannerSend ( { type : "REFRESH_WORKSPACE" , workspace } )
72
74
} , [ bannerSend , workspace ] )
73
75
76
+ useEffect ( ( ) => {
77
+ // workspaces can be started without being stopped first
78
+ shouldRestartWorkspace && workspaceSend ( { type : "START" } )
79
+ // clear location state
80
+ window . history . replaceState ( { } , document . title )
81
+ } , [ shouldRestartWorkspace , workspaceSend ] )
82
+
74
83
return (
75
84
< >
76
85
< Helmet >
You can’t perform that action at this time.
0 commit comments