Skip to content

Commit

Permalink
Added leet code cards to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
IDrumsey committed Nov 8, 2024
1 parent 892ae21 commit 3532024
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/api/leetcode/solved/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ export async function GET(request: Request) {
id: solution.titleSlug,
title: solution.title,
problemStatement: staticData.shortFormDescription,
category: staticData.problemCategory,
lang: solution.lang,
difficulty: questionDetails.difficulty,
},
codeSolution: staticData.codeSolution,
solutionAcceptedTimestamp: solution.timestamp,
solutionAcceptedTimestamp: solution.timestamp * 1000,
})
}

Expand Down
64 changes: 64 additions & 0 deletions app/homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { LeetCodeProblemSolution, Loading } from "./types"
import axios from "axios"
import { Doughnut } from "react-chartjs-2"
import { ArcElement, Chart, Legend, Tooltip } from "chart.js"
import { format } from "date-fns"

Chart.register(ArcElement, Tooltip, Legend)

Expand Down Expand Up @@ -777,6 +778,24 @@ const LeetCodeSection = (props: LeetCodeSectionProps) => {
numMedium={numPerDifficulty.medium}
numHard={numPerDifficulty.hard}
/>

{/* cards */}
<Stack
direction="column"
spacing={4}
sx={{ marginTop: 8 }}
>
{props.leetCodeSolutions == "loading" ? (
<></>
) : (
props.leetCodeSolutions.map((solution, i) => (
<LeetCodeSolutionCard
solution={solution}
key={i}
/>
))
)}
</Stack>
</Box>
)
}
Expand Down Expand Up @@ -884,3 +903,48 @@ const DifficultyLvlIndicator = (props: DifficultyLvlIndicatorProps) => {
</Stack>
)
}

type LeetCodeSolutionCardProps = {
solution: LeetCodeProblemSolution
}

const LeetCodeSolutionCard = (props: LeetCodeSolutionCardProps) => {
function getSubmittedDateAsStr(): string {
return format(
new Date(props.solution.solutionAcceptedTimestamp),
"MMMM dd, yyyy 'at' h:mma"
)
}

const theme = useTheme()

return (
<Box
paddingY={2}
paddingX={4}
sx={{ backgroundColor: new Color("#282828").toString(), borderRadius: 1 }}
>
<Typography
variant="h6"
marginBottom={1}
>
{props.solution.problem.title}
</Typography>
<Typography
variant="body2"
sx={{ color: new Color("#747474").toString() }}
>
{props.solution.problem.problemStatement}
</Typography>
<Typography
sx={{
color: new Color("#71FF71").toString(),
fontSize: theme.typography.caption.fontSize,
marginTop: theme.spacing(2),
}}
>
Submitted on {getSubmittedDateAsStr()}
</Typography>
</Box>
)
}

0 comments on commit 3532024

Please sign in to comment.