diff --git a/src/app/(frontend)/[slug]/page.tsx b/src/app/(frontend)/[slug]/page.tsx index 9934a2d..69db97f 100644 --- a/src/app/(frontend)/[slug]/page.tsx +++ b/src/app/(frontend)/[slug]/page.tsx @@ -1,10 +1,10 @@ import configPromise from '@payload-config' import { getPayload, type RequiredDataFromCollectionSlug } from 'payload' -import { draftMode } from "next/headers"; -import { cache } from "react"; -import { RenderBlocks } from "@/blocks/RenderBlocks"; -import PageClient from "./page.client"; - +import { draftMode } from 'next/headers' +import { cache } from 'react' +import { RenderBlocks } from '@/blocks/RenderBlocks' +import PageClient from './page.client' +import GitProfile from '@/components/GitProfile' export async function generateStaticParams() { const payload = await getPayload({ config: configPromise }) @@ -59,13 +59,14 @@ type Args = { export default async function Page({ params: paramsPromise }: Args) { const { slug = 'home' } = await paramsPromise - + //const { isEnabled: draft } = await draftMode() //const url = '/' + slug - const page: RequiredDataFromCollectionSlug<'pages'> | null = await queryPageBySlug({ - slug, - }) || null + const page: RequiredDataFromCollectionSlug<'pages'> | null = + (await queryPageBySlug({ + slug, + })) || null if (!page) { return
// return @@ -74,14 +75,14 @@ export default async function Page({ params: paramsPromise }: Args) { const { layout } = page return ( -
+
{/* Allows redirects for valid pages too */} {/**/} {/*draft && */} +
) } - diff --git a/src/components/GitProfile/index.tsx b/src/components/GitProfile/index.tsx new file mode 100644 index 0000000..1e8ebd3 --- /dev/null +++ b/src/components/GitProfile/index.tsx @@ -0,0 +1,47 @@ +'use client' + +import { CommitDetails, getGitActivity } from '@/serverActions/getGitActivity' +import { useMemo, useState } from 'react' +import { GitCommitCard } from '../git-commit-card' +import { Loader2 } from 'lucide-react' + +const GitProfile = () => { + const [commits, setCommits] = useState([]) + + useMemo(async () => { + if (commits.length) return + + const commitResponse = await getGitActivity() + setCommits(commitResponse || []) + }, [commits, setCommits]) + + return ( +
+ {!!commits.length ? + commits.map((c) => { + const refNameSplitArray = c.commitRefName.split('/') + const refName = refNameSplitArray[refNameSplitArray.length - 1] + + return ( + + ) + }) + : +
+ . . . loading contributions . . . + +
+ } +
+ ) +} + +export default GitProfile diff --git a/src/components/git-commit-card.tsx b/src/components/git-commit-card.tsx new file mode 100644 index 0000000..7ed6499 --- /dev/null +++ b/src/components/git-commit-card.tsx @@ -0,0 +1,70 @@ +import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' +import { Badge } from '@/components/ui/badge' +import Link from 'next/link' + +interface Props { + title: string + description: string + dates: string + location: string + image?: string + repoWebsite?: string + links?: readonly { + icon: React.ReactNode + title: string + href: string + }[] +} + +export function GitCommitCard({ + title, + description, + dates, + location, + image, + repoWebsite, + links, +}: Props) { + return ( +
+
  • +
    + + + {title[0]} + +
    +
    + {dates && } +
    + + {title} + + {location && ( + + {`=> ${location}`} + + )} +
    + {description && ( + + {description} + + )} +
    + {links && links.length > 0 && ( +
    + {links?.map((link, idx) => ( + + + {link.icon} + {link.title} + + + ))} +
    + )} +
  • +
    + ) +} diff --git a/src/components/hackathon-card.tsx b/src/components/hackathon-card.tsx deleted file mode 100644 index d444240..0000000 --- a/src/components/hackathon-card.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; -import { Badge } from "@/components/ui/badge"; -import Link from "next/link"; - -interface Props { - title: string; - description: string; - dates: string; - location: string; - image?: string; - links?: readonly { - icon: React.ReactNode; - title: string; - href: string; - }[]; -} - -export function HackathonCard({ - title, - description, - dates, - location, - image, - links, -}: Props) { - return ( -
  • -
    - - - {title[0]} - -
    -
    - {dates && ( - - )} -

    {title}

    - {location && ( -

    {location}

    - )} - {description && ( - - {description} - - )} -
    - {links && links.length > 0 && ( -
    - {links?.map((link, idx) => ( - - - {link.icon} - {link.title} - - - ))} -
    - )} -
  • - ); -} diff --git a/src/serverActions/getGitActivity.ts b/src/serverActions/getGitActivity.ts new file mode 100644 index 0000000..decd4a9 --- /dev/null +++ b/src/serverActions/getGitActivity.ts @@ -0,0 +1,44 @@ +'use server' + +type CommitContent = { + Commits: [any], + HeadCommit: { + Message: string, + Timestamp: string, + } +} + +export type CommitDetails = { + id: number, + repoName: string, + repoUrl: string, + repoWebsite: string, + commitMessage: string, + commitTimestamp: string, + commitRefName: string, + avatarUrl: string, +} + +export const getGitActivity = async (): Promise => { + const gitActivityResponse = await fetch('https://git.beitzah.net/api/v1/users/ysandler/activities/feeds?only-performed-by=true') + const gitActivityJson = await gitActivityResponse.json() + const commits = gitActivityJson + .filter((a: any) => a.op_type === 'commit_repo' && !!a.content) + .map((c: any) => { + const repo = c.repo + const commitContent = JSON.parse(c.content as string) as CommitContent + + return { + id: c.id, + repoName: repo.full_name, + repoUrl: repo.url, + repoWebsite: repo.html_url, + commitMessage: commitContent.HeadCommit.Message, + commitTimestamp: commitContent.HeadCommit.Timestamp, + commitRefName: c.ref_name || '', + avatarUrl: repo.owner.avatar_url, + } + }) + + return commits +}