99 DragTabList ,
1010 DragTab ,
1111 PanelList ,
12- Panel
12+ Panel ,
13+ TabListComponent
1314} from "@root/tabtab/index.js" ;
1415import { arrayMoveImmutable as simpleSwitch } from "array-move" ;
1516import { subscribeToProjectLastModified } from "@comp/project-last-modified/subscribers" ;
@@ -31,15 +32,14 @@ import {
3132 storeEditorKeyboardCallbacks ,
3233 storeProjectEditorKeyboardCallbacks
3334} from "@comp/hot-keys/actions" ;
34- import { pathOr , propOr } from "ramda" ;
3535import { find , isEmpty } from "lodash" ;
3636import {
3737 rearrangeTabs ,
3838 tabClose ,
3939 tabSwitch ,
4040 setManualPanelOpen
4141} from "./actions" ;
42- import { mapIndexed , isMobile } from "@root/utils" ;
42+ import { isMobile } from "@root/utils" ;
4343import * as SS from "./styles" ;
4444import BottomTabs from "@comp/bottom-tabs/component" ;
4545import MobileTabs from "@comp/bottom-tabs/mobile-tabs" ;
@@ -79,10 +79,10 @@ const MySplit = ({
7979 onDragStarted : ( ) => void ;
8080 onDragFinished : ( ) => void ;
8181 children : React . ReactNode [ ] ;
82- } ) => {
82+ } ) : React . ReactElement => {
8383 const filteredChildren = children . filter ( Boolean ) ;
8484 return filteredChildren . length === 1 ? (
85- filteredChildren [ 0 ]
85+ ( filteredChildren [ 0 ] as React . ReactElement )
8686 ) : (
8787 < SplitPane
8888 primary = { primary }
@@ -183,13 +183,9 @@ const ProjectEditor = ({
183183 // resizing the manual panel.
184184 const [ isDragging , setIsDragging ] = useState ( false ) ;
185185
186- const projectUid : string = propOr ( "" , "projectUid" , activeProject ) ;
187- const projectOwnerUid : string = propOr ( "" , "userUid" , activeProject ) ;
188- const projectName : string = propOr (
189- "Undefined Project" ,
190- "name" ,
191- activeProject
192- ) ;
186+ const projectUid : string = activeProject ?. projectUid ?? "" ;
187+ const projectOwnerUid : string = activeProject ?. userUid ?? "" ;
188+ const projectName : string = activeProject ?. name ?? "Undefined Project" ;
193189 const isOwner : boolean = useSelector ( selectIsOwner ) ;
194190
195191 useEffect ( ( ) => {
@@ -231,15 +227,14 @@ const ProjectEditor = ({
231227 } , [ dispatch , isOwner , projectOwnerUid , projectUid ] ) ;
232228
233229 const tabDockDocuments : IOpenDocument [ ] = useSelector (
234- pathOr ( [ ] as IOpenDocument [ ] , [
235- "ProjectEditorReducer" ,
236- "tabDock" ,
237- "openDocuments"
238- ] )
230+ ( store : RootState ) =>
231+ store . ProjectEditorReducer ?. tabDock ?. openDocuments ??
232+ ( [ ] as IOpenDocument [ ] )
239233 ) ;
240234
241235 const tabIndex : number = useSelector (
242- pathOr ( - 1 , [ "ProjectEditorReducer" , "tabDock" , "tabIndex" ] )
236+ ( store : RootState ) =>
237+ store . ProjectEditorReducer ?. tabDock ?. tabIndex ?? - 1
243238 ) ;
244239
245240 const openDocuments : AnyTab [ ] = tabDockDocuments . reduce (
@@ -248,9 +243,9 @@ const ProjectEditor = ({
248243 const isNonCloudFile = tabDocument . isNonCloudDocument || false ;
249244
250245 return isNonCloudFile
251- ? [ tabDocument , ...accumulator ]
246+ ? [ ...accumulator , tabDocument ]
252247 : maybeDocument && Object . keys ( maybeDocument ) . length > 0
253- ? [ maybeDocument , ...accumulator ]
248+ ? [ ...accumulator , maybeDocument ]
254249 : accumulator ;
255250 } ,
256251 [ ] as AnyTab [ ]
@@ -260,7 +255,12 @@ const ProjectEditor = ({
260255 dispatch ( tabClose ( projectUid , documentUid , isModified ) ) ;
261256 } ;
262257
263- const openTabList = mapIndexed ( ( document : any , index ) => {
258+ const switchTab = ( index : number ) => {
259+ localStorage . setItem ( projectUid + ":tabIndex" , `${ index } ` ) ;
260+ dispatch ( tabSwitch ( index ) ) ;
261+ } ;
262+
263+ const openTabList = openDocuments . map ( ( document : any , index ) => {
264264 const isModified : boolean = document . isModifiedLocally ;
265265 return (
266266 < DragTab
@@ -272,6 +272,10 @@ const ProjectEditor = ({
272272 }
273273 currentIndex = { tabIndex }
274274 thisIndex = { index }
275+ CustomTabStyle = { TabStyles . Tab }
276+ handleTabChange = { switchTab }
277+ index = { index }
278+ active = { index === tabIndex }
275279 >
276280 < p style = { { margin : 0 } } >
277281 { document
@@ -283,23 +287,16 @@ const ProjectEditor = ({
283287 ) ;
284288 } , openDocuments as IDocument [ ] ) ;
285289
286- const openTabPanels = mapIndexed (
287- ( document_ : any , index : number ) => (
288- < Panel key = { index } >
289- < EditorForDocument
290- uid = { activeProject . userUid }
291- projectUid = { projectUid }
292- isOwner = { isOwner }
293- doc = { document_ }
294- />
295- </ Panel >
296- ) ,
297- openDocuments
298- ) ;
299- const switchTab = ( index : number ) => {
300- localStorage . setItem ( projectUid + ":tabIndex" , `${ index } ` ) ;
301- dispatch ( tabSwitch ( index ) ) ;
302- } ;
290+ const openTabPanels = openDocuments . map ( ( document_ : any , index : number ) => (
291+ < Panel key = { index } >
292+ < EditorForDocument
293+ uid = { activeProject . userUid }
294+ projectUid = { projectUid }
295+ isOwner = { isOwner }
296+ doc = { document_ }
297+ />
298+ </ Panel >
299+ ) ) ;
303300
304301 const someUnsavedData : boolean = isOwner
305302 ? ! ! find (
@@ -319,7 +316,7 @@ const ProjectEditor = ({
319316 const tabDock : React . ReactElement = isEmpty ( openDocuments ) ? (
320317 < div key = "0" style = { { position : "relative" } } />
321318 ) : (
322- < div key = "1" css = { tabListStyle } >
319+ < div key = "1" css = { tabListStyle as any } >
323320 < Tabs
324321 defaultIndex = { Math . min ( tabIndex , tabDockDocuments . length - 1 ) }
325322 activeIndex = { Math . min ( tabIndex , tabDockDocuments . length - 1 ) }
@@ -343,7 +340,31 @@ const ProjectEditor = ({
343340 ) ;
344341 } }
345342 >
346- < DragTabList items = { openTabList } />
343+ < DragTabList
344+ id = "drag-tab-list"
345+ handleTabSequence = { ( {
346+ oldIndex,
347+ newIndex
348+ } : {
349+ oldIndex : number ;
350+ newIndex : number ;
351+ } ) => {
352+ dispatch (
353+ rearrangeTabs (
354+ projectUid ,
355+ simpleSwitch (
356+ tabDockDocuments ,
357+ oldIndex ,
358+ newIndex
359+ ) ,
360+ newIndex
361+ )
362+ ) ;
363+ } }
364+ handleTabChange = { switchTab }
365+ >
366+ { openTabList }
367+ </ DragTabList >
347368 < PanelList > { openTabPanels } </ PanelList >
348369 </ Tabs >
349370 </ div >
0 commit comments