Skip to content

Commit f69474f

Browse files
authored
feat(UI-1361): remember full screen between projects (#1089)
1 parent 0b91213 commit f69474f

File tree

7 files changed

+50
-46
lines changed

7 files changed

+50
-46
lines changed

src/components/organisms/deployments/sessions/table/table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { SessionStateType } from "@src/enums";
1313
import { useResize } from "@src/hooks";
1414
import { PopoverListItem } from "@src/interfaces/components/popover.interface";
1515
import { Session, SessionStateKeyType } from "@src/interfaces/models";
16-
import { useCacheStore, useModalStore, useProjectStore, useToastStore } from "@src/store";
16+
import { useCacheStore, useModalStore, useSharedBetweenProjectsStore, useToastStore } from "@src/store";
1717
import { SessionStatsFilterType } from "@src/types/components";
1818
import { calculateDeploymentSessionsStats, getShortId, initialSessionCounts } from "@src/utilities";
1919

@@ -52,13 +52,13 @@ export const SessionsTable = () => {
5252
const frameClass = "size-full bg-gray-1100 pb-3 pl-7 transition-all rounded-r-none";
5353
const filteredEntityId = deploymentId || projectId!;
5454
const [searchParams, setSearchParams] = useSearchParams();
55-
const { splitScreenRatio, setEditorWidth } = useProjectStore();
55+
const { splitScreenRatio, setEditorWidth } = useSharedBetweenProjectsStore();
5656
const [leftSideWidth] = useResize({
5757
direction: "horizontal",
5858
...defaultSplitFrameSize,
5959
initial: splitScreenRatio[projectId!]?.sessions || defaultSplitFrameSize.initial,
6060
id: resizeId,
61-
onChange: (width) => setEditorWidth({ sessions: width }),
61+
onChange: (width) => setEditorWidth(projectId!, { sessions: width }),
6262
});
6363

6464
const processStateFilter = (stateFilter?: string | null) => {

src/components/organisms/editorTabs.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,15 @@ import { Button, IconButton, IconSvg, Loader, Spinner, Tab, Typography } from "@
2424
import { AKRoundLogo } from "@assets/image";
2525
import { Close, CompressIcon, ExpandIcon, SaveIcon } from "@assets/image/icons";
2626

27-
export const EditorTabs = ({
28-
isExpanded,
29-
setExpanded,
30-
}: {
31-
isExpanded: boolean;
32-
setExpanded: (expandedState: boolean) => void;
33-
}) => {
34-
const { projectId } = useParams();
27+
export const EditorTabs = () => {
28+
const { projectId } = useParams() as { projectId: string };
3529
const { t: tErrors } = useTranslation("errors");
3630
const { t } = useTranslation("tabs", { keyPrefix: "editor" });
37-
const { closeOpenedFile, openFileAsActive, openFiles, saveFile } = useFileOperations(projectId!);
31+
const { closeOpenedFile, openFileAsActive, openFiles, saveFile } = useFileOperations(projectId);
3832
const { currentProjectId, fetchResources } = useCacheStore();
3933
const addToast = useToastStore((state) => state.addToast);
40-
const { cursorPositionPerProject, setCursorPosition } = useSharedBetweenProjectsStore();
34+
const { cursorPositionPerProject, setCursorPosition, fullScreenEditor, setFullScreenEditor } =
35+
useSharedBetweenProjectsStore();
4136
const activeEditorFileName =
4237
(projectId && openFiles[projectId]?.find(({ isActive }: { isActive: boolean }) => isActive)?.name) || "";
4338
const fileExtension = "." + last(activeEditorFileName.split("."));
@@ -197,7 +192,7 @@ export const EditorTabs = ({
197192
setIsFirstCursorPositionChange(false);
198193
return;
199194
}
200-
const cursorPosition = cursorPositionPerProject[projectId!]?.[activeEditorFileName];
195+
const cursorPosition = cursorPositionPerProject[projectId]?.[activeEditorFileName];
201196
const codeEditor = editorRef.current;
202197
if (!cursorPosition && codeEditor) {
203198
revealAndFocusOnLineInEditor(codeEditor, { lineNumber: 0, column: 0 });
@@ -288,21 +283,25 @@ export const EditorTabs = ({
288283
}, [debouncedManualSave]);
289284

290285
const activeCloseIcon = (fileName: string) => {
291-
const isActiveFile = openFiles[projectId!].find(({ isActive, name }) => name === fileName && isActive);
286+
const isActiveFile = openFiles[projectId].find(({ isActive, name }) => name === fileName && isActive);
292287

293288
return cn("size-4 p-0.5 opacity-0 hover:bg-gray-1100 group-hover:opacity-100", {
294289
"opacity-100": isActiveFile,
295290
});
296291
};
297292

293+
const toggleFullScreenEditor = () => {
294+
setFullScreenEditor(projectId, !fullScreenEditor[projectId]);
295+
};
296+
298297
const handleCloseButtonClick = (
299298
event: React.MouseEvent<HTMLButtonElement | HTMLDivElement, MouseEvent>,
300299
name: string
301300
): void => {
302301
event.stopPropagation();
303302
closeOpenedFile(name);
304-
if (!isExpanded || openFiles[projectId!]?.length !== 1) return;
305-
setExpanded(false);
303+
if (!fullScreenEditor[projectId] || openFiles[projectId]?.length !== 1) return;
304+
toggleFullScreenEditor();
306305
};
307306

308307
const isMarkdownFile = useMemo(() => activeEditorFileName.endsWith(".md"), [activeEditorFileName]);
@@ -387,8 +386,8 @@ export const EditorTabs = ({
387386
</Button>
388387
)}
389388
</div>
390-
<IconButton className="hover:bg-gray-1100" onClick={() => setExpanded(!isExpanded)}>
391-
{isExpanded ? (
389+
<IconButton className="hover:bg-gray-1100" onClick={toggleFullScreenEditor}>
390+
{fullScreenEditor[projectId] ? (
392391
<CompressIcon className="size-4 fill-white" />
393392
) : (
394393
<ExpandIcon className="size-4 fill-white" />

src/components/organisms/splitFrame.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { useId, useState } from "react";
1+
import React, { useId } from "react";
22

33
import { useParams } from "react-router-dom";
44

55
import { SplitFrameProps } from "@interfaces/components";
66
import { defaultSplitFrameSize } from "@src/constants";
7-
import { useProjectStore } from "@src/store";
7+
import { useSharedBetweenProjectsStore } from "@src/store";
88
import { cn } from "@utilities";
99

1010
import { useResize } from "@hooks";
@@ -14,17 +14,16 @@ import { EditorTabs } from "@components/organisms";
1414

1515
export const SplitFrame = ({ children }: SplitFrameProps) => {
1616
const resizeHorizontalId = useId();
17-
const { splitScreenRatio, setEditorWidth } = useProjectStore();
17+
const { splitScreenRatio, fullScreenEditor, setEditorWidth } = useSharedBetweenProjectsStore();
1818
const { projectId } = useParams();
1919
const [leftSideWidth] = useResize({
2020
direction: "horizontal",
2121
...defaultSplitFrameSize,
2222
initial: splitScreenRatio[projectId!]?.assets || defaultSplitFrameSize.initial,
2323
id: resizeHorizontalId,
24-
onChange: (width) => setEditorWidth({ assets: width }),
24+
onChange: (width) => setEditorWidth(projectId!, { assets: width }),
2525
});
26-
const [isExpanded, setIsExpanded] = useState(false);
27-
26+
const isExpanded = React.useMemo(() => fullScreenEditor[projectId!], [fullScreenEditor, projectId]);
2827
const rightFrameClass = cn(`h-full overflow-hidden rounded-l-none pb-0`, {
2928
"rounded-2xl": !children || isExpanded,
3029
});
@@ -47,7 +46,7 @@ export const SplitFrame = ({ children }: SplitFrameProps) => {
4746

4847
<div className="relative flex items-center overflow-hidden" style={{ width: `${rightSideWidth}%` }}>
4948
<Frame className={rightFrameClass}>
50-
<EditorTabs isExpanded={isExpanded} setExpanded={(expandedState) => setIsExpanded(expandedState)} />
49+
<EditorTabs />
5150
</Frame>
5251
</div>
5352
</div>

src/interfaces/store/projectStore.interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ export interface ProjectStore {
1919
latestOpened: LatestOpened;
2020
renameProject: (projectId: string, projectName: string) => void;
2121
isLoadingProjectsList: boolean;
22-
splitScreenRatio: Record<string, { assets: number; sessions: number }>;
2322
pendingFile?: File;
2423
setPendingFile: (file?: File) => void;
25-
setEditorWidth: ({ assets, sessions }: { assets?: number; sessions?: number }) => void;
2624
isExporting: boolean;
2725
setLatestOpened: (type: keyof Omit<LatestOpened, "projectId">, value: string, projectId?: string) => void;
2826
}

src/interfaces/store/sharedBetweenProjectsStore.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ export interface SharedBetweenProjectsStore {
77
[fileName: string]: EditorCodePosition;
88
};
99
};
10+
fullScreenEditor: { [projectId: string]: boolean };
11+
setFullScreenEditor: (projectId: string, value: boolean) => void;
12+
splitScreenRatio: Record<string, { assets: number; sessions: number }>;
13+
setEditorWidth: (projectId: string, { assets, sessions }: { assets?: number; sessions?: number }) => void;
1014
}

src/store/useProjectStore.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ const defaultState: Omit<
2323
| "deleteProject"
2424
| "exportProject"
2525
| "createProjectFromManifest"
26-
| "setEditorWidth"
2726
| "setPendingFile"
2827
| "setLatestOpened"
2928
> = {
3029
projectsList: [],
3130
isLoadingProjectsList: true,
32-
splitScreenRatio: {},
3331
currentProjectId: undefined,
3432
pendingFile: undefined,
3533
isExporting: false,
@@ -67,21 +65,6 @@ const store: StateCreator<ProjectStore> = (set, get) => ({
6765
});
6866
},
6967

70-
setEditorWidth: ({ assets, sessions }) => {
71-
const projectId = get().latestOpened.projectId;
72-
if (!projectId) return;
73-
74-
set(({ splitScreenRatio }) => ({
75-
splitScreenRatio: {
76-
...splitScreenRatio,
77-
[projectId]: {
78-
assets: assets || splitScreenRatio[projectId]?.assets,
79-
sessions: sessions || splitScreenRatio[projectId]?.sessions,
80-
},
81-
},
82-
}));
83-
},
84-
8568
setPendingFile: (file) => {
8669
set((state) => {
8770
state.pendingFile = file;

src/store/useSharedBetweenProjectsStore.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { immer } from "zustand/middleware/immer";
55
import { StoreName } from "@enums";
66
import { SharedBetweenProjectsStore } from "@interfaces/store";
77

8-
const defaultState: Omit<SharedBetweenProjectsStore, "setCursorPosition"> = {
8+
const defaultState: Omit<SharedBetweenProjectsStore, "setCursorPosition" | "setFullScreenEditor" | "setEditorWidth"> = {
99
cursorPositionPerProject: {},
10+
fullScreenEditor: {},
11+
splitScreenRatio: {},
1012
};
1113

1214
const store: StateCreator<SharedBetweenProjectsStore> = (set) => ({
@@ -21,6 +23,25 @@ const store: StateCreator<SharedBetweenProjectsStore> = (set) => ({
2123

2224
return state;
2325
}),
26+
27+
setFullScreenEditor: (projectId, value) =>
28+
set((state) => {
29+
state.fullScreenEditor[projectId] = value;
30+
31+
return state;
32+
}),
33+
34+
setEditorWidth: (projectId, { assets, sessions }) => {
35+
set(({ splitScreenRatio }) => ({
36+
splitScreenRatio: {
37+
...splitScreenRatio,
38+
[projectId]: {
39+
assets: assets || splitScreenRatio[projectId]?.assets,
40+
sessions: sessions || splitScreenRatio[projectId]?.sessions,
41+
},
42+
},
43+
}));
44+
},
2445
});
2546

2647
export const useSharedBetweenProjectsStore = create(

0 commit comments

Comments
 (0)