Skip to content

Commit f9b2bd7

Browse files
committed
feat: fix dragtabs rendering
1 parent 709cb05 commit f9b2bd7

5 files changed

Lines changed: 154 additions & 94 deletions

File tree

eslint.config.mjs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@ import tseslint from "typescript-eslint";
33
import globals from "globals";
44
import eslintPluginUnicorn from "eslint-plugin-unicorn";
55
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
6+
import eslintPluginReact from "eslint-plugin-react";
67

7-
export default tseslint.config(
8+
export default [
89
eslint.configs.recommended,
910
...tseslint.configs.recommended,
1011
{
12+
files: ["**/*.{js,jsx,ts,tsx}"],
1113
languageOptions: {
12-
globals: { ...globals.builtin, ...globals.browser }
14+
globals: {
15+
...globals.builtin,
16+
...globals.browser,
17+
React: "readonly"
18+
},
19+
parserOptions: {
20+
ecmaVersion: "latest",
21+
sourceType: "module",
22+
ecmaFeatures: {
23+
jsx: true
24+
}
25+
}
1326
},
1427
ignores: ["config/*", "scripts/*", "public/*", "*.test.tsx"],
15-
28+
settings: {
29+
react: {
30+
version: "detect"
31+
}
32+
},
1633
rules: {
1734
"@typescript-eslint/no-unused-vars": "off",
1835
"@typescript-eslint/no-explicit-any": "off",
@@ -24,11 +41,14 @@ export default tseslint.config(
2441
"unicorn/no-array-callback-reference": "off",
2542
"unicorn/no-useless-undefined": "off",
2643
"unicorn/prevent-abbreviations": "off",
27-
"unicorn/no-abusive-eslint-disable": "off"
44+
"unicorn/no-abusive-eslint-disable": "off",
45+
"react/react-in-jsx-scope": "off",
46+
"react/prop-types": "off"
2847
},
2948
plugins: {
3049
"react-hooks": eslintPluginReactHooks,
31-
unicorn: eslintPluginUnicorn
50+
unicorn: eslintPluginUnicorn,
51+
react: eslintPluginReact
3252
}
3353
}
34-
);
54+
];

src/components/bottom-tabs/component.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const BottomTabs = (): React.ReactElement => {
5151
);
5252

5353
const handleTabSequenceChange = useCallback(
54-
(oldIndex: number, newIndex: number) => {
54+
({ oldIndex, newIndex }: { oldIndex: number; newIndex: number }) => {
5555
if (openTabs) {
5656
const newOrder = simpleSwitch(openTabs, oldIndex, newIndex);
5757
dispatch(reorderBottomTabs(newOrder, newIndex));
@@ -60,6 +60,11 @@ const BottomTabs = (): React.ReactElement => {
6060
[dispatch, openTabs]
6161
);
6262

63+
const switchTab = useCallback(
64+
(newIndex: number) => dispatch(setBottomTabIndex(newIndex)),
65+
[dispatch]
66+
);
67+
6368
return (
6469
<div css={[SS.heightFix, tabListStyle]}>
6570
{!isEmpty(openTabs) && bottomTabIndex > -1 && (
@@ -74,8 +79,11 @@ const BottomTabs = (): React.ReactElement => {
7479
showArrowButton={"auto"}
7580
onTabSequenceChange={handleTabSequenceChange}
7681
>
77-
<DragTabList items={openTabs} />
78-
{/* {(openTabs || []).map((k, index) => (
82+
<DragTabList
83+
handleTabSequence={handleTabSequenceChange}
84+
handleTabChange={switchTab}
85+
>
86+
{(openTabs || []).map((k, index) => (
7987
<DragTab
8088
id={"drag-tab-" + index}
8189
key={index}
@@ -85,6 +93,10 @@ const BottomTabs = (): React.ReactElement => {
8593
}
8694
currentIndex={bottomTabIndex}
8795
thisIndex={index}
96+
CustomTabStyle={TabStyles.Tab}
97+
handleTabChange={switchTab}
98+
index={index}
99+
active={index === bottomTabIndex}
88100
>
89101
<p
90102
style={{
@@ -97,7 +109,7 @@ const BottomTabs = (): React.ReactElement => {
97109
</p>
98110
</DragTab>
99111
))}
100-
</DragTabList> */}
112+
</DragTabList>
101113

102114
<PanelList style={{ height: "100%", width: "100%" }}>
103115
{(openTabs || []).map((k, index) => {

src/components/project-editor/project-editor.tsx

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
DragTabList,
1010
DragTab,
1111
PanelList,
12-
Panel
12+
Panel,
13+
TabListComponent
1314
} from "@root/tabtab/index.js";
1415
import { arrayMoveImmutable as simpleSwitch } from "array-move";
1516
import { 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";
3535
import { find, isEmpty } from "lodash";
3636
import {
3737
rearrangeTabs,
3838
tabClose,
3939
tabSwitch,
4040
setManualPanelOpen
4141
} from "./actions";
42-
import { mapIndexed, isMobile } from "@root/utils";
42+
import { isMobile } from "@root/utils";
4343
import * as SS from "./styles";
4444
import BottomTabs from "@comp/bottom-tabs/component";
4545
import 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

Comments
 (0)