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 3, 2024
2 parents 566e108 + 3ea55bc commit 2ca9189
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 201 deletions.
74 changes: 73 additions & 1 deletion app/leaderboard/[duration]/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { HiSortAscending, HiSortDescending } from "react-icons/hi";
import { Popover } from "@headlessui/react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import { BiGitPullRequest } from "react-icons/bi";
import { GoIssueOpened, GoIssueClosed } from "react-icons/go";
import { VscGitPullRequestClosed } from "react-icons/vsc";

const filterBySearchTerm = (searchTermLC: string) => {
return (item: LeaderboardAPIResponse[number]) =>
Expand Down Expand Up @@ -78,7 +81,11 @@ export default function Leaderboard(props: Props) {
) => {
const params = new URLSearchParams(searchParams.toString());
if (Array.isArray(value)) {
params.set(key, value.join(","));
if (value.length) {
params.set(key, value.join(","));
} else {
params.delete(key);
}
} else {
params.set(key, value.toString());
}
Expand Down Expand Up @@ -221,6 +228,71 @@ export default function Leaderboard(props: Props) {
</div>
</div>

{/* Stats Summary */}
<div className="mx-4 mt-4 rounded-lg border border-primary-500 p-4 md:mx-0">
<div className="grid grid-cols-2 gap-4 md:grid-cols-4">
<div className="flex items-center space-x-2 rounded-lg border border-secondary-600 p-3 dark:border-secondary-300">
<GoIssueOpened className="text-2xl text-green-500" />
<div>
<p className="text-sm text-secondary-500 dark:text-secondary-300">
Issues Opened
</p>
<p className="text-xl font-semibold">
{resultSet.reduce(
(sum, user) => sum + user.highlights.issue_opened,
0,
)}
</p>
</div>
</div>

<div className="flex items-center space-x-2 rounded-lg border border-secondary-600 p-3 dark:border-secondary-300">
<GoIssueClosed className="text-2xl text-purple-500" />
<div>
<p className="text-sm text-secondary-500 dark:text-secondary-300">
Issues Closed
</p>
<p className="text-xl font-semibold">
{resultSet.reduce(
(sum, user) => sum + user.highlights.issue_closed,
0,
)}
</p>
</div>
</div>

<div className="flex items-center space-x-2 rounded-lg border border-secondary-600 p-3 dark:border-secondary-300">
<BiGitPullRequest className="text-2xl text-blue-500" />
<div>
<p className="text-sm text-secondary-500 dark:text-secondary-300">
PRs Opened
</p>
<p className="text-xl font-semibold">
{resultSet.reduce(
(sum, user) => sum + user.highlights.pr_opened,
0,
)}
</p>
</div>
</div>

<div className="flex items-center space-x-2 rounded-lg border border-secondary-600 p-3 dark:border-secondary-300">
<VscGitPullRequestClosed className="text-2xl text-orange-500" />
<div>
<p className="text-sm text-secondary-500 dark:text-secondary-300">
PRs Merged
</p>
<p className="text-xl font-semibold">
{resultSet.reduce(
(sum, user) => sum + user.highlights.pr_merged,
0,
)}
</p>
</div>
</div>
</div>
</div>

{/* Leaderboard List */}
<div className="mx-4 border-secondary-600 xl:mx-0">
<div className="px-0 pb-10 lg:grid lg:grid-cols-12 lg:pb-20 2xl:gap-5">
Expand Down
93 changes: 52 additions & 41 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { env } from "@/env.mjs";
import { FaYoutube, FaLinkedin, FaGithub, FaEnvelope } from "react-icons/fa";
import { ReactNode } from "react";
import { BsTwitterX } from "react-icons/bs";
import RelativeTime from "@/components/RelativeTime";

const SocialLink = ({
href,
Expand Down Expand Up @@ -84,48 +85,58 @@ export default function Footer() {
</FooterSection>
</div>

<div className="flex w-full flex-col md:w-1/3 md:flex-row md:justify-end md:space-x-12">
<FooterSection title="Resources">
<FooterLink href={env.NEXT_PUBLIC_DATA_SOURCE}>
Data Repository
</FooterLink>
<FooterLink href={env.NEXT_PUBLIC_FLAT_REPO_EXPLORER_URL}>
Flat Repository Explorer
</FooterLink>
</FooterSection>
<div className="flex w-full flex-col items-end gap-4">
<div className="flex w-full flex-col md:w-1/3 md:flex-row md:justify-end md:space-x-12">
<FooterSection title="Resources">
<FooterLink href={env.NEXT_PUBLIC_DATA_SOURCE}>
Data Repository
</FooterLink>
<FooterLink href={env.NEXT_PUBLIC_FLAT_REPO_EXPLORER_URL}>
Flat Repository Explorer
</FooterLink>
</FooterSection>

<FooterSection title="Connect">
<div className="flex space-x-4">
<SocialLink
href={env.NEXT_PUBLIC_YOUTUBE_URL}
icon={FaYoutube}
label="YouTube"
/>
<SocialLink
href={env.NEXT_PUBLIC_LINKEDIN_URL}
icon={FaLinkedin}
label="LinkedIn"
/>
<SocialLink
href={env.NEXT_PUBLIC_GITHUB_URL}
icon={FaGithub}
label="GitHub"
/>
<SocialLink
href={
env.NEXT_PUBLIC_CONTACT_EMAIL &&
`mailto:${env.NEXT_PUBLIC_CONTACT_EMAIL}`
}
icon={FaEnvelope}
label="Email"
/>
<SocialLink
href={env.NEXT_PUBLIC_X_URL}
icon={BsTwitterX}
label="Twitter"
/>
</div>
</FooterSection>
<FooterSection title="Connect">
<div className="flex space-x-4">
<SocialLink
href={env.NEXT_PUBLIC_YOUTUBE_URL}
icon={FaYoutube}
label="YouTube"
/>
<SocialLink
href={env.NEXT_PUBLIC_LINKEDIN_URL}
icon={FaLinkedin}
label="LinkedIn"
/>
<SocialLink
href={env.NEXT_PUBLIC_GITHUB_URL}
icon={FaGithub}
label="GitHub"
/>
<SocialLink
href={
env.NEXT_PUBLIC_CONTACT_EMAIL &&
`mailto:${env.NEXT_PUBLIC_CONTACT_EMAIL}`
}
icon={FaEnvelope}
label="Email"
/>
<SocialLink
href={env.NEXT_PUBLIC_X_URL}
icon={BsTwitterX}
label="Twitter"
/>
</div>
</FooterSection>
</div>

<span className="text-end text-sm italic text-gray-400">
<p>Leaderboard scrapes data frequently.</p>
<p>
Data was last updated{" "}
<RelativeTime className="font-semibold" time={new Date()} />.
</p>
</span>
</div>
</div>
</div>
Expand Down
98 changes: 11 additions & 87 deletions components/contributors/GithubActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import {
parseOrgRepoFromURL,
} from "@/lib/utils";
import OpenGraphImage from "../gh_events/OpenGraphImage";
import { useState } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import RelativeTime from "../RelativeTime";
import DateRangePicker from "../DateRangePicker";
import { format } from "date-fns";
import GithubDiscussion from "../discussions/GithubDiscussion";
import { IoIosChatboxes } from "react-icons/io";
import Link from "next/link";
import { atomWithStorage } from "jotai/utils";
import { useAtom } from "jotai";

const activityTypesAtom = atomWithStorage("leaderboard-activity-types", [
...ACTIVITY_TYPES,
]);

let commentTypes = (activityEvent: string[]) => {
switch (activityEvent[0]) {
Expand Down Expand Up @@ -339,30 +344,6 @@ const activitiesOfType = (types: Activity["type"][]) => {
};
};

/*const getRangeFilterPresets = (activities: Activity[]) => {
if (!activities.length) return [];
const latest = new Date(activities[0].time);
let oldest = new Date(latest);
activities.forEach((activity) => {
const time = new Date(activity.time);
if (time < oldest) {
oldest = time;
}
});
let current = new Date(oldest.getFullYear(), oldest.getMonth());
const end = new Date(latest.getFullYear(), latest.getMonth());
const results: string[] = [];
while (current <= end) {
results.push(current.toISOString().slice(0, 7));
current.setMonth(current.getMonth() + 1);
}
return results.reverse();
};*/

interface Props {
activityData: ActivityData;
}
Expand All @@ -371,7 +352,6 @@ export default function GithubActivity({ activityData }: Props) {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
// const rangeQuery = searchParams.get("range") ?? "last-month";
const [start, end] = parseDateRangeSearchParam(searchParams.get("between"));

const updateSearchParam = (key: string, value?: string) => {
Expand All @@ -386,32 +366,7 @@ export default function GithubActivity({ activityData }: Props) {
router.replace(`${pathname}${query}`, { scroll: false });
};

const [activityTypes, setActivityTypes] = useState([...ACTIVITY_TYPES]);

/*const range = useMemo(() => {
const to = new Date();
to.setDate(to.getDate() + 1);
if (rangeQuery === "last-month") {
const from = new Date(to);
from.setDate(from.getDate() - 30);
return { from, to: to };
} else if (rangeQuery === "last-week") {
const from = new Date(to);
from.setDate(from.getDate() - 7);
return { from, to };
} else {
const from = new Date(rangeQuery);
const to = new Date(rangeQuery);
to.setMonth(to.getMonth() + 1);
return { from, to };
}
}, [rangeQuery]);*/

/*const rangePresets = useMemo(
() => getRangeFilterPresets(activityData["activity"]),
[activityData],
);*/
const [activityTypes, setActivityTypes] = useAtom(activityTypesAtom);

const activitiesInRange = activityData.activity.filter(
activitiesBetween({ from: start, to: end }),
Expand All @@ -437,36 +392,6 @@ export default function GithubActivity({ activityData }: Props) {
);
}}
/>
{/* <select
className="my-4 block rounded border border-secondary-600 px-2 py-1 text-sm font-medium text-foreground focus:z-10 focus:outline-none dark:border-secondary-300"
disabled={!rangePresets}
value={rangeQuery}
onChange={(event) => {
const current = new URLSearchParams(
Array.from(searchParams.entries()),
);
const value = event.target.value;
if (!value) {
current.delete("range");
} else {
current.set("range", event.target.value);
}
const search = current.toString();
const query = search ? `?${search}` : "";
router.replace(`${pathname}${query}`, { scroll: false });
}}
>
<option value="last-week">Last week</option>
<option value="last-month">Last 30 days</option>
{rangePresets?.map((preset) => (
<option key={preset} value={preset}>
{new Date(preset).toLocaleString("default", {
month: "long",
year: "numeric",
})}
</option>
))}
</select> */}
{ACTIVITY_TYPES.map((type) => (
<ActivityCheckbox
key={type}
Expand Down Expand Up @@ -509,11 +434,10 @@ export const ActivityCheckbox = (props: {
type="checkbox"
checked={props.state.includes(props.type)}
onChange={(event) => {
const final = event.target.checked
? Array.from(new Set([...props.state, props.type]))
: props.state.filter((type) => type !== props.type);

props.setState(final);
const isChecked = event.target.checked;
const final = new Set([...props.state]);
final[isChecked ? "add" : "delete"](props.type);
props.setState(Array.from(final));
}}
/>{" "}
{
Expand Down
2 changes: 1 addition & 1 deletion components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Navbar() {
const pathname = usePathname();
return (
<>
<nav className="sticky top-0 z-10 border-b border-secondary-300 bg-background px-4 py-1 shadow-md dark:border-secondary-700 sm:shadow-lg">
<nav className="sticky top-0 z-10 border-b border-secondary-300 bg-background px-4 py-1 shadow dark:border-secondary-700">
<div className="mx-auto flex max-w-7xl items-center justify-between xl:px-3">
<Logo />

Expand Down
Loading

0 comments on commit 2ca9189

Please sign in to comment.