File tree Expand file tree Collapse file tree 3 files changed +57
-12
lines changed
packages/app/src/app/overmind Expand file tree Collapse file tree 3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import { getSandboxOptions } from '@codesandbox/common/lib/url';
2222import { Derive } from 'app/overmind' ;
2323import immer from 'immer' ;
2424
25+ import { ViewConfig } from '@codesandbox/common/lib/templates/template' ;
2526import { mainModule as getMainModule } from '../../utils/main-module' ;
2627import { parseConfigurations } from '../../utils/parse-configurations' ;
2728
@@ -35,7 +36,7 @@ type State = {
3536 } ;
3637 // TODO: What is this really? Could not find it in Cerebral, but
3738 // EditorPreview is using it... weird stuff
38- devToolTabs : Derive < State , any [ ] > ;
39+ devToolTabs : Derive < State , ViewConfig [ ] > ;
3940 isLoading : boolean ;
4041 notFound : boolean ;
4142 error : string | null ;
Original file line number Diff line number Diff line change 55 ServerPort ,
66} from '@codesandbox/common/lib/types' ;
77import { NotificationStatus } from '@codesandbox/notifications/lib/state' ;
8+ import { getDevToolsTabPosition } from 'app/overmind/utils/server' ;
89
910export const restartSandbox : Action = ( { effects } ) => {
1011 effects . executor . emit ( 'sandbox:restart' ) ;
@@ -192,17 +193,26 @@ export const onBrowserTabOpened: Action<{
192193
193194export const onBrowserFromPortOpened : Action < {
194195 port : ServerPort ;
195- } > = ( { actions } , { port } ) => {
196- actions . editor . onDevToolsTabAdded ( {
197- tab : port . main
198- ? { id : 'codesandbox.browser' }
199- : {
200- id : 'codesandbox.browser' ,
201- closeable : true ,
202- options : {
203- port : port . port ,
204- url : `https://${ port . hostname } ` ,
205- } ,
196+ } > = ( { actions, state } , { port } ) => {
197+ const tab = port . main
198+ ? { id : 'codesandbox.browser' }
199+ : {
200+ id : 'codesandbox.browser' ,
201+ closeable : true ,
202+ options : {
203+ port : port . port ,
204+ url : `https://${ port . hostname } ` ,
206205 } ,
206+ } ;
207+
208+ const position = getDevToolsTabPosition ( {
209+ tabs : state . editor . devToolTabs ,
210+ tab,
207211 } ) ;
212+
213+ if ( position ) {
214+ actions . editor . onDevToolsPositionChanged ( { position } ) ;
215+ } else {
216+ actions . editor . onDevToolsTabAdded ( { tab } ) ;
217+ }
208218} ;
Original file line number Diff line number Diff line change 1+ import {
2+ ViewConfig ,
3+ ViewTab ,
4+ } from '@codesandbox/common/lib/templates/template' ;
5+
6+ // eslint-disable-next-line consistent-return
7+ export function getDevToolsTabPosition ( {
8+ tabs,
9+ tab,
10+ } : {
11+ tabs : ViewConfig [ ] ;
12+ tab : ViewTab ;
13+ } ) :
14+ | {
15+ devToolIndex : number ;
16+ tabPosition : number ;
17+ }
18+ | undefined {
19+ const serializedTab = JSON . stringify ( tab ) ;
20+
21+ for ( let i = 0 ; i < tabs . length ; i ++ ) {
22+ const view = tabs [ i ] ;
23+
24+ for ( let j = 0 ; j < view . views . length ; j ++ ) {
25+ const tabFounded = view . views [ j ] ;
26+ if ( JSON . stringify ( tabFounded ) === serializedTab ) {
27+ return {
28+ devToolIndex : i ,
29+ tabPosition : j ,
30+ } ;
31+ }
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments