From 1ac9b0afac11161d44279bf79d333ed3824bee8b Mon Sep 17 00:00:00 2001 From: dhrumit parmar Date: Fri, 19 Jul 2024 11:12:19 +0530 Subject: [PATCH] Chages done as per review --- app/discussions/layout.tsx | 4 +-- .../discussions/DiscussionLeaderboard.tsx | 8 ++--- components/discussions/GithubDiscussions.tsx | 30 +++++-------------- lib/discussion.ts | 10 +++---- lib/types.ts | 2 +- 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/app/discussions/layout.tsx b/app/discussions/layout.tsx index 7e118ccd..31e8b773 100644 --- a/app/discussions/layout.tsx +++ b/app/discussions/layout.tsx @@ -3,7 +3,7 @@ import { env } from "@/env.mjs"; import { notFound } from "next/navigation"; import { featureIsEnabled } from "@/lib/utils"; import FilterDiscussions from "../../components/discussions/FilterDiscussions"; -import { categoriesArray } from "../../lib/discussion"; +import { categories } from "../../lib/discussion"; import DiscussionLeaderboard from "../../components/discussions/DiscussionLeaderboard"; export const metadata: Metadata = { @@ -21,7 +21,7 @@ export default function DiscussionsLayout({

Disucssions

- +
{children} diff --git a/components/discussions/DiscussionLeaderboard.tsx b/components/discussions/DiscussionLeaderboard.tsx index 75d68708..ebbd3f91 100644 --- a/components/discussions/DiscussionLeaderboard.tsx +++ b/components/discussions/DiscussionLeaderboard.tsx @@ -13,10 +13,10 @@ export async function calculateContributor() { // If we have contributors then we will calculate the top contributors and save it in an array of objects {name, points, githubHandle} // points = 1 for each comment + 2 for creating a discussion + 5 discussion marked as helpful if (contributors) { - const contributorsArray: Contributor[] = []; + const uniqueContributors: Contributor[] = []; contributors.forEach((contributor) => { - const existingContributor = contributorsArray.find( + const existingContributor = uniqueContributors.find( (c) => c.name === contributor.name, ); @@ -29,7 +29,7 @@ export async function calculateContributor() { if (existingContributor) { existingContributor.points += points; } else { - contributorsArray.push({ + uniqueContributors.push({ name: contributor.name, points: points, githubHandle: contributor.slug, @@ -37,7 +37,7 @@ export async function calculateContributor() { } }); - return contributorsArray; + return uniqueContributors; } return []; diff --git a/components/discussions/GithubDiscussions.tsx b/components/discussions/GithubDiscussions.tsx index c599beb3..326b9113 100644 --- a/components/discussions/GithubDiscussions.tsx +++ b/components/discussions/GithubDiscussions.tsx @@ -9,33 +9,19 @@ interface Props { const GithubDiscussions = ({ discussions, searchParams }: Props) => { const category = searchParams?.category; - const dateRange = searchParams?.between; - const [start, end] = parseDateRangeSearchParam(dateRange, 30); + const [start, end] = parseDateRangeSearchParam(searchParams?.between, 30); - if (category && dateRange) { - discussions = discussions.filter( - (discussion) => - new Date(discussion.time) >= new Date(start) && - new Date(discussion.time) <= new Date(end) && - discussion.category?.name === category, - ); - } else if (category) { + discussions = discussions.filter( + (discussion) => + new Date(discussion.time) >= start && new Date(discussion.time) <= end, + ); + + if (category) { discussions = discussions.filter( (discussion) => discussion.category?.name === category, ); - } else if (dateRange) { - discussions = discussions.filter( - (discussion) => - new Date(discussion.time) >= new Date(start) && - new Date(discussion.time) <= new Date(end), - ); } - discussions = discussions.filter( - (discussion) => - new Date(discussion.time) >= new Date(start) && - new Date(discussion.time) <= new Date(end) && - (!category || discussion.category?.name === category), - ); + return (
{discussions.length > 0 ? ( diff --git a/lib/discussion.ts b/lib/discussion.ts index ad354005..8f2f4519 100644 --- a/lib/discussion.ts +++ b/lib/discussion.ts @@ -13,7 +13,7 @@ const GH_DATA = join( process.env.DATA_REPO ?? "data-repo", "../data/github/discussions", ); -export const categoriesArray: { name: string; emoji: string }[] = []; +export const categories: { name: string; emoji: string }[] = []; export async function fetchGithubDiscussion( noOfDiscussion?: number | null, @@ -35,13 +35,13 @@ export async function fetchGithubDiscussion( if (d.category) { const key = `${d.category.name}-${d.category.emoji}`; if ( - !categoriesArray.some( + !categories.some( (category) => category.name === d.category!.name && category.emoji === d.category!.emoji, ) ) { - categoriesArray.push(d.category); + categories.push(d.category); } } }); @@ -110,9 +110,7 @@ export async function getGithubDiscussions(githubHandle: string) { discussion.link?.split("/").pop() ?? "", discussion.repoName, ); - title = isAnswered - ? "Answered a Discussion" - : "Commented on a Discussion"; + title = isAnswered ? "Discussion Answered" : "Commented on discussion"; activityType = isAnswered ? "discussion_answered" : "discussion_comment_created"; diff --git a/lib/types.ts b/lib/types.ts index 6f6fec00..61928b2a 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -43,7 +43,7 @@ export interface Highlights { pr_collaborated: number; issue_assigned: number; issue_opened: number; - pr_stale?: number; // stale PRs added because there is need in app/api/leadeborad/functions.ts to avoid type error + pr_stale?: number; discussion_created: number; discussion_answered: number; discussion_comment_created: number;