Files
full_encoach_platform/frontend/src/pages/student/ProficiencyProfile.tsx
Yamen Ahmad e1f059069f feat(i18n,rtl): full Arabic localization + RTL sweep across all layouts
Frontend
- i18n: install tailwindcss-rtl, Cairo font, RTL-aware direction in index.css.
- Language toggle: localize aria-label / menu label, persist choice, update
  document dir synchronously.
- Sidebar: add `side` prop so the drawer pins to the right in RTL; wire up
  AdminLmsLayout, RoleLayout (student/teacher) and AppSidebar to pass
  side = i18n.dir() === 'rtl' ? 'right' : 'left'.
- AdminLmsLayout: convert every nav item from hard-coded title to titleKey,
  translate group labels (incl. the collapsible Training), breadcrumbs,
  user menu (Profile / Settings / Logout), help button and toggle aria
  labels; replace physical mr-/right- utilities with logical me-/end-.
- AI components (AiTipBanner, AiInsightsPanel, AiAlertBanner, AiSearchBar,
  AiAssistantDrawer): apply dir="auto" at the container level, localize
  titles, loading / error / empty states.
- Dashboards (admin / student / teacher): wrap numeric values in <bdi>,
  localize dates via ar-EG, fix flex direction for KPI and assignment cards.
- UI primitives (breadcrumb, calendar, carousel, dropdown-menu, menubar,
  context-menu, pagination, sidebar): flip chevrons in RTL via a scoped
  CSS rule, swap pl-/pr-/ml-/mr- for ps-/pe-/ms-/me-.
- Add logical-direction helpers and bidirectional isolation classes.

Locales
- Expand en.ts and ar.ts with full `nav`, `sidebarGroup`, `breadcrumb`,
  `userMenu`, `chrome`, `ai`, and dashboard key sets; keep key parity.

API client
- `api-client.ts` reads the active language from localStorage/i18n and sends
  `Accept-Language` on every request so the backend can localize AI output.

Backend (encoach_ai)
- openai_service: add _LANGUAGE_NAMES, normalize_language, language-aware
  system prompt injection for every OpenAI call.
- coach_service + controllers (coach_controller, ai_controller): thread
  the requested language from headers / user locale down to OpenAIService.
- ai_feedback: fix latent registry error by pointing course_id at op.course
  instead of the non-existent encoach.course.

Other
- .gitignore: ignore runtime odoo logs and local caches.

Made-with: Cursor
2026-04-19 18:13:16 +04:00

118 lines
5.3 KiB
TypeScript

import { useParams, useNavigate } from "react-router-dom";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { Badge } from "@/components/ui/badge";
import { ArrowRight, Target, TrendingUp } from "lucide-react";
import { useProficiency } from "@/hooks/queries";
function getMasteryColor(mastery: number): string {
if (mastery >= 80) return "text-green-600";
if (mastery >= 60) return "text-blue-600";
if (mastery >= 40) return "text-yellow-600";
if (mastery >= 20) return "text-orange-600";
return "text-red-600";
}
function getMasteryBg(mastery: number): string {
if (mastery >= 80) return "bg-green-100";
if (mastery >= 60) return "bg-blue-100";
if (mastery >= 40) return "bg-yellow-100";
if (mastery >= 20) return "bg-orange-100";
return "bg-red-100";
}
export default function ProficiencyProfile() {
const { subjectId } = useParams<{ subjectId: string }>();
const navigate = useNavigate();
const { data: proficiencies = [], isLoading } = useProficiency({ subject_id: Number(subjectId) });
if (isLoading) return <div className="flex items-center justify-center min-h-[400px]"><div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary" /></div>;
const domains = [...new Set(proficiencies.map(p => p.domain_name))];
const overallMastery = proficiencies.length > 0 ? proficiencies.reduce((sum, p) => sum + p.mastery, 0) / proficiencies.length : 0;
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold">Proficiency Profile</h1>
<p className="text-muted-foreground">Your knowledge map across all topics.</p>
</div>
<div className="flex gap-2">
<Button variant="outline" onClick={() => navigate(`/student/diagnostic/${subjectId}`)}>Retake Diagnostic</Button>
<Button onClick={() => navigate(`/student/plan/${subjectId}`)}>Learning Plan <ArrowRight className="ms-1 h-4 w-4 rtl:rotate-180" /></Button>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<Card>
<CardContent className="pt-6 text-center">
<Target className="h-8 w-8 mx-auto text-primary mb-2" />
<div className="text-3xl font-bold">{Math.round(overallMastery)}%</div>
<p className="text-sm text-muted-foreground">Overall Mastery</p>
</CardContent>
</Card>
<Card>
<CardContent className="pt-6 text-center">
<TrendingUp className="h-8 w-8 mx-auto text-green-500 mb-2" />
<div className="text-3xl font-bold">{proficiencies.filter(p => p.mastery >= 80).length}</div>
<p className="text-sm text-muted-foreground">Topics Mastered</p>
</CardContent>
</Card>
<Card>
<CardContent className="pt-6 text-center">
<div className="h-8 w-8 mx-auto text-orange-500 mb-2 text-2xl font-bold">{proficiencies.filter(p => p.mastery < 40).length}</div>
<p className="text-sm text-muted-foreground">Topics Needing Work</p>
</CardContent>
</Card>
</div>
{domains.map((domain) => {
const topics = proficiencies.filter(p => p.domain_name === domain);
const domainMastery = topics.reduce((s, t) => s + t.mastery, 0) / topics.length;
return (
<Card key={domain}>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-lg">{domain}</CardTitle>
<Badge variant="outline" className={getMasteryColor(domainMastery)}>{Math.round(domainMastery)}%</Badge>
</div>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
{topics.map((topic) => (
<div
key={topic.topic_id}
className={`p-3 rounded-lg border ${getMasteryBg(topic.mastery)} cursor-pointer hover:shadow-sm transition-shadow`}
onClick={() => navigate(`/student/topic/${topic.topic_id}`)}
>
<div className="flex items-center justify-between mb-1">
<span className="text-sm font-medium truncate">{topic.topic_name}</span>
<span className={`text-sm font-semibold ${getMasteryColor(topic.mastery)}`}>{Math.round(topic.mastery)}%</span>
</div>
<Progress value={topic.mastery} className="h-1.5" />
<div className="flex items-center justify-between mt-1">
<Badge variant="secondary" className="text-xs">{topic.mastery_level}</Badge>
</div>
</div>
))}
</div>
</CardContent>
</Card>
);
})}
{proficiencies.length === 0 && (
<Card>
<CardContent className="text-center py-12 text-muted-foreground">
<p>No proficiency data yet. Take a diagnostic assessment first.</p>
<Button className="mt-4" onClick={() => navigate(`/student/diagnostic/${subjectId}`)}>Start Diagnostic</Button>
</CardContent>
</Card>
)}
</div>
);
}