From 353a2dfc3bc3bb7ad3743929b6f9591a9b4519d8 Mon Sep 17 00:00:00 2001 From: Stalin Date: Sun, 19 Apr 2026 18:03:24 +0530 Subject: [PATCH] fix(dashboard): hide endpoint paths in recent activity UI --- backend/routes/dashboard.py | 48 ++++++++++++++++----- frontend/app/coding/join/page.tsx | 2 +- frontend/app/courses/[courseId]/page.tsx | 4 +- frontend/app/dashboard/page.tsx | 54 +++++++++++++++++++++++- frontend/app/quiz-join/page.tsx | 2 +- 5 files changed, 95 insertions(+), 15 deletions(-) diff --git a/backend/routes/dashboard.py b/backend/routes/dashboard.py index e09409a..13075ad 100644 --- a/backend/routes/dashboard.py +++ b/backend/routes/dashboard.py @@ -377,25 +377,53 @@ def get_recent_activity(): if not any(segment in path for segment in ["/api/quizzes", "/api/exam", "/api/coding", "/api/courses", "/api/auth"]): continue + if any(noise in path for noise in ["/api/auth/verify-token", "/api/health"]): + continue + log_type = "activity" - title = f"{method} {path}" - description = f"API activity on {path}" + title = "Learning activity" + description = "Activity recorded" if "/api/quizzes" in path: log_type = "quiz" - title = "Quiz activity" - description = f"{method} {path}" + if "/join-room" in path: + title = "Joined quiz room" + description = "Entered a live quiz room" + elif "/submit-answer" in path or "/submit" in path: + title = "Attempted quiz question" + description = "Submitted a quiz answer" + else: + title = "Quiz activity" + description = "Interacted with quizzes" elif "/api/exam" in path or "/api/coding" in path: log_type = "coding" - title = "Coding activity" - description = f"{method} {path}" + if "/join-exam" in path: + title = "Joined coding exam" + description = "Entered a coding exam" + elif "/submit" in path: + title = "Submitted coding solution" + description = "Submitted code for evaluation" + else: + title = "Coding activity" + description = "Interacted with coding workspace" elif "/api/courses" in path: log_type = "course" - title = "Course activity" - description = f"{method} {path}" + if "/activity" in path: + title = "Course activity" + description = "Visited or started a course lesson" + elif "/complete" in path: + title = "Completed lesson" + description = "Marked lesson as completed" + else: + title = "Course activity" + description = "Viewed course content" elif "/api/auth" in path: log_type = "auth_login" - title = "Authentication activity" - description = f"{method} {path}" + if "/login" in path or "/verify" in path: + title = "Authentication activity" + description = "Signed in to account" + else: + title = "Account activity" + description = "Authentication event recorded" activities.append({ "id": str(item.get("_id", uuid.uuid4())), diff --git a/frontend/app/coding/join/page.tsx b/frontend/app/coding/join/page.tsx index 53e308e..01553b5 100644 --- a/frontend/app/coding/join/page.tsx +++ b/frontend/app/coding/join/page.tsx @@ -27,7 +27,7 @@ export default function JoinExam() { setLoading(true) try { - const token = localStorage.getItem("openlearnx_jwt_token") + const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token") const storedUserRaw = localStorage.getItem("openlearnx_user") const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null diff --git a/frontend/app/courses/[courseId]/page.tsx b/frontend/app/courses/[courseId]/page.tsx index cc9bfcf..89f0514 100644 --- a/frontend/app/courses/[courseId]/page.tsx +++ b/frontend/app/courses/[courseId]/page.tsx @@ -64,7 +64,7 @@ export default function CoursePage() { const logCourseActivity = async (action: "view" | "start" | "lesson_view", lessonId?: string) => { try { - const token = localStorage.getItem("openlearnx_jwt_token") + const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token") await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/activity`, { method: "POST", headers: { @@ -242,7 +242,7 @@ export default function CoursePage() { const markComplete = async () => { try { - const token = localStorage.getItem("openlearnx_jwt_token") + const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token") if (selectedLessonId) { await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/lessons/${selectedLessonId}/complete`, { method: "POST", diff --git a/frontend/app/dashboard/page.tsx b/frontend/app/dashboard/page.tsx index 345eed7..83d6430 100644 --- a/frontend/app/dashboard/page.tsx +++ b/frontend/app/dashboard/page.tsx @@ -155,7 +155,59 @@ export default function DashboardPage() { return fakeMarkers.some((marker) => text.includes(marker)) } - const realActivities = recentActivity.filter((item) => !isPlaceholderActivity(item)) + const isEndpointText = (value: string) => /^(get|post|put|patch|delete)\s+\/api\//i.test(String(value || "").trim()) + + const normalizeActivityForUI = (item: ActivityData): ActivityData | null => { + const rawTitle = String(item.title || "") + const rawDescription = String(item.description || "") + const lower = `${rawTitle} ${rawDescription}`.toLowerCase() + + if (lower.includes("/api/auth/verify-token")) { + return null + } + + let title = rawTitle + let description = rawDescription + + if (isEndpointText(rawTitle) || isEndpointText(rawDescription)) { + if (lower.includes("/api/quizzes") && lower.includes("join-room")) { + title = "Joined quiz room" + description = "Entered a live quiz room" + } else if (lower.includes("/api/quizzes") && (lower.includes("submit-answer") || lower.includes("/submit"))) { + title = "Attempted quiz question" + description = "Submitted a quiz answer" + } else if ((lower.includes("/api/exam") || lower.includes("/api/coding")) && lower.includes("join-exam")) { + title = "Joined coding exam" + description = "Entered a coding exam" + } else if ((lower.includes("/api/exam") || lower.includes("/api/coding")) && lower.includes("submit")) { + title = "Submitted coding solution" + description = "Submitted code for evaluation" + } else if (lower.includes("/api/courses") && lower.includes("complete")) { + title = "Completed lesson" + description = "Marked lesson as completed" + } else if (lower.includes("/api/courses")) { + title = "Course activity" + description = "Viewed or continued course learning" + } else if (lower.includes("/api/auth")) { + title = "Authentication activity" + description = "Signed in to account" + } else { + title = "Learning activity" + description = "Activity recorded" + } + } + + return { + ...item, + title, + description, + } + } + + const realActivities = recentActivity + .map((item) => normalizeActivityForUI(item)) + .filter((item): item is ActivityData => Boolean(item)) + .filter((item) => !isPlaceholderActivity(item)) const visibleActivities = showAllActivities ? realActivities : realActivities.slice(0, 6) const handleProfileUpdate = async () => { diff --git a/frontend/app/quiz-join/page.tsx b/frontend/app/quiz-join/page.tsx index 70d1d5d..9d67dc1 100644 --- a/frontend/app/quiz-join/page.tsx +++ b/frontend/app/quiz-join/page.tsx @@ -49,7 +49,7 @@ export default function QuizJoinPage() { setLoading(true) try { - const token = localStorage.getItem("openlearnx_jwt_token") + const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token") const storedUserRaw = localStorage.getItem("openlearnx_user") const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null