diff --git a/src/components/Header.tsx b/src/components/Header.tsx
index 59d0e4c..456c767 100644
--- a/src/components/Header.tsx
+++ b/src/components/Header.tsx
@@ -4,8 +4,6 @@ import { useOpenFiles } from "@/hooks/useOpenFiles"
export function Header() {
const { currentOpenFile } = useOpenFiles()
- const openFileName = currentOpenFile()
-
return (
@@ -14,7 +12,7 @@ export function Header() {
- {openFileName && `${openFileName.title} — `}fala-dev
+ {currentOpenFile && `${currentOpenFile.title} — `}fala-dev
diff --git a/src/components/OpenFilesTabs/CloseFileButton.tsx b/src/components/OpenFilesTabs/CloseFileButton.tsx
index a08686a..f724e70 100644
--- a/src/components/OpenFilesTabs/CloseFileButton.tsx
+++ b/src/components/OpenFilesTabs/CloseFileButton.tsx
@@ -30,10 +30,8 @@ export function CloseFileButton({ isActive, index }: CloseFileButtonProps) {
}
return (
- {
- e.preventDefault();
- e.stopPropagation();
+
+
)
}
diff --git a/src/components/OpenFilesTabs/index.tsx b/src/components/OpenFilesTabs/index.tsx
index 050c89d..7fdd9d1 100644
--- a/src/components/OpenFilesTabs/index.tsx
+++ b/src/components/OpenFilesTabs/index.tsx
@@ -16,11 +16,7 @@ export function OpenFilesTabs() {
const isActive = pathName === openFile;
const file = explorerFiles[openFile];
-
- if (!file) {
- return <>>;
- }
-
+
return (
void;
closeFile: (tabIndex: number) => void;
- currentOpenFile: () => FileType | null;
+ currentOpenFile: FileType | null;
};
const OpenFilesContext = createContext({} as OpenFilesContextProps);
@@ -16,12 +15,9 @@ const OpenFilesContext = createContext({} as OpenFilesContextProps);
export function OpenFilesProvider({ children }: { children: React.ReactNode }) {
const pathName = usePathname();
- const [openFiles, setOpenFiles] = useState
(() => {
- if (pathName) {
- const openTab = explorerFiles[pathName];
- if (openTab) {
- return [pathName];
- }
+ const [openFiles, setOpenFiles] = useState>(() => {
+ if (pathName && pathName !== '/') {
+ return [pathName];
}
return [];
@@ -32,7 +28,7 @@ export function OpenFilesProvider({ children }: { children: React.ReactNode }) {
return;
}
- setOpenFiles([...openFiles, file]);
+ setOpenFiles(state => [...state, file]);
};
const closeFile = (fileIndex: number) => {
@@ -40,13 +36,15 @@ export function OpenFilesProvider({ children }: { children: React.ReactNode }) {
setOpenFiles(newOpenFiles);
};
- const currentOpenFile = () => {
+ const currentOpenFile = useMemo(() => {
const openFileHref = openFiles.find((openFile) => pathName === openFile);
+
if (openFileHref) {
return explorerFiles[openFileHref];
}
+
return null;
- };
+ }, [openFiles, pathName])
return (