From 770c9e4afc15add94d24e3cb9af271ae9f7ad6a3 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 16 Aug 2024 23:31:42 +0100 Subject: [PATCH] Add user avatars --- .../Projects/ListProjectSolutions.tsx | 137 +++++++++++------- .../Projects/SubmitProjectModal.tsx | 4 +- src/components/Projects/VoteButton.tsx | 30 ++++ src/lib/date.ts | 6 +- 4 files changed, 122 insertions(+), 55 deletions(-) create mode 100644 src/components/Projects/VoteButton.tsx diff --git a/src/components/Projects/ListProjectSolutions.tsx b/src/components/Projects/ListProjectSolutions.tsx index c691084be..18e02f1fa 100644 --- a/src/components/Projects/ListProjectSolutions.tsx +++ b/src/components/Projects/ListProjectSolutions.tsx @@ -3,7 +3,13 @@ import { useToast } from '../../hooks/use-toast'; import { httpGet, httpPost } from '../../lib/http'; import { LoadingSolutions } from './LoadingSolutions'; import { EmptySolutions } from './EmptySolutions'; -import { ArrowDown, ArrowUp, CalendarCheck } from 'lucide-react'; +import { + ArrowDown, + ArrowUp, + CalendarCheck, + ThumbsDown, + ThumbsUp, +} from 'lucide-react'; import { getRelativeTimeString } from '../../lib/date'; import { Pagination } from '../Pagination/Pagination'; import { deleteUrlParam, getUrlParams, setUrlParams } from '../../lib/browser'; @@ -12,6 +18,9 @@ import { cn } from '../../lib/classname'; import { LeavingRoadmapWarningModal } from './LeavingRoadmapWarningModal'; import { isLoggedIn } from '../../lib/jwt'; import { showLoginPopup } from '../../lib/popup'; +import { CheckIcon } from '../ReactIcons/CheckIcon.tsx'; +import { VoteButton } from './VoteButton.tsx'; +import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx'; export interface ProjectStatusDocument { _id?: string; @@ -63,6 +72,30 @@ type ListProjectSolutionsProps = { projectId: string; }; +const submittedAlternatives = [ + 'submitted their solution', + 'got it done', + 'submitted their take', + 'finished the project', + 'submitted their work', + 'completed the project', + 'got it done', + 'delivered their project', + 'handed in their solution', + 'provided their deliverables', + 'submitted their approach', + 'sent in their project', + 'presented their take', + 'shared their completed task', + 'submitted their approach', + 'completed it', + 'finalized their solution', + 'delivered their approach', + 'turned in their project', + 'submitted their final draft', + 'delivered their solution', +]; + export function ListProjectSolutions(props: ListProjectSolutionsProps) { const { projectId } = props; @@ -220,72 +253,72 @@ export function ListProjectSolutions(props: ListProjectSolutionsProps) { }} /> -
- {solutions?.data.map((solution) => { - const repoUrlParts = solution?.repositoryUrl - ?.replace(/https?:\/\/(www\.)?github\.com/, '') - .split('/'); - const username = repoUrlParts?.[1]; - const repoName = repoUrlParts?.[2]; - +
+ {solutions?.data.map((solution, counter) => { const isVisited = alreadyVisitedSolutions[solution._id!]; + const avatar = solution.user.avatar || ''; return (
-
+
+ {solution.user.name} + + {solution.user.name} + + {submittedAlternatives[ + counter % submittedAlternatives.length + ] || 'submitted their solution'}{' '} + + {getRelativeTimeString(solution?.submittedAt!)} + +
+ +
+ + { + handleSubmitVote(solution._id!, 'upvote'); + }} + /> + + { + handleSubmitVote(solution._id!, 'downvote'); + }} + /> + + { if (!isVisited) { e.preventDefault(); setShowLeavingRoadmapModal(solution); } }} + target="_blank" + href={solution.repositoryUrl} > - {username}/{repoName} + + Visit Solution - -
- - · - - · - - - {getRelativeTimeString(solution?.submittedAt!)} - -
); diff --git a/src/components/Projects/SubmitProjectModal.tsx b/src/components/Projects/SubmitProjectModal.tsx index 3ccc8f537..ac8b84e4c 100644 --- a/src/components/Projects/SubmitProjectModal.tsx +++ b/src/components/Projects/SubmitProjectModal.tsx @@ -206,7 +206,7 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) { return ( -

+

Submit Solution URL

@@ -272,7 +272,7 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) { + ); +} diff --git a/src/lib/date.ts b/src/lib/date.ts index 0316c2ca4..2adbc3a86 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -33,11 +33,15 @@ export function getRelativeTimeString( } else { relativeTime = rtf.format(-diffInDays, 'day'); } + } else if (diffInDays < 30) { + relativeTime = rtf.format(-Math.round(diffInDays / 7), 'week'); + } else if (diffInDays < 365) { + relativeTime = rtf.format(-Math.round(diffInDays / 30), 'month'); } else { if (isTimed) { relativeTime = dayjs(date).format('MMM D, YYYY h:mm A'); } else { - relativeTime = rtf.format(-Math.round(diffInDays / 7), 'week'); + relativeTime = dayjs(date).format('MMM D, YYYY'); } }