feat: Default to "recently viewed" (#2390)

* feat: Default user to first collection on first app open

* Default home tab to 'recently viewed'

* fix: Styling of inactive tab
This commit is contained in:
Tom Moor
2021-07-30 10:16:03 -04:00
committed by GitHub
parent 63eb8aadaf
commit 59de4a7db0
4 changed files with 38 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ type Props = {
const NavLinkWithChildrenFunc = ({ to, exact = false, children, ...rest }) => (
<Route path={to} exact={exact}>
{({ match }) => (
<NavLink to={to} {...rest}>
<NavLink to={to} exact={exact} {...rest}>
{children(match)}
</NavLink>
)}

View File

@@ -5,6 +5,7 @@ import * as React from "react";
import { useTranslation } from "react-i18next";
import { Switch, Route } from "react-router-dom";
import { Action } from "components/Actions";
import Empty from "components/Empty";
import Heading from "components/Heading";
import InputSearchPage from "components/InputSearchPage";
import LanguagePrompt from "components/LanguagePrompt";
@@ -41,19 +42,19 @@ function Home() {
<Heading>{t("Home")}</Heading>
<Tabs>
<Tab to="/home" exact>
{t("Recently updated")}
{t("Recently viewed")}
</Tab>
<Tab to="/home/recent" exact>
{t("Recently viewed")}
{t("Recently updated")}
</Tab>
<Tab to="/home/created">{t("Created by me")}</Tab>
</Tabs>
<Switch>
<Route path="/home/recent">
<PaginatedDocumentList
key="recent"
documents={documents.recentlyViewed}
fetch={documents.fetchRecentlyViewed}
documents={documents.recentlyUpdated}
fetch={documents.fetchRecentlyUpdated}
empty={<Empty>{t("Weird, this shouldnt ever be empty")}</Empty>}
showCollection
/>
</Route>
@@ -63,13 +64,22 @@ function Home() {
documents={documents.createdByUser(user)}
fetch={documents.fetchOwned}
options={{ user }}
empty={<Empty>{t("Weird, this shouldnt ever be empty")}</Empty>}
showCollection
/>
</Route>
<Route path="/home">
<PaginatedDocumentList
documents={documents.recentlyUpdated}
fetch={documents.fetchRecentlyUpdated}
key="recent"
documents={documents.recentlyViewed}
fetch={documents.fetchRecentlyViewed}
empty={
<Empty>
{t(
"Documents youve recently viewed will be here for easy access"
)}
</Empty>
}
showCollection
/>
</Route>

View File

@@ -8,7 +8,7 @@ import Router from "koa-router";
import { AuthenticationError } from "../errors";
import auth from "../middlewares/authentication";
import validation from "../middlewares/validation";
import { Team } from "../models";
import { Collection, Team, View } from "../models";
import providers from "./providers";
const log = debug("server");
@@ -41,8 +41,23 @@ router.get("/redirect", auth(), async (ctx) => {
expires: addMonths(new Date(), 3),
});
const team = await Team.findByPk(user.teamId);
ctx.redirect(`${team.url}/home`);
const [team, collection, view] = await Promise.all([
Team.findByPk(user.teamId),
Collection.findOne({
where: { teamId: user.teamId },
}),
View.findOne({
where: { userId: user.id },
}),
]);
const hasViewedDocuments = !!view;
ctx.redirect(
!hasViewedDocuments && collection
? `${team.url}${collection.url}`
: `${team.url}/home`
);
});
app.use(bodyParser());

View File

@@ -381,6 +381,8 @@
"Group members": "Group members",
"Recently viewed": "Recently viewed",
"Created by me": "Created by me",
"Weird, this shouldnt ever be empty": "Weird, this shouldnt ever be empty",
"Documents youve recently viewed will be here for easy access": "Documents youve recently viewed will be here for easy access",
"We sent out your invites!": "We sent out your invites!",
"Sorry, you can only send {{MAX_INVITES}} invites at a time": "Sorry, you can only send {{MAX_INVITES}} invites at a time",
"Invite team members or guests to join your knowledge base. Team members can sign in with {{signinMethods}} or use their email address.": "Invite team members or guests to join your knowledge base. Team members can sign in with {{signinMethods}} or use their email address.",