Skip to content

Commit

Permalink
fix(ProjectsPage): show only first level projects
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Jun 27, 2023
1 parent a12a059 commit e1733bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export const PageHeader: FC = () => {
href: routes.goals(),
title: tr('Goals'),
},
{
href: routes.exploreTopProjects(),
title: tr('Explore'),
},
{
href: routes.projects(),
title: tr('Projects'),
},
{
href: routes.exploreTopProjects(),
title: tr('Explore'),
},
];

const onUserMenuClick = useCallback(() => (user ? userSettings() : signIn()), [user, userSettings, signIn]);
Expand Down
4 changes: 3 additions & 1 deletion src/components/ProjectsPage/ProjectsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const ProjectsPage = ({ user, ssrTime }: ExternalPageProps) => {
const [preview, setPreview] = useState<GoalByIdReturnType | null>(null);
const { toggleFilterStar } = useFilterResource();

const { data: projects = [] } = trpc.project.getAll.useQuery();
const { data: projects = [] } = trpc.project.getAll.useQuery({
firstLevel: true,
});

const utils = trpc.useContext();
const preset = trpc.filter.getById.useQuery(String(nextRouter.query.filter), {
Expand Down
37 changes: 27 additions & 10 deletions trpc/router/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,33 @@ export const project = router({
},
});
}),
getAll: protectedProcedure.query(({ ctx }) => {
return prisma.project
.findMany({
orderBy: {
createdAt: 'asc',
},
include: { ...projectFullSchema },
})
.then((res) => res.map((project) => addCalculatedProjectFields(project, ctx.session.user.activityId)));
}),
getAll: protectedProcedure
.input(
z
.object({
firstLevel: z.boolean().optional(),
})
.optional(),
)
.query(({ ctx, input: { firstLevel } = {} }) => {
return prisma.project
.findMany({
orderBy: {
createdAt: 'asc',
},
include: { ...projectFullSchema },
...(firstLevel
? {
where: {
parent: {
none: {},
},
},
}
: {}),
})
.then((res) => res.map((project) => addCalculatedProjectFields(project, ctx.session.user.activityId)));
}),
getTop: protectedProcedure.query(async ({ ctx }) => {
const allProjects = await prisma.project
.findMany({
Expand Down

0 comments on commit e1733bf

Please sign in to comment.