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

@@ -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());