Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client/src/module/student/learn/LearnHubPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ import {
type WeakArea,
} from "./components/RecommendationCard";
import api from "../../../lib/axios";
import { useAuthStore } from "../../../lib/auth.store";

export default function LearnHubPage() {
const [search, setSearch] = useState("");
const [weakAreas, setWeakAreas] = useState<WeakArea[]>([]);
const [loadingRecs, setLoadingRecs] = useState(true);
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
const userRole = useAuthStore((s) => s.user?.role);

useEffect(() => {
if (!isAuthenticated || userRole !== "STUDENT") {
setWeakAreas([]);
setLoadingRecs(false);
return;
}

api
.get<{ weakAreas: WeakArea[] }>("/student/recommendations")
.then((res) => setWeakAreas(res.data.weakAreas ?? []))
.catch(() => setWeakAreas([]))
.finally(() => setLoadingRecs(false));
}, []);
}, [isAuthenticated, userRole]);

const grouped = useMemo(() => {
const needle = search.trim().toLowerCase();
Expand Down
10 changes: 9 additions & 1 deletion client/src/module/student/roadmap/RoadmapCanvasPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import type {
} from "../../../lib/types";
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
import { queryKeys } from "../../../lib/query-keys";
import { useAuthStore } from "../../../lib/auth.store";

interface EnrollmentResponse {
enrollment: RoadmapEnrollment;
Expand Down Expand Up @@ -430,8 +431,15 @@ export default function RoadmapCanvasPage() {
const [weakTopicTitles, setWeakTopicTitles] = useState<Set<string>>(
new Set(),
);
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
const userRole = useAuthStore((s) => s.user?.role);

useEffect(() => {
if (!isAuthenticated || userRole !== "STUDENT") {
setWeakTopicTitles(new Set());
return;
}

api
.get<{
weakAreas: { type: string; topic: string; topicSlug?: string }[];
Expand All @@ -445,7 +453,7 @@ export default function RoadmapCanvasPage() {
setWeakTopicTitles(slugs);
})
.catch(() => {});
}, []);
}, [isAuthenticated, userRole]);

const toggleSection = useCallback((id: number) => {
setCollapsedSections((prev) => {
Expand Down
10 changes: 9 additions & 1 deletion client/src/module/student/roadmap/RoadmapDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import toast from "../../../components/ui/toast";
import type { RoadmapEnrollmentListItem } from "../../../lib/types";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { queryKeys } from "../../../lib/query-keys";
import { useAuthStore } from "../../../lib/auth.store";
import {
RecommendationCard,
type WeakArea,
Expand All @@ -31,14 +32,21 @@ export default function RoadmapDashboardPage() {
null,
);
const [weakAreas, setWeakAreas] = useState<WeakArea[]>([]);
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
const userRole = useAuthStore((s) => s.user?.role);
const queryClient = useQueryClient();

useEffect(() => {
if (!isAuthenticated || userRole !== "STUDENT") {
setWeakAreas([]);
return;
}

api
.get<{ weakAreas: WeakArea[] }>("/student/recommendations")
.then((res) => setWeakAreas(res.data.weakAreas ?? []))
.catch(() => {});
}, []);
}, [isAuthenticated, userRole]);
const {
data,
isLoading: loading,
Expand Down