Spaces:
Sleeping
Sleeping
Update components/Sidebar.tsx
Browse files- components/Sidebar.tsx +7 -3
components/Sidebar.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
|
| 2 |
import React, { useState, useEffect } from 'react';
|
| 3 |
-
import { LayoutDashboard, Users, BookOpen, GraduationCap, Settings, LogOut, FileText, School, UserCog, Palette, X, Building, Gamepad2, CalendarCheck, UserCircle, MessageSquare, Bot, ArrowUp, ArrowDown, Save } from 'lucide-react';
|
| 4 |
import { UserRole } from '../types';
|
| 5 |
import { api } from '../services/api';
|
| 6 |
|
|
@@ -23,10 +23,12 @@ interface MenuItem {
|
|
| 23 |
export const Sidebar: React.FC<SidebarProps> = ({ currentView, onChangeView, userRole, onLogout, isOpen, onClose }) => {
|
| 24 |
const currentUser = api.auth.getCurrentUser();
|
| 25 |
const canSeeAI = userRole === UserRole.ADMIN || (userRole === UserRole.TEACHER && currentUser?.aiAccess);
|
|
|
|
| 26 |
|
| 27 |
// Default Items
|
| 28 |
const defaultItems: MenuItem[] = [
|
| 29 |
{ id: 'dashboard', label: '工作台', icon: LayoutDashboard, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
|
|
|
|
| 30 |
{ id: 'ai-assistant', label: 'AI 智能助教', icon: Bot, roles: canSeeAI ? [UserRole.ADMIN, UserRole.TEACHER] : [] },
|
| 31 |
{ id: 'attendance', label: '考勤管理', icon: CalendarCheck, roles: [UserRole.TEACHER, UserRole.PRINCIPAL] },
|
| 32 |
{ id: 'games', label: '互动教学', icon: Gamepad2, roles: [UserRole.TEACHER, UserRole.STUDENT] },
|
|
@@ -118,8 +120,10 @@ export const Sidebar: React.FC<SidebarProps> = ({ currentView, onChangeView, use
|
|
| 118 |
</div>
|
| 119 |
<nav className="space-y-1 px-2">
|
| 120 |
{menuItems.map((item, idx) => {
|
| 121 |
-
if (!item.roles.includes(userRole)) return null;
|
| 122 |
if (item.id === 'ai-assistant' && !canSeeAI) return null;
|
|
|
|
|
|
|
| 123 |
|
| 124 |
const Icon = item.icon;
|
| 125 |
const isActive = currentView === item.id;
|
|
@@ -167,4 +171,4 @@ export const Sidebar: React.FC<SidebarProps> = ({ currentView, onChangeView, use
|
|
| 167 |
</div>
|
| 168 |
</>
|
| 169 |
);
|
| 170 |
-
};
|
|
|
|
| 1 |
|
| 2 |
import React, { useState, useEffect } from 'react';
|
| 3 |
+
import { LayoutDashboard, Users, BookOpen, GraduationCap, Settings, LogOut, FileText, School, UserCog, Palette, X, Building, Gamepad2, CalendarCheck, UserCircle, MessageSquare, Bot, ArrowUp, ArrowDown, Save, UserCheck } from 'lucide-react';
|
| 4 |
import { UserRole } from '../types';
|
| 5 |
import { api } from '../services/api';
|
| 6 |
|
|
|
|
| 23 |
export const Sidebar: React.FC<SidebarProps> = ({ currentView, onChangeView, userRole, onLogout, isOpen, onClose }) => {
|
| 24 |
const currentUser = api.auth.getCurrentUser();
|
| 25 |
const canSeeAI = userRole === UserRole.ADMIN || (userRole === UserRole.TEACHER && currentUser?.aiAccess);
|
| 26 |
+
const isHomeroom = userRole === UserRole.TEACHER && !!currentUser?.homeroomClass;
|
| 27 |
|
| 28 |
// Default Items
|
| 29 |
const defaultItems: MenuItem[] = [
|
| 30 |
{ id: 'dashboard', label: '工作台', icon: LayoutDashboard, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
|
| 31 |
+
{ id: 'my-class', label: '我的班级', icon: UserCheck, roles: isHomeroom ? [UserRole.TEACHER] : [] },
|
| 32 |
{ id: 'ai-assistant', label: 'AI 智能助教', icon: Bot, roles: canSeeAI ? [UserRole.ADMIN, UserRole.TEACHER] : [] },
|
| 33 |
{ id: 'attendance', label: '考勤管理', icon: CalendarCheck, roles: [UserRole.TEACHER, UserRole.PRINCIPAL] },
|
| 34 |
{ id: 'games', label: '互动教学', icon: Gamepad2, roles: [UserRole.TEACHER, UserRole.STUDENT] },
|
|
|
|
| 120 |
</div>
|
| 121 |
<nav className="space-y-1 px-2">
|
| 122 |
{menuItems.map((item, idx) => {
|
| 123 |
+
if (item.roles.length > 0 && !item.roles.includes(userRole)) return null;
|
| 124 |
if (item.id === 'ai-assistant' && !canSeeAI) return null;
|
| 125 |
+
// Special check for 'my-class': only homeroom teachers
|
| 126 |
+
if (item.id === 'my-class' && !isHomeroom) return null;
|
| 127 |
|
| 128 |
const Icon = item.icon;
|
| 129 |
const isActive = currentView === item.id;
|
|
|
|
| 171 |
</div>
|
| 172 |
</>
|
| 173 |
);
|
| 174 |
+
};
|