diff --git a/apps/app/hooks/use-local-storage.tsx b/apps/app/hooks/use-local-storage.tsx index f6439ec1b..0eb7e20f3 100644 --- a/apps/app/hooks/use-local-storage.tsx +++ b/apps/app/hooks/use-local-storage.tsx @@ -1,6 +1,7 @@ import { useState, useEffect, useCallback } from "react"; const getValueFromLocalStorage = (key: string, defaultValue: any) => { + if (typeof window === undefined || typeof window === "undefined") return defaultValue; try { const item = window.localStorage.getItem(key); return item ? JSON.parse(item) : defaultValue; diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/index.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/index.tsx index 4068e3be7..73f9b0aa1 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/index.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/index.tsx @@ -14,6 +14,7 @@ import projectService from "services/project.service"; import pagesService from "services/pages.service"; // hooks import useToast from "hooks/use-toast"; +import useLocalStorage from "hooks/use-local-storage"; // icons import { PlusIcon } from "components/icons"; // layouts @@ -74,6 +75,8 @@ const ProjectPages: NextPage = () => { const { setToastAlert } = useToast(); + const { storedValue: pageTab, setValue: setPageTab } = useLocalStorage("pageTab", "Recent"); + const { handleSubmit, register, @@ -145,6 +148,25 @@ const ProjectPages: NextPage = () => { }); }; + + const currentTabValue = (tab: string | null) => { + switch (tab) { + case "Recent": + return 0; + case "All": + return 1; + case "Favorites": + return 2; + case "Created by me": + return 3; + case "Created by others": + return 4; + + default: + return 0; + } + }; + return ( <> { )}
- + { + switch (i) { + case 0: + return setPageTab("Recent"); + case 1: + return setPageTab("All"); + case 2: + return setPageTab("Favorites"); + case 3: + return setPageTab("Created by me"); + case 4: + return setPageTab("Created by others"); + + default: + return setPageTab("Recent"); + } + }} + >
{["Recent", "All", "Favorites", "Created by me", "Created by others"].map(