Skip to content

Refactor/improve UI - #35

Closed
Dkain-icl wants to merge 3 commits into
mainfrom
refactor/improve-ui
Closed

Refactor/improve UI#35
Dkain-icl wants to merge 3 commits into
mainfrom
refactor/improve-ui

Conversation

@Dkain-icl

@Dkain-icl Dkain-icl commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Lecturers can preview quizzes in a dedicated view, including question types, correct answers, and available AI explanations.
    • Draft quizzes can be published directly from the preview screen.
    • Completed quiz generation now opens the quiz preview automatically.
    • Quiz pages support preview mode through the preview link.
  • Improvements
    • Simplified lecturer practice navigation and page layout.
    • Updated the student practice area with a refreshed full-page header and layout.
    • Removed the lecturer student-results panel and preview modal.

Extract quiz preview modal from practice-view into dedicated full-page component (quiz-preview-view.tsx). Replace modal-based state management with URL-based navigation (?preview=true&id=quizId). Add Explanation field to QuizQuestion interface. Simplify header styling in student and lecturer practice views for consistency. This improves component reusability and enables direct sharing of quiz preview links.
Remove the 'Kết quả sinh viên' (student results) tab and associated table displaying quiz completion data. This includes removing the results panel UI, the Tabs.List navigation, and the mockStudentResults data.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Quiz previewing moves from an embedded lecturer modal to a routed preview page. The page selects preview or student mode via a query parameter, fetches and renders quiz details, supports draft publishing, adds optional question explanations, and updates lecturer and student practice layouts.

Quiz Preview Flow

Layer / File(s) Summary
Preview route and question contract
frontend/src/api/quiz.ts, frontend/src/app/[role]/practice/quiz/page.tsx
QuizQuestion now supports optional explanations, and the quiz route selects QuizPreviewView or TakeQuizView from preview=true.
Lecturer preview rendering
frontend/src/components/lecturer/quiz/quiz-preview-view.tsx
QuizPreviewView fetches quiz details, renders question options and explanations, handles loading and errors, and exposes draft publishing.
Lecturer navigation and view cleanup
frontend/src/hooks/lecturer/use-practice.ts, frontend/src/components/lecturer/practice/practice-view.tsx
Quiz generation and preview actions navigate to the preview route; the lecturer results tab and embedded preview modal are removed.
Student practice layout
frontend/src/components/student/practice/student-practice-view.tsx
The student practice page receives a sticky icon header and revised container and tab layout.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Lecturer
  participant TeacherPracticeView
  participant usePractice
  participant QuizPreviewPage
  participant QuizPreviewView
  participant quizApi
  Lecturer->>TeacherPracticeView: select quiz preview
  TeacherPracticeView->>usePractice: preview quiz
  usePractice->>QuizPreviewPage: navigate with preview=true
  QuizPreviewPage->>QuizPreviewView: render lecturer preview
  QuizPreviewView->>quizApi: fetch quiz detail
  quizApi-->>QuizPreviewView: return questions and metadata
Loading

Possibly related PRs

Suggested reviewers: uging265

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is too generic and does not convey the specific quiz preview and practice UI changes in this pull request. Rename it to summarize the main change, such as adding lecturer quiz preview navigation and refining practice/quiz UI.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/improve-ui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
frontend/src/components/lecturer/quiz/quiz-preview-view.tsx (2)

23-244: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

New file already exceeds the 200-line guideline (244 lines).

Consider extracting the per-question rendering (options list + AI explanation block, roughly lines 148-239) into a separate QuestionCard/QuestionExplanation component to keep QuizPreviewView focused on data loading and page layout.

As per coding guidelines, "Avoid God files; keep files under 200 lines and focused on a single purpose."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/lecturer/quiz/quiz-preview-view.tsx` around lines 23
- 244, The new QuizPreviewView exceeds the 200-line guideline and mixes page
state management with detailed question rendering. Extract the questions.map
rendering, including option display and AI explanation markup, into a focused
QuestionCard component (and optionally a small QuestionExplanation component),
then render QuestionCard from QuizPreviewView while preserving the existing
question, option, and explanation behavior.

Source: Coding guidelines


149-153: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fallback (q as any).x casts undermine the typed QuizQuestion contract.

QuizQuestion (in api/quiz.ts) already defines ID, Content, QuestionType, Options, and now Explanation. Falling back to (q as any).id/.explanation/etc. bypasses that contract and hides real API mismatches instead of surfacing them.

Please confirm the backend response for quiz questions actually matches the PascalCase QuizQuestion shape; if it doesn't, the mapping should be normalized once in quizApi.getQuizDetail rather than defensively at every call site.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/lecturer/quiz/quiz-preview-view.tsx` around lines 149
- 153, Remove the `(q as any)` lowercase-property fallbacks from the question
mapping in the quiz preview component and rely on the typed `QuizQuestion`
fields. Verify the backend response and, if it uses a different shape, normalize
it once in `quizApi.getQuizDetail` so callers receive the PascalCase
`QuizQuestion` contract.
frontend/src/hooks/lecturer/use-practice.ts (1)

