Skip to content

Commit 6416110

Browse files
committed
Hero Refactored
2 parents 5c3d214 + 63a4477 commit 6416110

28 files changed

+1714
-287
lines changed

.github/Pull_request_Template.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Pull Request Template
22

33
## Summary
4-
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
4+
Just write what issue worked on and how it is working now.
55

66
Fixes # (issue)
77

@@ -10,23 +10,6 @@ Please mark [X] for applicable items:
1010

1111
- [ ] Bug fix (non-breaking change which fixes an issue)
1212
- [ ] New feature (non-breaking change which adds functionality)
13-
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14-
- [ ] Documentation update
15-
- [ ] Code refactoring
16-
- [ ] Other (please describe):
1713

18-
## Testing
19-
Please describe the tests you performed to verify your changes:
20-
21-
## Screenshots/Videos
22-
Please attach relevant screenshots or videos demonstrating the changes.
23-
24-
## Checklist
25-
Please mark [X] for completed items:
26-
27-
- [ ] My code follows the project's style guidelines
28-
- [ ] I have performed a self-review of my code
29-
- [ ] I have commented my code, particularly in hard-to-understand areas
30-
- [ ] I have updated the documentation accordingly
31-
- [ ] My changes generate no new warnings
32-
- [ ] I have added tests that prove my fix is effective or that my feature works
14+
## Screenshots/Videos (optional)
15+
Please attach relevant screenshots or videos demonstrating the changes.

GQL_Queries/contest.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* This GraphQL query retrieves the contest ranking and ranking history for a specific user.
3+
*
4+
* The `getUserContestRanking` query takes the `username` as a parameter and returns the user's contest ranking, including:
5+
* - `attendedContestsCount`: The number of contests the user has attended.
6+
* - `rating`: The user's rating.
7+
* - `globalRanking`: The user's global ranking.
8+
* - `totalParticipants`: The total number of participants.
9+
* - `topPercentage`: The user's top percentage.
10+
* - `badge`: The badge information, including the badge name.
11+
*
12+
* The `userContestRankingHistory` query takes the `username` as a parameter and returns the user's contest ranking history, including:
13+
* - `attended`: Whether the user attended the contest.
14+
* - `rating`: The user's rating for the contest.
15+
* - `ranking`: The user's ranking in the contest.
16+
* - `trendDirection`: The trend direction of the user's ranking.
17+
* - `problemsSolved`: The number of problems solved by the user.
18+
* - `totalProblems`: The total number of problems in the contest.
19+
* - `finishTimeInSeconds`: The finish time in seconds.
20+
* - `contest`: The contest information, including the title and start time.
21+
*/
22+
const query = `#graphql
23+
query getUserContestRanking ($username: String!) {
24+
userContestRanking(username: $username) {
25+
attendedContestsCount
26+
rating
27+
globalRanking
28+
totalParticipants
29+
topPercentage
30+
badge {
31+
name
32+
}
33+
}
34+
userContestRankingHistory(username: $username) {
35+
attended
36+
rating
37+
ranking
38+
trendDirection
39+
problemsSolved
40+
totalProblems
41+
finishTimeInSeconds
42+
contest {
43+
title
44+
startTime
45+
}
46+
}
47+
}`;
48+
49+
export default query;

GQL_Queries/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// import exp from 'constants';
2+
3+
/**
4+
* @fileoverview This file exports the default export from the 'recentAcSubmit' module
5+
* as 'AcSubmissionQuery'.
6+
*/
7+
export { default as AcSubmissionQuery } from './recentAcSubmit';
8+
export { default as contestQuery } from './contest';
9+
export { default as userProfileQuery } from './userProfile';
10+
export { default as submissionQuery } from './recentSubmit';
11+
export { default as languageStatsQuery } from './languageStats';

