diff --git a/app/scenes/Home.tsx b/app/scenes/Home.tsx index bdf7ba220c..496546e65e 100644 --- a/app/scenes/Home.tsx +++ b/app/scenes/Home.tsx @@ -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( + "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 = ( + + {t("Documents you’ve recently viewed will be here for easy access")} + + } + showCollection + /> + ); return ( - - - {t("Recently viewed")} - - - {t("Popular")} - - - {t("Recently updated")} - - {t("Created by me")} - + {!redirectTo && ( + + setHomeTab(HomeTab.Viewed)}> + {t("Recently viewed")} + + setHomeTab(HomeTab.Popular)} + > + {t("Popular")} + + setHomeTab(HomeTab.Updated)} + > + {t("Recently updated")} + + setHomeTab(HomeTab.Created)}> + {t("Created by me")} + + + )} + + {redirectTo ? : recentlyViewed} + - - - {t( - "Documents you’ve recently viewed will be here for easy access" - )} - - } - showCollection - /> - + {recentlyViewed} diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index f14b5323ba..d887fd8996 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -986,11 +986,11 @@ "Warning Sign": "Warning Sign", "A workspace admin ({{ suspendedContactEmail }}) has suspended your account. To re-activate your account, please reach out to them directly.": "A workspace admin ({{ suspendedContactEmail }}) 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",