178-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove leftover modal-era state (previewQuiz, isViewQuizOpen) now that preview navigation is route-based. Both files still declare/destructure this state even though the only consumer (the in-page preview modal) has been deleted.

  • frontend/src/hooks/lecturer/use-practice.ts#L178-L182: drop previewQuiz/setPreviewQuiz and isViewQuizOpen/setIsViewQuizOpen (and the no-op setIsViewQuizOpen(false) in handlePublishQuiz) from the hook's state and return value.
  • frontend/src/components/lecturer/practice/practice-view.tsx#L626-L627: stop destructuring isViewQuizOpen, setIsViewQuizOpen, previewQuiz from usePractice() since nothing in the remaining JSX uses them.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/hooks/lecturer/use-practice.ts` around lines 178 - 182, Remove
the unused previewQuiz/setPreviewQuiz and isViewQuizOpen/setIsViewQuizOpen
state, including the no-op setIsViewQuizOpen(false) call in handlePublishQuiz,
from usePractice and its return value. In
frontend/src/hooks/lecturer/use-practice.ts:178-182, update the hook state and
returned API; in
frontend/src/components/lecturer/practice/practice-view.tsx:626-627, stop
destructuring these values from usePractice.
frontend/src/components/lecturer/practice/practice-view.tsx (1)

120-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Single-panel Tabs with no Tabs.List is now vestigial.

After removing the "results" tab, only Tabs.Panel value="dashboard" remains and there's no Tabs.List to switch tabs. The Tabs/activeTab machinery no longer serves a purpose here; consider replacing with a plain wrapper div.

♻️ Suggested simplification
-      <div className="max-w-6xl mx-auto px-6 pb-12 space-y-8">
-        <Tabs value={activeTab} onChange={setActiveTab} variant="outline" radius="lg">
-
-          <Tabs.Panel value="dashboard" className="space-y-8">
-            <div className="grid gap-6 lg:grid-cols-3">
+      <div className="max-w-6xl mx-auto px-6 pb-12 space-y-8">
+        <div className="space-y-8">
+          <div className="grid gap-6 lg:grid-cols-3">

(and close the corresponding wrapper instead of </Tabs.Panel>/</Tabs>)

Also applies to: 430-433

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/lecturer/practice/practice-view.tsx` around lines 120
- 121, Remove the vestigial Tabs and activeTab machinery from the practice view,
since only the dashboard panel remains and no tab list can switch it. Replace
the outer Tabs wrapper with a plain div and update the matching closing wrapper
around the dashboard content, removing the corresponding Tabs.Panel closing tag
while preserving the panel’s contents.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/app/`[role]/practice/quiz/page.tsx:
- Around line 9-18: Update QuizPageContent so the preview=true branch renders
QuizPreviewView only for authorized lecturers/quiz owners, using the existing
role or authorization context; all other users must fall back to TakeQuizView.
Preserve the current non-preview behavior.

In `@frontend/src/components/lecturer/quiz/quiz-preview-view.tsx`:
- Around line 29-50: Ensure the useEffect handling quizId clears loading when
the query parameter is missing, so the component reaches the “Không thể tải
thông tin bài tập.” branch instead of remaining stuck. Update the early-return
path before fetchDetail in the quiz detail loading flow, while preserving the
existing fetch behavior for valid quizId values.

---

Nitpick comments:
In `@frontend/src/components/lecturer/practice/practice-view.tsx`:
- Around line 120-121: Remove the vestigial Tabs and activeTab machinery from
the practice view, since only the dashboard panel remains and no tab list can
switch it. Replace the outer Tabs wrapper with a plain div and update the
matching closing wrapper around the dashboard content, removing the
corresponding Tabs.Panel closing tag while preserving the panel’s contents.

In `@frontend/src/components/lecturer/quiz/quiz-preview-view.tsx`:
- Around line 23-244: The new QuizPreviewView exceeds the 200-line guideline and
mixes page state management with detailed question rendering. Extract the
questions.map rendering, including option display and AI explanation markup,
into a focused QuestionCard component (and optionally a small
QuestionExplanation component), then render QuestionCard from QuizPreviewView
while preserving the existing question, option, and explanation behavior.
- Around line 149-153: Remove the `(q as any)` lowercase-property fallbacks from
the question mapping in the quiz preview component and rely on the typed
`QuizQuestion` fields. Verify the backend response and, if it uses a different
shape, normalize it once in `quizApi.getQuizDetail` so callers receive the
PascalCase `QuizQuestion` contract.

In `@frontend/src/hooks/lecturer/use-practice.ts`:
- Around line 178-182: Remove the unused previewQuiz/setPreviewQuiz and
isViewQuizOpen/setIsViewQuizOpen state, including the no-op
setIsViewQuizOpen(false) call in handlePublishQuiz, from usePractice and its
return value. In frontend/src/hooks/lecturer/use-practice.ts:178-182, update the
hook state and returned API; in
frontend/src/components/lecturer/practice/practice-view.tsx:626-627, stop
destructuring these values from usePractice.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b54fd6ad-6bec-4379-a020-5df66a3bd7d3

