Skip to content

Commit

Permalink
Merge branch 'main' into Issues/ohcnetwork#492/improve-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Dec 12, 2024
2 parents 2ca9189 + be46e0b commit 01d9c75
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 224 deletions.
2 changes: 0 additions & 2 deletions app/discussions/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { notFound } from "next/navigation";
import { featureIsEnabled } from "@/lib/utils";
import FilterDiscussions from "../../components/discussions/FilterDiscussions";
import { categories } from "../../lib/discussion";
import DiscussionLeaderboard from "../../components/discussions/DiscussionLeaderboard";
import { Suspense } from "react";

export const metadata: Metadata = {
Expand All @@ -28,7 +27,6 @@ export default function DiscussionsLayout({
</div>
<div className="flex w-full flex-col-reverse gap-3 lg:flex lg:flex-row">
{children}
<DiscussionLeaderboard />
</div>
</div>
);
Expand Down
89 changes: 87 additions & 2 deletions app/discussions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,97 @@
import { fetchGithubDiscussion } from "../../lib/discussion";
import GithubDiscussions from "../../components/discussions/GithubDiscussions";
import { getContributors } from "@/lib/api";
import Link from "next/link";

export default async function Page() {
const discussions = await fetchGithubDiscussion();

if (!discussions) {
return null;
}

const contributors = await calculateContributor();

return (
discussions && (
<>
<GithubDiscussions discussions={discussions} searchParams={{}} />
)
<div className="bg-secondary-100/50 dark:bg-secondary-800/50 h-fit w-full rounded-lg border border-secondary-100 shadow-lg dark:border-secondary-800 lg:fixed lg:right-28 lg:top-48 lg:w-[23%]">
<div className="flex flex-col justify-between rounded-t-lg border-b border-secondary-300 bg-secondary-100 px-6 py-4 dark:border-secondary-700 dark:bg-secondary-800 md:flex-row md:items-center">
<h4 className="font-bold">Most Helpful</h4>
</div>

<div className="flex flex-col gap-2 p-4 ">
{contributors
.filter((contributor) => contributor.points > 0)
.sort((a, b) => b.points - a.points)
.slice(0, 3)
.map((contributor, index) => (
<Link
key={index}
href={`/contributors/${contributor.githubHandle}`}
>
<span className="flex cursor-pointer items-center space-x-3 rounded-lg bg-background px-2 py-3 transition duration-300 hover:shadow-lg hover:shadow-primary-500">
<span className="flex h-10 w-10 items-center justify-center rounded-full bg-secondary-100 text-lg dark:bg-secondary-800">
{index + 1}
</span>
<span className="text-lg font-medium">
{contributor.name}
</span>
</span>
</Link>
))}
</div>
<div className="pt-2">
<Link
className="block rounded border border-primary-500 bg-gradient-to-b from-primary-500 to-primary-700 p-3 px-10 text-center font-bold text-white shadow-lg transition hover:from-secondary-800 hover:to-secondary-900 hover:text-primary-500 hover:shadow-xl"
href="/leaderboard?sortBy=discussion_comment_created"
>
Show More
</Link>
</div>
</div>
</>
);
}

interface Contributor {
name: string;
points: number;
githubHandle: string;
}

async function calculateContributor() {
const contributors = await getContributors();

// 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 uniqueContributors: Contributor[] = [];

contributors.forEach((contributor) => {
const existingContributor = uniqueContributors.find(
(c) => c.name === contributor.name,
);

const points =
contributor.highlights.discussion_answered ||
contributor.highlights.discussion_created ||
contributor.highlights.discussion_comment_created ||
0;

if (existingContributor) {
existingContributor.points += points;
} else {
uniqueContributors.push({
name: contributor.name,
points: points,
githubHandle: contributor.slug,
});
}
});

return uniqueContributors;
}

return [];
}
1 change: 0 additions & 1 deletion app/feed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import octokit from "@/lib/octokit";
const GITHUB_ORG: string = env.NEXT_PUBLIC_GITHUB_ORG;

export default async function FeedPage() {
console.log(GITHUB_ORG);
const events = await octokit.paginate(
"GET /orgs/{org}/events",
{
Expand Down
2 changes: 1 addition & 1 deletion components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import clsx from "clsx";

export default async function Markdown(props: {
export default function Markdown(props: {
children: string;
className?: string;
}) {
Expand Down
2 changes: 1 addition & 1 deletion components/contributors/BadgeIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GraduateAttribute } from "@/config/GraduateAttributes";
import Image from "next/image";

function useOnClickOutside(
ref: RefObject<HTMLInputElement>,
ref: RefObject<HTMLInputElement | null>,
handler: () => void,
) {
useEffect(() => {
Expand Down
3 changes: 1 addition & 2 deletions components/contributors/InfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* */
import { Contributor } from "@/lib/types";
import clsx from "clsx";
import Link from "next/link";
import { BsSlack, BsTwitterX, BsLinkedin, BsGithub } from "react-icons/bs";
import { env } from "@/env.mjs";
import ContributorImage from "./ContributorImage";

export default async function InfoCard({
export default function InfoCard({
contributor,
rank = null,
isClickable = false,
Expand Down
90 changes: 0 additions & 90 deletions components/discussions/DiscussionLeaderboard.tsx

This file was deleted.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "node ./scripts/checkData.js && next dev",
"build": "node ./scripts/loadOrgData.js && next build",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint-fix": "eslint . --fix",
Expand All @@ -26,9 +26,9 @@
"jotai": "^2.10.2",
"next": "^14.2.10",
"next-themes": "^0.2.1",
"react": "^18.3.1",
"react": "^19.0.0",
"react-activity-calendar": "^2.2.11",
"react-dom": "^18.3.1",
"react-dom": "^19.0.0",
"react-icons": "^4.12.0",
"rehype-stringify": "^9.0.4",
"remark": "^14.0.3",
Expand All @@ -43,7 +43,7 @@
"devDependencies": {
"@tailwindcss/typography": "^0.5.13",
"@types/node": "^20.14.12",
"@types/react": "^18.3.3",
"@types/react": "^19.0.1",
"autoprefixer": "^10.4.19",
"chai": "^5.1.1",
"chai-json-schema": "^1.5.1",
Expand All @@ -63,5 +63,8 @@
"tailwindcss": "^3.4.6",
"typescript": "^5.5.4",
"yaml": "^2.5.0"
},
"overrides": {
"@types/react": "19.0.1"
}
}
Loading

0 comments on commit 01d9c75

Please sign in to comment.