mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
cleanup tabs
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
|
||||
export const homeTabAtom = atomWithStorage<string>("home-tab", "recent");
|
||||
@@ -4,28 +4,22 @@ import RecentChanges from "@/components/common/recent-changes";
|
||||
import FavoritesPages from "./favorites-pages";
|
||||
import CreatedByMe from "./created-by-me";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const STORAGE_KEY = "home-tab";
|
||||
const DEFAULT_TAB = "recent";
|
||||
const VALID_TABS = ["recent", "favorites", "created"];
|
||||
|
||||
function getStoredTab(): string {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored && VALID_TABS.includes(stored) ? stored : DEFAULT_TAB;
|
||||
}
|
||||
import { useAtom } from "jotai";
|
||||
import { homeTabAtom } from "@/features/home/atoms/home-tab-atom";
|
||||
|
||||
export default function HomeTabs() {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useAtom(homeTabAtom);
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
color="dark"
|
||||
defaultValue={getStoredTab()}
|
||||
value={activeTab}
|
||||
onChange={(value) => {
|
||||
if (value) localStorage.setItem(STORAGE_KEY, value);
|
||||
if (value) setActiveTab(value);
|
||||
}}
|
||||
>
|
||||
<Tabs.List>
|
||||
<Tabs.List style={{ flexWrap: "nowrap", overflowX: "auto" }}>
|
||||
<Tabs.Tab value="recent" leftSection={<IconClockHour3 size={18} />}>
|
||||
<Text size="sm" fw={500}>
|
||||
{t("Recently updated")}
|
||||
|
||||
@@ -6,30 +6,24 @@ import CreatedByMe from "@/features/home/components/created-by-me";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const STORAGE_KEY = "space-home-tab";
|
||||
const DEFAULT_TAB = "recent";
|
||||
const VALID_TABS = ["recent", "favorites", "created"];
|
||||
|
||||
function getStoredTab(): string {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored && VALID_TABS.includes(stored) ? stored : DEFAULT_TAB;
|
||||
}
|
||||
import { useAtom } from "jotai";
|
||||
import { homeTabAtom } from "@/features/home/atoms/home-tab-atom";
|
||||
|
||||
export default function SpaceHomeTabs() {
|
||||
const { t } = useTranslation();
|
||||
const { spaceSlug } = useParams();
|
||||
const { data: space } = useGetSpaceBySlugQuery(spaceSlug);
|
||||
const [activeTab, setActiveTab] = useAtom(homeTabAtom);
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
color="dark"
|
||||
defaultValue={getStoredTab()}
|
||||
value={activeTab}
|
||||
onChange={(value) => {
|
||||
if (value) localStorage.setItem(STORAGE_KEY, value);
|
||||
if (value) setActiveTab(value);
|
||||
}}
|
||||
>
|
||||
<Tabs.List>
|
||||
<Tabs.List style={{ flexWrap: "nowrap", overflowX: "auto" }}>
|
||||
<Tabs.Tab value="recent" leftSection={<IconClockHour3 size={18} />}>
|
||||
<Text size="sm" fw={500}>
|
||||
{t("Recently updated")}
|
||||
|
||||
Reference in New Issue
Block a user