📥 Commits

Reviewing files that changed from the base of the PR and between 33db500 and bbdf0c2.

📒 Files selected for processing (6)
  • frontend/src/api/quiz.ts
  • frontend/src/app/[role]/practice/quiz/page.tsx
  • frontend/src/components/lecturer/practice/practice-view.tsx
  • frontend/src/components/lecturer/quiz/quiz-preview-view.tsx
  • frontend/src/components/student/practice/student-practice-view.tsx
  • frontend/src/hooks/lecturer/use-practice.ts

Comment on lines +9 to +18
function QuizPageContent() {
const searchParams = useSearchParams();
const isPreview = searchParams.get("preview") === "true";

if (isPreview) {
return <QuizPreviewView />;
}

return <TakeQuizView />;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "useParams|role" frontend/src/app -g '*layout*'

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 262


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== quiz page ==\n'
sed -n '1,220p' frontend/src/app/[role]/practice/quiz/page.tsx

printf '\n== role layout ==\n'
sed -n '1,220p' frontend/src/app/[role]/layout.tsx

printf '\n== role shell ==\n'
sed -n '1,260p' frontend/src/components/layout/role-shell.tsx

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 2510


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== auth client refs ==\n'
rg -n "auth-client|Better Auth|session|role" frontend/src -g '!**/node_modules/**' | sed -n '1,220p'

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 21172


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== backend quiz api refs ==\n'
rg -n "publishQuiz|getQuizDetail|quizApi" . -g '!**/node_modules/**' | sed -n '1,220p'

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 2801


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== frontend/src/app/[role]/practice/quiz/page.tsx =='
sed -n '1,220p' frontend/src/app/[role]/practice/quiz/page.tsx

echo
echo '== frontend/src/app/[role]/layout.tsx =='
sed -n '1,220p' frontend/src/app/[role]/layout.tsx

echo
echo '== frontend/src/components/layout/role-shell.tsx =='
sed -n '1,260p' frontend/src/components/layout/role-shell.tsx

echo
echo '== role/auth references =='
rg -n "RoleShell|useSession|session|role" frontend/src/components frontend/src/app frontend/lib -g '!**/node_modules/**' | sed -n '1,260p'

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 21169


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in \
  frontend/src/app/[role]/layout.tsx \
  frontend/src/app/[role]/practice/quiz/page.tsx \
  frontend/src/components/layout/role-shell.tsx
do
  echo "### $f"
  wc -l "$f"
  sed -n '1,220p' "$f"
  echo
done

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 2735


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,240p' frontend/src/components/lecturer/quiz/quiz-preview-view.tsx

Repository: UGing265/SWD392_Chatbot_RAG

Length of output: 9422


Gate quiz preview to lecturers

RoleShell already blocks cross-role routing, but this page still opens QuizPreviewView for any user on their own /[role]/practice/quiz route when preview=true is present. That exposes lecturer-only quiz content/correct answers and the publish control; restrict the branch to lecturers/quiz owners or split it out of the shared page.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/app/`[role]/practice/quiz/page.tsx around lines 9 - 18, Update
QuizPageContent so the preview=true branch renders QuizPreviewView only for
authorized lecturers/quiz owners, using the existing role or authorization
context; all other users must fall back to TakeQuizView. Preserve the current
non-preview behavior.

Source: Coding guidelines

Comment on lines +29 to +50
const quizId = searchParams.get("id");
const [quizDetail, setQuizDetail] = useState<QuizDetailResponse | null>(null);
const [loading, setLoading] = useState(true);
const [publishing, setPublishing] = useState(false);

useEffect(() => {
if (!quizId) return;

const fetchDetail = async () => {
try {
setLoading(true);
const data = await quizApi.getQuizDetail(quizId);
setQuizDetail(data);
} catch (err) {
console.error("Failed to fetch quiz detail:", err);
} finally {
setLoading(false);
}
};

fetchDetail();
}, [quizId]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Stuck spinner when id query param is missing.

loading starts true and is only set to false inside fetchDetail, which never runs if quizId is falsy — the component is stuck on the loading state forever instead of falling through to the "Không thể tải thông tin bài tập." error branch.

🐛 Proposed fix
   useEffect(() => {
-    if (!quizId) return;
+    if (!quizId) {
+      setLoading(false);
+      return;
+    }
     
     const fetchDetail = async () => {

Also applies to: 70-92

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/lecturer/quiz/quiz-preview-view.tsx` around lines 29
- 50, Ensure the useEffect handling quizId clears loading when the query
parameter is missing, so the component reaches the “Không thể tải thông tin bài
tập.” branch instead of remaining stuck. Update the early-return path before
fetchDetail in the quiz detail loading flow, while preserving the existing fetch
behavior for valid quizId values.

@Dkain-icl Dkain-icl closed this Jul 16, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant