From 2b6c4e29ffb68a3c3962dc1cbe13cf8ca64b5b7a Mon Sep 17 00:00:00 2001 From: sleeplessghost Date: Sat, 21 Oct 2023 23:35:10 +1030 Subject: [PATCH] when removing the last tab, add a default new tab --- src/components/tabs/BoardsPage.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/tabs/BoardsPage.tsx b/src/components/tabs/BoardsPage.tsx index 927f6664..f341f8d4 100644 --- a/src/components/tabs/BoardsPage.tsx +++ b/src/components/tabs/BoardsPage.tsx @@ -15,7 +15,7 @@ import { TreeStateProvider } from "../common/TreeStateContext"; import Puzzles from "../puzzles/Puzzles"; import { BoardTab } from "./BoardTab"; import NewTabHome from "./NewTabHome"; -import { useCallback } from "react"; +import { useCallback, useEffect } from "react"; import { useAtom } from "jotai"; import { activeTabAtom, tabsAtom } from "@/atoms/atoms"; import ConfirmChangesModal from "./ConfirmChangesModal"; @@ -45,6 +45,16 @@ export default function BoardsPage() { const [activeTab, setActiveTab] = useAtom(activeTabAtom); const [saveModalOpened, toggleSaveModal] = useToggle(); + useEffect(() => { + if (tabs.length == 0) { + createTab({ + tab: { name: "New Tab", type: "new" }, + setTabs, + setActiveTab, + }); + } + }, [tabs]); + const closeTab = useCallback( async (value: string | null, forced?: boolean) => { if (value !== null) {