@@ -49,6 +49,42 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
4949
5050 const [ terminalHidden , setTerminalHidden ] = useState ( true ) ;
5151
52+ // Extract restart logic into a reusable function to follow DRY principles
53+ const handleRestartSandbox = async ( ) => {
54+ const activeBranch = branches . activeBranch ;
55+ if ( ! activeBranch ) return ;
56+
57+ try {
58+ const sandbox = branches . getSandboxById ( activeBranch . id ) ;
59+ if ( ! sandbox ?. session ) {
60+ toast . error ( 'Sandbox session not available' ) ;
61+ return ;
62+ }
63+
64+ const success = await sandbox . session . restartDevServer ( ) ;
65+ if ( success ) {
66+ // Refresh all webviews for the active branch
67+ const frames = editorEngine . frames . getAll ( ) ;
68+ frames . forEach ( frame => {
69+ try {
70+ editorEngine . frames . reloadView ( frame . frame . id ) ;
71+ } catch ( frameError ) {
72+ console . error ( 'Failed to reload frame:' , frame . frame . id , frameError ) ;
73+ }
74+ } ) ;
75+
76+ toast . success ( 'Sandbox restarted successfully' , {
77+ icon : < Icons . Cube className = "h-4 w-4" /> ,
78+ } ) ;
79+ } else {
80+ toast . error ( 'Failed to restart sandbox' ) ;
81+ }
82+ } catch ( error ) {
83+ console . error ( 'Error restarting sandbox:' , error ) ;
84+ toast . error ( 'An error occurred while restarting the sandbox' ) ;
85+ }
86+ } ;
87+
5288 return (
5389 < >
5490 { terminalHidden ? (
@@ -57,22 +93,7 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
5793 < Tooltip >
5894 < TooltipTrigger asChild >
5995 < button
60- onClick = { async ( ) => {
61- const activeBranch = branches . activeBranch ;
62- if ( activeBranch ) {
63- const sandbox = branches . getSandboxById ( activeBranch . id ) ;
64- if ( sandbox ?. session ) {
65- const success = await sandbox . session . restartDevServer ( ) ;
66- if ( success ) {
67- toast . success ( 'Sandbox restarted successfully' , {
68- icon : < Icons . Cube className = "h-4 w-4" /> ,
69- } ) ;
70- } else {
71- toast . error ( 'Failed to restart sandbox' ) ;
72- }
73- }
74- }
75- } }
96+ onClick = { handleRestartSandbox }
7697 disabled = { ! branches . activeBranch }
7798 className = { cn (
7899 "h-9 w-9 flex items-center justify-center rounded-md border border-transparent" ,
@@ -81,7 +102,7 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
81102 : "text-foreground-disabled cursor-not-allowed opacity-50"
82103 ) }
83104 >
84- < Icons . Reload className = "h-4 w-4" />
105+ < Icons . RestartSandbox className = "h-4 w-4" />
85106 </ button >
86107 </ TooltipTrigger >
87108 < TooltipContent sideOffset = { 5 } hideArrow > Restart Sandbox</ TooltipContent >
@@ -117,15 +138,7 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
117138 < Tooltip >
118139 < TooltipTrigger asChild >
119140 < button
120- onClick = { async ( ) => {
121- const activeBranch = branches . activeBranch ;
122- if ( activeBranch ) {
123- const sandbox = branches . getSandboxById ( activeBranch . id ) ;
124- if ( sandbox ?. session ) {
125- await sandbox . session . restartDevServer ( ) ;
126- }
127- }
128- } }
141+ onClick = { handleRestartSandbox }
129142 disabled = { ! branches . activeBranch }
130143 className = { cn (
131144 "h-9 w-9 flex items-center justify-center rounded-md border border-transparent" ,
@@ -134,7 +147,7 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
134147 : "text-foreground-disabled cursor-not-allowed opacity-50"
135148 ) }
136149 >
137- < Icons . Reload className = "h-4 w-4" />
150+ < Icons . RestartSandbox className = "h-4 w-4" />
138151 </ button >
139152 </ TooltipTrigger >
140153 < TooltipContent sideOffset = { 5 } hideArrow > Restart Sandbox</ TooltipContent >
0 commit comments