From c0660965959a4843f87bdcae5e7ed8480f16485d Mon Sep 17 00:00:00 2001 From: Goriany Igor Date: Mon, 15 Jul 2024 19:27:15 +0300 Subject: [PATCH] feat: add starred projects tab --- .../ExploreProjectsStarredPage.i18n/en.json | 3 ++ .../ExploreProjectsStarredPage.i18n/index.ts | 17 +++++++ .../ExploreProjectsStarredPage.i18n/ru.json | 3 ++ .../ExploreProjectsStarredPage.tsx | 45 +++++++++++++++++++ .../PageNavigation/PageNavigation.tsx | 4 ++ src/hooks/router.ts | 1 + .../{projects.tsx => projects/index.tsx} | 4 +- src/pages/explore/projects/starred.tsx | 13 ++++++ trpc/router/project.ts | 23 ++++++++++ 9 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/en.json create mode 100644 src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/index.ts create mode 100644 src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/ru.json create mode 100644 src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.tsx rename src/pages/explore/{projects.tsx => projects/index.tsx} (56%) create mode 100644 src/pages/explore/projects/starred.tsx diff --git a/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/en.json b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/en.json new file mode 100644 index 000000000..2386dbbde --- /dev/null +++ b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/en.json @@ -0,0 +1,3 @@ +{ + "title": "Taskany — Explore — Projects — Starred" +} diff --git a/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/index.ts b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/index.ts new file mode 100644 index 000000000..5c148475b --- /dev/null +++ b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/index.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ +// Do not edit, use generator to update +import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; +import getLang from '../../../utils/getLang'; + +import ru from './ru.json'; +import en from './en.json'; + +export type I18nKey = keyof typeof ru & keyof typeof en; +type I18nLang = 'ru' | 'en'; + +const keyset: I18nLangSet = {}; + +keyset['ru'] = ru; +keyset['en'] = en; + +export const tr = i18n(keyset, fmt, getLang); diff --git a/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/ru.json b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/ru.json new file mode 100644 index 000000000..568e5e9d4 --- /dev/null +++ b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.i18n/ru.json @@ -0,0 +1,3 @@ +{ + "title": "Taskany — Обзор — Проекты — Избранное" +} diff --git a/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.tsx b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.tsx new file mode 100644 index 000000000..5e7e483cf --- /dev/null +++ b/src/components/ExploreProjectsStarredPage/ExploreProjectsStarredPage.tsx @@ -0,0 +1,45 @@ +import { nullable } from '@taskany/bricks'; +import { Table, Link } from '@taskany/bricks/harmony'; +import NextLink from 'next/link'; + +import { ExternalPageProps } from '../../utils/declareSsrProps'; +import { routes } from '../../hooks/router'; +import { Page } from '../Page/Page'; +import { ExplorePageHeader } from '../ExplorePageHeader/ExplorePageHeader'; +import { ProjectListItem } from '../ProjectListItem/ProjectListItem'; +import { TableRowItem, TableRowItemTitle } from '../TableRowItem/TableRowItem'; +import { trpc } from '../../utils/trpcClient'; + +import { tr } from './ExploreProjectsStarredPage.i18n'; + +export const ExploreProjectsStarredPage = ({ user, ssrTime }: ExternalPageProps) => { + const { data } = trpc.project.getStarred.useQuery(); + + if (!data) return null; + + return ( + }> + + {data.map((project) => + nullable(project, (p) => ( + + + {p.title}}> + + + + + )), + )} +
+
+ ); +}; diff --git a/src/components/PageNavigation/PageNavigation.tsx b/src/components/PageNavigation/PageNavigation.tsx index b7d15e695..15542d9c1 100644 --- a/src/components/PageNavigation/PageNavigation.tsx +++ b/src/components/PageNavigation/PageNavigation.tsx @@ -69,6 +69,10 @@ export const PageNavigation: FC = ({ logo }) => { title: p.title, href: routes.project(p.id), })), + { + title: tr('Starred'), + href: routes.exploreProjectsStarred(), + }, { title: tr('All projects'), href: routes.exploreProjects(), diff --git a/src/hooks/router.ts b/src/hooks/router.ts index c8869f9d2..d6e5ffc9c 100644 --- a/src/hooks/router.ts +++ b/src/hooks/router.ts @@ -20,6 +20,7 @@ export const routes = { exploreProjects: () => '/explore/projects', exploreTopProjects: () => '/explore/top', + exploreProjectsStarred: () => '/explore/projects/starred', exploreGoals: () => '/explore/goals', help: (slug: AvailableHelpPages) => `/help/${slug}`, diff --git a/src/pages/explore/projects.tsx b/src/pages/explore/projects/index.tsx similarity index 56% rename from src/pages/explore/projects.tsx rename to src/pages/explore/projects/index.tsx index c63cdfd34..a3b2ac847 100644 --- a/src/pages/explore/projects.tsx +++ b/src/pages/explore/projects/index.tsx @@ -1,5 +1,5 @@ -import { ExploreProjectsPage } from '../../components/ExploreProjectsPage/ExploreProjectsPage'; -import { declareSsrProps } from '../../utils/declareSsrProps'; +import { ExploreProjectsPage } from '../../../components/ExploreProjectsPage/ExploreProjectsPage'; +import { declareSsrProps } from '../../../utils/declareSsrProps'; export const getServerSideProps = declareSsrProps( async ({ ssrHelpers }) => { diff --git a/src/pages/explore/projects/starred.tsx b/src/pages/explore/projects/starred.tsx new file mode 100644 index 000000000..8736d7e66 --- /dev/null +++ b/src/pages/explore/projects/starred.tsx @@ -0,0 +1,13 @@ +import { ExploreProjectsStarredPage } from '../../../components/ExploreProjectsStarredPage/ExploreProjectsStarredPage'; +import { declareSsrProps } from '../../../utils/declareSsrProps'; + +export const getServerSideProps = declareSsrProps( + async ({ ssrHelpers }) => { + await ssrHelpers.project.getStarred.fetch(); + }, + { + private: true, + }, +); + +export default ExploreProjectsStarredPage; diff --git a/trpc/router/project.ts b/trpc/router/project.ts index 8a7bc6e54..6aaf09aa9 100644 --- a/trpc/router/project.ts +++ b/trpc/router/project.ts @@ -422,6 +422,29 @@ export const project = router({ }) .then((res) => res.map((project) => addCalculatedProjectFields(project, activityId, role))); }), + getStarred: protectedProcedure.query(async ({ ctx }) => { + const { activityId, role } = ctx.session.user; + + const whereQuery = { + stargizers: { + some: { + id: activityId, + }, + }, + }; + return prisma.project + .findMany({ + orderBy: { + createdAt: 'asc', + }, + ...getProjectSchema({ + role, + activityId, + whereQuery, + }), + }) + .then((res) => res.map((project) => addCalculatedProjectFields(project, activityId, role))); + }), getById: protectedProcedure .input( z.object({