From 314eb5d7d226a1851414c4a74afb002dbdc58949 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 3 Feb 2025 21:17:06 +0000 Subject: [PATCH] Refactor project solutoin row --- .../Projects/ListProjectSolutions.tsx | 101 ++-------------- .../Projects/ProjectSolutionModal.tsx | 31 ++--- .../Projects/ProjectSolutionRow.tsx | 111 ++++++++++++++++++ 3 files changed, 138 insertions(+), 105 deletions(-) create mode 100644 src/components/Projects/ProjectSolutionRow.tsx diff --git a/src/components/Projects/ListProjectSolutions.tsx b/src/components/Projects/ListProjectSolutions.tsx index 994096ee8..7e10ebd8a 100644 --- a/src/components/Projects/ListProjectSolutions.tsx +++ b/src/components/Projects/ListProjectSolutions.tsx @@ -17,6 +17,7 @@ import { SelectLanguages } from './SelectLanguages.tsx'; import type { ProjectFrontmatter } from '../../lib/project.ts'; import { ProjectSolutionModal } from './ProjectSolutionModal.tsx'; import { SortProjects } from './SortProjects.tsx'; +import { ProjectSolutionRow } from './ProjectSolutionRow'; export interface ProjectStatusDocument { _id?: string; @@ -72,30 +73,6 @@ type ListProjectSolutionsProps = { projectId: string; }; -export 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, project: projectData } = props; @@ -276,73 +253,15 @@ export function ListProjectSolutions(props: ListProjectSolutionsProps) { ) : ( <>
- {solutions?.data.map((solution, counter) => { - 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'); - }} - /> - - - -
-
-
- ); - })} + {solutions?.data.map((solution, counter) => ( + + ))}
{(solutions?.totalPages || 0) > 1 && ( diff --git a/src/components/Projects/ProjectSolutionModal.tsx b/src/components/Projects/ProjectSolutionModal.tsx index 0cda0b5cf..a28e105b7 100644 --- a/src/components/Projects/ProjectSolutionModal.tsx +++ b/src/components/Projects/ProjectSolutionModal.tsx @@ -1,20 +1,17 @@ +import { ArrowUpRight, ThumbsDown, ThumbsUp } from 'lucide-react'; import { useEffect, useState } from 'react'; +import { useToast } from '../../hooks/use-toast'; import { deleteUrlParam, getUrlParams } from '../../lib/browser'; -import { ModalLoader } from '../UserProgress/ModalLoader'; -import { Modal } from '../Modal'; -import { httpGet, httpPost } from '../../lib/http'; -import { - submittedAlternatives, - type AllowedVoteType, -} from './ListProjectSolutions'; import { getRelativeTimeString } from '../../lib/date'; -import { ArrowUpRight, ThumbsDown, ThumbsUp, Trophy } from 'lucide-react'; -import { VoteButton } from './VoteButton'; -import { GitHubIcon } from '../ReactIcons/GitHubIcon'; +import { httpGet, httpPost } from '../../lib/http'; import { isLoggedIn } from '../../lib/jwt'; import { showLoginPopup } from '../../lib/popup'; import { pageProgressMessage } from '../../stores/page'; -import { useToast } from '../../hooks/use-toast'; +import { Modal } from '../Modal'; +import { GitHubIcon } from '../ReactIcons/GitHubIcon'; +import { ModalLoader } from '../UserProgress/ModalLoader'; +import { type AllowedVoteType } from './ListProjectSolutions'; +import { VoteButton } from './VoteButton'; type UserProjectSolutionResponse = { id?: string; @@ -135,8 +132,12 @@ export function ProjectSolutionModal(props: ProjectSolutionModalProps) { bodyClassName={'h-auto'} >
-

{projectTitle}

-

{projectDescription}

+

+ {projectTitle} +

+

+ {projectDescription} +

@@ -150,7 +151,9 @@ export function ProjectSolutionModal(props: ProjectSolutionModalProps) { className="h-12 w-12 rounded-full border-2 border-white shadow-md" />
-

{solution?.user.name}'s Solution

+

+ {solution?.user.name}'s Solution +

Submitted their solution{' '} {getRelativeTimeString(solution?.submittedAt!)} diff --git a/src/components/Projects/ProjectSolutionRow.tsx b/src/components/Projects/ProjectSolutionRow.tsx new file mode 100644 index 000000000..45934cd8e --- /dev/null +++ b/src/components/Projects/ProjectSolutionRow.tsx @@ -0,0 +1,111 @@ +import { ThumbsDown, ThumbsUp } from 'lucide-react'; +import { getRelativeTimeString } from '../../lib/date'; +import { VoteButton } from './VoteButton'; +import { GitHubIcon } from '../ReactIcons/GitHubIcon'; +import type { + AllowedVoteType, + ProjectStatusDocument, +} from './ListProjectSolutions'; + +export 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', +]; + +type ProjectSolutionRowProps = { + solution: ProjectStatusDocument & { + user: { + id: string; + name: string; + avatar: string; + }; + voteType?: AllowedVoteType | 'none'; + }; + counter: number; + onVote: (solutionId: string, voteType: AllowedVoteType) => void; + onVisitSolution: (solution: ProjectSolutionRowProps['solution']) => void; +}; + +export function ProjectSolutionRow(props: ProjectSolutionRowProps) { + const { solution, counter, onVote, onVisitSolution } = props; + + const avatar = solution.user.avatar || ''; + + return ( +

+
+
+ {solution.user.name} + {solution.user.name} + + {submittedAlternatives[counter % submittedAlternatives.length] || + 'submitted their solution'} + {' '} + + {getRelativeTimeString(solution?.submittedAt!)} + +
+ +
+ + { + onVote(solution._id!, 'upvote'); + }} + /> + + { + onVote(solution._id!, 'downvote'); + }} + /> + + + +
+
+
+ ); +}