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 FavoritesPages from "./favorites-pages";
|
||||||
import CreatedByMe from "./created-by-me";
|
import CreatedByMe from "./created-by-me";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
const STORAGE_KEY = "home-tab";
|
import { homeTabAtom } from "@/features/home/atoms/home-tab-atom";
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function HomeTabs() {
|
export default function HomeTabs() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [activeTab, setActiveTab] = useAtom(homeTabAtom);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
color="dark"
|
color="dark"
|
||||||
defaultValue={getStoredTab()}
|
value={activeTab}
|
||||||
onChange={(value) => {
|
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} />}>
|
<Tabs.Tab value="recent" leftSection={<IconClockHour3 size={18} />}>
|
||||||
<Text size="sm" fw={500}>
|
<Text size="sm" fw={500}>
|
||||||
{t("Recently updated")}
|
{t("Recently updated")}
|
||||||
|
|||||||
@@ -6,30 +6,24 @@ import CreatedByMe from "@/features/home/components/created-by-me";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query";
|
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
const STORAGE_KEY = "space-home-tab";
|
import { homeTabAtom } from "@/features/home/atoms/home-tab-atom";
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function SpaceHomeTabs() {
|
export default function SpaceHomeTabs() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { spaceSlug } = useParams();
|
const { spaceSlug } = useParams();
|
||||||
const { data: space } = useGetSpaceBySlugQuery(spaceSlug);
|
const { data: space } = useGetSpaceBySlugQuery(spaceSlug);
|
||||||
|
const [activeTab, setActiveTab] = useAtom(homeTabAtom);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
color="dark"
|
color="dark"
|
||||||
defaultValue={getStoredTab()}
|
value={activeTab}
|
||||||
onChange={(value) => {
|
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} />}>
|
<Tabs.Tab value="recent" leftSection={<IconClockHour3 size={18} />}>
|
||||||
<Text size="sm" fw={500}>
|
<Text size="sm" fw={500}>
|
||||||
{t("Recently updated")}
|
{t("Recently updated")}
|
||||||
|
|||||||
Reference in New Issue
Block a user