From 51b8e58d7cc91dbb64b1051f106182bcd1f2bb4e Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Tue, 9 Apr 2024 23:14:07 +0100 Subject: [PATCH] Add public profile page --- src/api/user.ts | 8 +- .../UserPublicActivityHeatmap.tsx | 7 +- .../UserPublicProfilePage.tsx | 5 +- .../UserPublicProgresses.tsx | 97 +++++++++++-------- src/lib/date.ts | 7 ++ src/pages/u/[username]/index.astro | 13 ++- 6 files changed, 88 insertions(+), 49 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index e82f13b75..b10458dbf 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -54,10 +54,10 @@ export interface UserDocument { roadmapVisibility: AllowedRoadmapVisibility; customRoadmapVisibility: AllowedCustomRoadmapVisibility; }; - resetPasswordCodeAt: Date; - verifiedAt: Date; - createdAt: Date; - updatedAt: Date; + resetPasswordCodeAt: string; + verifiedAt: string; + createdAt: string; + updatedAt: string; } export type UserActivityCount = { diff --git a/src/components/UserPublicProfile/UserPublicActivityHeatmap.tsx b/src/components/UserPublicProfile/UserPublicActivityHeatmap.tsx index 8a36c4661..80be3cbaa 100644 --- a/src/components/UserPublicProfile/UserPublicActivityHeatmap.tsx +++ b/src/components/UserPublicProfile/UserPublicActivityHeatmap.tsx @@ -2,12 +2,13 @@ import CalendarHeatmap from 'react-calendar-heatmap'; import { Tooltip as ReactTooltip } from 'react-tooltip'; import 'react-calendar-heatmap/dist/styles.css'; import 'react-tooltip/dist/react-tooltip.css'; -import { formatActivityDate } from '../../lib/date'; +import { formatActivityDate, formatMonthDate } from '../../lib/date'; import type { UserActivityCount } from '../../api/user'; import dayjs from 'dayjs'; type UserActivityHeatmapProps = { activity: UserActivityCount; + joinedAt: string; }; const legends = [ @@ -37,7 +38,9 @@ export function UserActivityHeatmap(props: UserActivityHeatmapProps) { Progress updates over the past year

- Member since: June 2021 + + Member since: {formatMonthDate(props.joinedAt)} + +
- + {customRoadmapVisibility !== 'none' && customRoadmaps?.length > 0 && ( -
+

Roadmaps made by me

-
- {customRoadmaps.map((roadmap, counter) => ( - - {roadmap.title} - - ))} +
+ {customRoadmaps.map((roadmap, counter) => { + const doneCount = roadmap.done; + const skippedCount = roadmap.skipped; + const totalCount = roadmap.total; + + const totalMarked = doneCount + skippedCount; + const progressPercentage = getPercentage(totalMarked, totalCount); + + return ( + + {roadmap.title} + + ); + })}
)} -
- {roadmapVisibility !== 'none' && ( - <> -

My Skills

-
    - {roadmaps.map((roadmap, counter) => ( -
  • - -
  • - ))} -
- - )} -
+ {roadmapVisibility !== 'none' && roadmaps.length > 0 && ( + <> +

+ Skills I have mastered +

+
+ {roadmaps.map((roadmap, counter) => { + const percentageDone = getPercentage( + roadmap.done + roadmap.skipped, + roadmap.total, + ); + + return ( + + {roadmap.title} + + {parseInt(percentageDone, 10)}% + + + + + ); + })} +
+ + )}
); } diff --git a/src/lib/date.ts b/src/lib/date.ts index 5d34da249..ecb6bd726 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -33,6 +33,13 @@ export function getRelativeTimeString(date: string): string { return relativeTime; } +export function formatMonthDate(date: string): string { + return new Date(date).toLocaleDateString('en-US', { + month: 'long', + year: 'numeric', + }); +} + export function formatActivityDate(date: string): string { return new Date(date).toLocaleDateString('en-US', { month: 'long', diff --git a/src/pages/u/[username]/index.astro b/src/pages/u/[username]/index.astro index 0dcdaa62c..843c4bb73 100644 --- a/src/pages/u/[username]/index.astro +++ b/src/pages/u/[username]/index.astro @@ -3,6 +3,8 @@ import { FrownIcon } from 'lucide-react'; import { userApi } from '../../../api/user'; import AccountLayout from '../../../layouts/AccountLayout.astro'; import { UserPublicProfilePage } from '../../../components/UserPublicProfile/UserPublicProfilePage'; +import OpenSourceBanner from '../../../components/OpenSourceBanner.astro'; +import Footer from '../../../components/Footer.astro'; interface Params extends Record { username: string; @@ -40,11 +42,18 @@ if (error || !userDetails) { height='120' /> -

Problem loading user!

+

+ Problem loading user! +

- {errorMessage} + + {errorMessage} +

) } + + +