GQL_Queries/languageStats.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* This GraphQL query retrieves the count of problems solved by a user for each programming language.
3+
*
4+
* @param $username - The username of the user whose language problem count is being queried.
5+
* @returns An object containing the user's language problem count, including the language name and the number of problems solved.
6+
*
7+
* Example usage:
8+
*
9+
* ```typescript
10+
* const query = `
11+
* query languageStats($username: String!) {
12+
* matchedUser(username: $username) {
13+
* languageProblemCount {
14+
* languageName
15+
* problemsSolved
16+
* }
17+
* }
18+
* }
19+
* `;
20+
* ```
21+
*/
22+
const query = `
23+
query languageStats($username: String!) {
24+
matchedUser(username: $username) {
25+
languageProblemCount {
26+
languageName
27+
problemsSolved
28+
}
29+
}
30+
}
31+
`;
32+
33+
34+
export default query;

GQL_Queries/recentAcSubmit.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* GraphQL query to fetch recent Accepted (AC) submissions of a user.
3+
*
4+
* @param $username - The username of the user whose submissions are to be fetched.
5+
* @param $limit - The maximum number of submissions to fetch.
6+
*
7+
* @returns An object containing the following fields for each submission:
8+
* - title: The title of the problem.
9+
* - titleSlug: The URL-friendly slug of the problem title.
10+
* - timestamp: The timestamp when the submission was made.
11+
* - statusDisplay: The display status of the submission.
12+
* - lang: The programming language used for the submission.
13+
*/
14+
const query = `#graphql
15+
query getACSubmissions ($username: String!, $limit: Int) {
16+
recentAcSubmissionList(username: $username, limit: $limit) {
17+
title
18+
titleSlug
19+
timestamp
20+
statusDisplay
21+
lang
22+
}
23+
}`;
24+
25+
export default query;

GQL_Queries/recentSubmit.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* GraphQL query to fetch recent submissions of a user.
3+
*
4+
* @param $username - The username of the user whose recent submissions are to be fetched.
5+
* @param $limit - The maximum number of recent submissions to fetch.
6+
*
7+
* @returns An object containing the following fields:
8+
* - title: The title of the submission.
9+
* - titleSlug: The slugified title of the submission.
10+
* - timestamp: The timestamp of the submission.
11+
* - statusDisplay: The status of the submission (e.g., Accepted, Wrong Answer).
12+
* - lang: The programming language used for the submission.
13+
*/
14+
const query = `#graphql
15+
query getRecentSubmissions($username: String!, $limit: Int) {
16+
recentSubmissionList(username: $username, limit: $limit) {
17+
title
18+
titleSlug
19+
timestamp
20+
statusDisplay
21+
lang
22+
}
23+
}`;
24+
25+
export default query;

