mirror of
https://github.com/outline/outline.git
synced 2026-12-01 17:32:49 +03:00
feat: Remember last viewed tab on home (#13303)
This commit is contained in:
1 parent
58e62c9a42
commit
d18783c43f
2 files changed
+66
-29
No files matched your search
+65
-28
@@ -1,7 +1,7 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { HomeIcon } from "outline-icons";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Switch, Route } from "react-router-dom";
|
||||
import { Switch, Route, Redirect, useRouteMatch } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { Action } from "~/components/Actions";
|
||||
@@ -17,10 +17,18 @@ import { Tab, Tabs } from "~/components/Tabs";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import { usePinnedDocuments } from "~/hooks/usePinnedDocuments";
|
||||
import usePersistedState from "~/hooks/usePersistedState";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import NewDocumentMenu from "~/menus/NewDocumentMenu";
|
||||
|
||||
enum HomeTab {
|
||||
Viewed = "",
|
||||
Popular = "popular",
|
||||
Updated = "recent",
|
||||
Created = "created",
|
||||
}
|
||||
|
||||
function Home() {
|
||||
const { documents, ui } = useStores();
|
||||
const team = useCurrentTeam();
|
||||
@@ -29,6 +37,34 @@ function Home() {
|
||||
const userId = user?.id;
|
||||
const { pins, count } = usePinnedDocuments("home");
|
||||
const can = usePolicy(team);
|
||||
const [homeTab, setHomeTab] = usePersistedState<HomeTab>(
|
||||
"home-tab",
|
||||
HomeTab.Viewed,
|
||||
{
|
||||
listen: false,
|
||||
}
|
||||
);
|
||||
|
||||
// When landing on the index the last viewed tab is restored, the tabs are
|
||||
// hidden until the redirect resolves so that the active indicator does not
|
||||
// animate across from the first tab on mount.
|
||||
const isIndex = !!useRouteMatch({ path: "/home", exact: true });
|
||||
const redirectTo =
|
||||
isIndex && homeTab !== HomeTab.Viewed ? `/home/${homeTab}` : undefined;
|
||||
|
||||
const recentlyViewed = (
|
||||
<PaginatedDocumentList
|
||||
key="recent"
|
||||
documents={documents.recentlyViewed}
|
||||
fetch={documents.fetchRecentlyViewed}
|
||||
empty={
|
||||
<Empty>
|
||||
{t("Documents you’ve recently viewed will be here for easy access")}
|
||||
</Empty>
|
||||
}
|
||||
showCollection
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Scene
|
||||
@@ -54,19 +90,34 @@ function Home() {
|
||||
collapseKey="home"
|
||||
/>
|
||||
<Documents>
|
||||
<Tabs>
|
||||
<Tab to="/home" exact>
|
||||
{t("Recently viewed")}
|
||||
</Tab>
|
||||
<Tab to="/home/popular" exact>
|
||||
{t("Popular")}
|
||||
</Tab>
|
||||
<Tab to="/home/recent" exact>
|
||||
{t("Recently updated")}
|
||||
</Tab>
|
||||
<Tab to="/home/created">{t("Created by me")}</Tab>
|
||||
</Tabs>
|
||||
{!redirectTo && (
|
||||
<Tabs>
|
||||
<Tab to="/home" exact onClick={() => setHomeTab(HomeTab.Viewed)}>
|
||||
{t("Recently viewed")}
|
||||
</Tab>
|
||||
<Tab
|
||||
to="/home/popular"
|
||||
exact
|
||||
onClick={() => setHomeTab(HomeTab.Popular)}
|
||||
>
|
||||
{t("Popular")}
|
||||
</Tab>
|
||||
<Tab
|
||||
to="/home/recent"
|
||||
exact
|
||||
onClick={() => setHomeTab(HomeTab.Updated)}
|
||||
>
|
||||
{t("Recently updated")}
|
||||
</Tab>
|
||||
<Tab to="/home/created" onClick={() => setHomeTab(HomeTab.Created)}>
|
||||
{t("Created by me")}
|
||||
</Tab>
|
||||
</Tabs>
|
||||
)}
|
||||
<Switch>
|
||||
<Route path="/home" exact>
|
||||
{redirectTo ? <Redirect to={redirectTo} /> : recentlyViewed}
|
||||
</Route>
|
||||
<Route path="/home/recent">
|
||||
<PaginatedDocumentList
|
||||
documents={documents.recentlyUpdated}
|
||||
@@ -102,21 +153,7 @@ function Home() {
|
||||
showCollection
|
||||
/>
|
||||
</Route>
|
||||
<Route path="/home">
|
||||
<PaginatedDocumentList
|
||||
key="recent"
|
||||
documents={documents.recentlyViewed}
|
||||
fetch={documents.fetchRecentlyViewed}
|
||||
empty={
|
||||
<Empty>
|
||||
{t(
|
||||
"Documents you’ve recently viewed will be here for easy access"
|
||||
)}
|
||||
</Empty>
|
||||
}
|
||||
showCollection
|
||||
/>
|
||||
</Route>
|
||||
<Route path="/home">{recentlyViewed}</Route>
|
||||
</Switch>
|
||||
</Documents>
|
||||
</Scene>
|
||||
|
||||
@@ -986,11 +986,11 @@
|
||||
"Warning Sign": "Warning Sign",
|
||||
"A workspace admin (<em>{{ suspendedContactEmail }}</em>) has suspended your account. To re-activate your account, please reach out to them directly.": "A workspace admin (<em>{{ suspendedContactEmail }}</em>) has suspended your account. To re-activate your account, please reach out to them directly.",
|
||||
"Sorry, an unknown error occurred loading the page. Please try again or contact support if the issue persists.": "Sorry, an unknown error occurred loading the page. Please try again or contact support if the issue persists.",
|
||||
"Documents you’ve recently viewed will be here for easy access": "Documents you’ve recently viewed will be here for easy access",
|
||||
"Created by me": "Created by me",
|
||||
"Weird, this shouldn't ever be empty": "Weird, this shouldn't ever be empty",
|
||||
"Documents with recent activity will appear here": "Documents with recent activity will appear here",
|
||||
"You haven’t created any documents yet": "You haven’t created any documents yet",
|
||||
"Documents you’ve recently viewed will be here for easy access": "Documents you’ve recently viewed will be here for easy access",
|
||||
"{{ count }} invites sent": "{{ count }} invite sent",
|
||||
"{{ count }} invites sent_plural": "{{ count }} invites sent",
|
||||
"Those email addresses are already invited": "Those email addresses are already invited",
|
||||
|
||||
Reference in new issue
Block a user