@@ -13,7 +16,12 @@ export function RootLayout() {
diff --git a/src/hooks/code-editor-sidebar/types.ts b/src/hooks/code-editor-sidebar/types.ts
index 88bf6711..61d6e4c9 100644
--- a/src/hooks/code-editor-sidebar/types.ts
+++ b/src/hooks/code-editor-sidebar/types.ts
@@ -7,6 +7,7 @@ export type CodeEditorDiffInfo = {
export type CodeEditorFile = {
name: string;
path: string;
+ projectName?: string;
diffInfo?: CodeEditorDiffInfo | null;
[key: string]: unknown;
-};
\ No newline at end of file
+};
diff --git a/src/hooks/code-editor-sidebar/useEditorSidebar.ts b/src/hooks/code-editor-sidebar/useEditorSidebar.ts
index 2c73c293..80897591 100644
--- a/src/hooks/code-editor-sidebar/useEditorSidebar.ts
+++ b/src/hooks/code-editor-sidebar/useEditorSidebar.ts
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from 'react';
-import type { MouseEvent as ReactMouseEvent } from 'react';
+import type { MouseEvent as ReactMouseEvent, MutableRefObject } from 'react';
import { CodeEditorFile, CodeEditorDiffInfo } from '@/hooks/code-editor-sidebar/types.js';
import { useDeviceSettings } from '@/hooks/useDeviceSettings.js';
@@ -8,6 +8,24 @@ type UseEditorSidebarOptions = {
initialWidth?: number;
};
+export type OpenEditorFileHandler = (
+ filePath: string,
+ diffInfo?: CodeEditorDiffInfo | null,
+ projectName?: string,
+) => void;
+
+export type UseEditorSidebarReturn = {
+ editingFile: CodeEditorFile | null;
+ editorWidth: number;
+ editorExpanded: boolean;
+ hasManualWidth: boolean;
+ resizeHandleRef: MutableRefObject
;
+ handleFileOpen: OpenEditorFileHandler;
+ handleCloseEditor: () => void;
+ handleToggleEditorExpand: () => void;
+ handleResizeStart: (event: ReactMouseEvent) => void;
+};
+
// TODO: Remove every parameter here (except initial width)
// selectedProject is only used to set projectName on the file being edited. It turns out that projectName
// isn't actually used anywhere in the code editor, so it can be removed without affecting functionality. If we do want to keep track of projectName for some reason, we can set it in the MainContent component where the file is opened instead of here.
@@ -15,7 +33,7 @@ type UseEditorSidebarOptions = {
//
export const useEditorSidebar = ({
initialWidth = 600,
-}: UseEditorSidebarOptions) => {
+}: UseEditorSidebarOptions): UseEditorSidebarReturn => {
const [editingFile, setEditingFile] = useState(null);
const [editorWidth, setEditorWidth] = useState(initialWidth);
const [editorExpanded, setEditorExpanded] = useState(false);
@@ -25,14 +43,15 @@ export const useEditorSidebar = ({
const { isMobile } = useDeviceSettings({ trackPWA: false });
- const handleFileOpen = useCallback(
- (filePath: string, diffInfo: CodeEditorDiffInfo | null = null) => {
+ const handleFileOpen = useCallback(
+ (filePath, diffInfo = null, projectName) => {
const normalizedPath = filePath.replace(/\\/g, '/');
const fileName = normalizedPath.split('/').pop() || filePath;
setEditingFile({
name: fileName,
path: filePath,
+ projectName,
diffInfo,
});
},
diff --git a/src/utils/api.js b/src/utils/api.js
index f563a66e..7ff31a7c 100644
--- a/src/utils/api.js
+++ b/src/utils/api.js
@@ -110,9 +110,9 @@ export const api = {
body: JSON.stringify(workspaceData),
}),
readFile: (projectName, filePath) =>
- authenticatedFetch(`/api/projects/${projectName}/file?filePath=${encodeURIComponent(filePath)}`),
+ authenticatedFetch(`/api/projects/${encodeURIComponent(projectName)}/file?filePath=${encodeURIComponent(filePath)}`),
saveFile: (projectName, filePath, content) =>
- authenticatedFetch(`/api/projects/${projectName}/file`, {
+ authenticatedFetch(`/api/projects/${encodeURIComponent(projectName)}/file`, {
method: 'PUT',
body: JSON.stringify({ filePath, content }),
}),