GQL_Queries/userProfile.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* GraphQL query to fetch user profile information from LeetCode.
3+
*
4+
* This query retrieves various details about a user, including:
5+
*
6+
* - `allQuestionsCount`: The count of all questions categorized by difficulty.
7+
* - `matchedUser`: Detailed information about the matched user, including:
8+
* - `username`: The username of the user.
9+
* - `githubUrl`: The GitHub profile URL of the user.
10+
* - `twitterUrl`: The Twitter profile URL of the user.
11+
* - `linkedinUrl`: The LinkedIn profile URL of the user.
12+
* - `contributions`: The user's contributions, including points, question count, and testcase count.
13+
* - `profile`: The user's profile details, such as real name, avatar, birthday, ranking, reputation, websites, country, company, school, skills, about me, and star rating.
14+
* - `badges`: The badges earned by the user, including id, display name, icon, and creation date.
15+
* - `upcomingBadges`: The badges that the user is about to earn, including name and icon.
16+
* - `activeBadge`: The currently active badge of the user, including id, display name, icon, and creation date.
17+
* - `submitStats`: The user's submission statistics, including total and accepted submissions categorized by difficulty.
18+
* - `submissionCalendar`: The user's submission calendar.
19+
* - `recentSubmissionList`: The list of recent submissions by the user, including title, title slug, timestamp, status display, and language.
20+
*
21+
* @param {string} $username - The username of the user whose profile is to be fetched.
22+
*/
23+
const query = `#graphql
24+
query getUserProfile($username: String!) {
25+
allQuestionsCount {
26+
difficulty
27+
count
28+
}
29+
matchedUser(username: $username) {
30+
username
31+
githubUrl
32+
twitterUrl
33+
linkedinUrl
34+
contributions {
35+
points
36+
questionCount
37+
testcaseCount
38+
}
39+
profile {
40+
realName
41+
userAvatar
42+
birthday
43+
ranking
44+
reputation
45+
websites
46+
countryName
47+
company
48+
school
49+
skillTags
50+
aboutMe
51+
starRating
52+
}
53+
badges {
54+
id
55+
displayName
56+
icon
57+
creationDate
58+
}
59+
upcomingBadges {
60+
name
61+
icon
62+
}
63+
activeBadge {
64+
id
65+
displayName
66+
icon
67+
creationDate
68+
}
69+
submitStats {
70+
totalSubmissionNum {
71+
difficulty
72+
count
73+
submissions
74+
}
75+
acSubmissionNum {
76+
difficulty
77+
count
78+
submissions
79+
}
80+
}
81+
submissionCalendar
82+
}
83+
recentSubmissionList(username: $username, limit: 20) {
84+
title
85+
titleSlug
86+
timestamp
87+
statusDisplay
88+
lang
89+
}
90+
}`;
91+
92+
export default query;

app/actions/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ export async function signout() {
4747
const supabase = await createClient();
4848
await supabase.auth.signOut();
4949
revalidatePath('/', 'layout');
50-
redirect('/auth/signin');
50+
redirect('/');
5151
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Response } from 'express';
2+
3+
const fetchDataRawFormat = async (
4+
options: { username: string },
5+
res: Response,
6+
query: string
7+
) => {
8+
try {
9+
10+
const response = await fetch('https://leetcode.com/graphql', {
11+
method: 'POST',
12+
headers: {
13+
'Content-Type': 'application/json',
14+
Referer: 'https://leetcode.com',
15+
},
16+
body: JSON.stringify({
17+
query: query,
18+
variables: {
19+
username: options.username,
20+
},
21+
}),
22+
});
23+
24+
const result = await response.json();
25+
if (!response.ok) {
26+
console.error(`HTTP error! status: ${response.status}`);
27+
}
28+
if (result.errors) {
29+
return res.send(result);
30+
}
31+
32+
return res.json(result.data);
33+
} catch (err) {
34+
console.error('Error: ', err);
35+
return res.send(err);
36+
}
37+
};
38+
39+
export default fetchDataRawFormat;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Response } from 'express';
2+
import { UserData } from '../../../../types/typeInterfaces';
3+
4+
const fetchUserDetails = async (
5+
options: { username: string; limit: number },
6+
res: Response,
7+
formatData: (data: UserData) => {},
8+
query: string
9+
) => {
10+
try {
11+
const response = await fetch('https://leetcode.com/graphql', {
12+
method: 'POST',
13+
headers: {
14+
'Content-Type': 'application/json',
15+
Referer: 'https://leetcode.com',
16+
},
17+
body: JSON.stringify({
18+
query: query,
19+
variables: {
20+
username: options.username, //username required
21+
limit: options.limit, //only for submission
22+
},
23+
}),
24+
});
25+
26+
const result = await response.json();
27+
28+
if (result.errors) {
29+
return res.send(result);
30+
}
31+
32+
return res.json(formatData(result.data));
33+
} catch (err) {
34+
console.error('Error: ', err);
35+
return res.send(err);
36+
}
37+
};
38+
39+
export default fetchUserDetails;

app/api/leetcode/controllers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as fetchUserDetails } from './fetchUserDetails';
2+
export { default as fetchDataRawFormat } from './fetchDataRawFormat';

0 commit comments

Comments
 (0)