From 59de4a7db01b378c26c605dfd12acfe553f5de21 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 30 Jul 2021 10:16:03 -0400 Subject: [PATCH] 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 --- app/components/Tab.js | 2 +- app/scenes/Home.js | 24 +++++++++++++++------- server/auth/index.js | 21 ++++++++++++++++--- shared/i18n/locales/en_US/translation.json | 2 ++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/components/Tab.js b/app/components/Tab.js index ece4546af..feb1c0df9 100644 --- a/app/components/Tab.js +++ b/app/components/Tab.js @@ -13,7 +13,7 @@ type Props = { const NavLinkWithChildrenFunc = ({ to, exact = false, children, ...rest }) => ( {({ match }) => ( - + {children(match)} )} diff --git a/app/scenes/Home.js b/app/scenes/Home.js index ff18fae48..26d1a3f3e 100644 --- a/app/scenes/Home.js +++ b/app/scenes/Home.js @@ -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() { {t("Home")} - {t("Recently updated")} + {t("Recently viewed")} - {t("Recently viewed")} + {t("Recently updated")} {t("Created by me")} {t("Weird, this shouldn’t ever be empty")}} showCollection /> @@ -63,13 +64,22 @@ function Home() { documents={documents.createdByUser(user)} fetch={documents.fetchOwned} options={{ user }} + empty={{t("Weird, this shouldn’t ever be empty")}} showCollection /> + {t( + "Documents you’ve recently viewed will be here for easy access" + )} + + } showCollection /> diff --git a/server/auth/index.js b/server/auth/index.js index b1064829c..11254b5fd 100644 --- a/server/auth/index.js +++ b/server/auth/index.js @@ -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()); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index fefcb0678..9a3494829 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -381,6 +381,8 @@ "Group members": "Group members", "Recently viewed": "Recently viewed", "Created by me": "Created by me", + "Weird, this shouldn’t ever be empty": "Weird, this shouldn’t ever be empty", + "Documents you’ve recently viewed will be here for easy access": "Documents you’ve 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.",