Skip to content

Commit

Permalink
Chages done as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
dgparmar14 committed Jul 19, 2024
1 parent a032253 commit 1ac9b0a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/discussions/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -21,7 +21,7 @@ export default function DiscussionsLayout({
<div className="mx-auto max-w-6xl p-5">
<div className="items-center gap-5 pb-8 lg:mt-10 lg:flex">
<h1 className="text-3xl sm:text-4xl">Disucssions</h1>
<FilterDiscussions categories={categoriesArray} />
<FilterDiscussions categories={categories} />
</div>
<div className="flex w-full flex-col-reverse gap-3 lg:flex lg:flex-row">
{children}
Expand Down
8 changes: 4 additions & 4 deletions components/discussions/DiscussionLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand All @@ -29,15 +29,15 @@ export async function calculateContributor() {
if (existingContributor) {
existingContributor.points += points;
} else {
contributorsArray.push({
uniqueContributors.push({
name: contributor.name,
points: points,
githubHandle: contributor.slug,
});
}
});

return contributorsArray;
return uniqueContributors;
}

return [];
Expand Down
30 changes: 8 additions & 22 deletions components/discussions/GithubDiscussions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex w-full flex-col items-start justify-center lg:w-[90%]">
{discussions.length > 0 ? (
Expand Down
10 changes: 4 additions & 6 deletions lib/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
});
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ac9b0a

Please sign in to comment.