Skip to content

Commit 1b166b3

Browse files
committed
Wire up new progress tracker
1 parent 6e562f0 commit 1b166b3

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

src/Dashboard.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { HiOutlineExternalLink } from "react-icons/hi";
33
import { IoArrowBack } from "react-icons/io5";
44
import { MdOutlineRefresh } from "react-icons/md";
55
import { Link, useParams } from "react-router";
6-
import { ProblemSet, useGetProblemSetsQuery } from "./api/queries/get_problem_sets";
6+
import { Exercise, useGetExercisesQuery } from "./api/queries/get_exercises";
77
import { useGetUserQuery } from "./api/queries/get_user";
88
import { useGetUserProgressQuery } from "./api/queries/get_user_progress";
99
import Spinner from "./components/Spinner";
1010

1111
type UserProblemSetStatus = string;
1212

1313
function Dashboard() {
14-
let { username } = useParams();
14+
const { username } = useParams();
1515

1616
const {
1717
data: user,
@@ -46,22 +46,22 @@ function Dashboard() {
4646
const {
4747
data: problemSets,
4848
isLoading: isProblemSetsLoading,
49-
} = useGetProblemSetsQuery();
49+
} = useGetExercisesQuery();
5050

5151
const problemSetGroups = useMemo(() => {
5252
if (isProblemSetsLoading || problemSets == null) {
53-
return new Map<string, ProblemSet[]>();
53+
return new Map<string, Exercise[]>();
5454
}
5555

56-
const repoGroups = new Map<string, ProblemSet[]>();
56+
const repoGroups = new Map<string, Exercise[]>();
5757
for (const repo of problemSets) {
58-
for (const topic of repo.topics) {
59-
if (topic !== "problem-set") {
60-
if (parsedUserProgress.has(repo.name)) {
61-
if (!repoGroups.has(topic)) {
62-
repoGroups.set(topic, [])
58+
for (const tag of repo.tags) {
59+
if (tag !== "problem-set") {
60+
if (parsedUserProgress.has(repo.exercise_name)) {
61+
if (!repoGroups.has(tag)) {
62+
repoGroups.set(tag, [])
6363
}
64-
repoGroups.get(topic)!.push(repo)
64+
repoGroups.get(tag)!.push(repo)
6565
}
6666
}
6767
}
@@ -124,11 +124,11 @@ function Dashboard() {
124124
</thead>
125125
<tbody>
126126
{value
127-
.filter(problemSet => parsedUserProgress.has(problemSet.name))
128-
.map(problemSet => (
129-
<tr key={problemSet.id}>
130-
<td className="border border-gray-300 px-4 py-2 text-left"><a target="_blank" href={problemSet.html_url}><code className="underline text-blue-800">{problemSet.name}</code></a></td>
131-
<td className="border border-gray-300 px-4 py-2 text-left">{parsedUserProgress.get(problemSet.name)}</td>
127+
.filter(exercise => parsedUserProgress.has(exercise.exercise_name))
128+
.map((exercise, idx) => (
129+
<tr key={idx}>
130+
<td className="border border-gray-300 px-4 py-2 text-left"><a target="_blank" href={`https://git-mastery.github.io/exercises/${exercise.exercise_name.replace("_", "-")}`}><code className="underline text-blue-800">{exercise.exercise_name}</code></a></td>
131+
<td className="border border-gray-300 px-4 py-2 text-left">{parsedUserProgress.get(exercise.exercise_name)}</td>
132132
</tr>
133133
))}
134134
</tbody>

src/api/queries/get_exercises.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from "axios"
2+
import { useQuery } from "react-query"
3+
4+
export interface Exercise {
5+
exercise_name: string;
6+
tags: string[];
7+
}
8+
9+
export const getExercises = async () => {
10+
try {
11+
const result = await axios.get<Exercise[]>("https://raw.githubusercontent.com/git-mastery/exercises/refs/heads/gh-pages/exercises.json");
12+
return result.data;
13+
} catch {
14+
return [];
15+
}
16+
}
17+
18+
export const useGetExercisesQuery = () => {
19+
return useQuery<Exercise[]>({
20+
queryKey: ["get-exercises"],
21+
queryFn: () => getExercises(),
22+
});
23+
}
24+

src/api/queries/get_problem_sets.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/api/queries/get_user_progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface UserProgress {
88

99
export const getUserProgress = async (userId: number) => {
1010
try {
11-
const result = await axios.get<UserProgress[]>(`https://raw.githubusercontent.com/git-mastery/progress-tracker/refs/heads/main/progress/${userId}.json`);
11+
const result = await axios.get<UserProgress[]>(`https://raw.githubusercontent.com/git-mastery/progress/refs/heads/tracker/students/${userId}.json`);
1212
return result.data;
1313
} catch {
1414
return null;

0 commit comments

Comments
 (0)