From 8bb7a61f56707fcbbef245985d82872f3f931cab Mon Sep 17 00:00:00 2001 From: Nicolai <47388378+Ph0en1XXX@users.noreply.github.com> Date: Mon, 9 Mar 2026 18:43:34 +0300 Subject: [PATCH] fix(sidebar): restore custom Enlight sidebar items after v2.46.0 merge Two bugs fixed: 1. updateSidebarLinks() was called AFTER custom add functions, resetting sidebarLinks.value and erasing all custom items 2. Custom items were pushed as flat objects but the template expects grouped structure { label, hideLabel, items: [] } Refactored all custom functions into a single addEnlightCustomItems() that builds a proper group and pushes it AFTER updateSidebarLinks(). Items: LeaderBoard, MyPoints, ChatGPT (role-based), MyChild, Profile. Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/Sidebar/AppSidebar.vue | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/frontend/src/components/Sidebar/AppSidebar.vue b/frontend/src/components/Sidebar/AppSidebar.vue index 933f9011..4e2ffbc6 100644 --- a/frontend/src/components/Sidebar/AppSidebar.vue +++ b/frontend/src/components/Sidebar/AppSidebar.vue @@ -589,59 +589,56 @@ const setUpOnboarding = () => { } } -const addMyPoints = () => { +const addEnlightCustomItems = () => { const roles = userResource.data?.roles || [] - if (roles.includes('LMS Student') || roles.includes('LMS Schoolchild')) { - sidebarLinks.value.push({ - label: __('My points'), - icon: 'Award', - to: 'MyPoints', - activeFor: [], - }) - } -} + const customItems = [] -const addLeaderBoard = () => { + // LeaderBoard — для всех авторизованных if (user) { - sidebarLinks.value.push({ + customItems.push({ label: __('Leader Board'), icon: 'Trophy', to: 'LeaderBoard', activeFor: [], }) } -} -const addChatGPT = () => { - const roles = userResource.data?.roles || [] - let URL = '' - let nameLabel = '' - if (roles.includes('LMS Schoolchild') || roles.includes('LMS Student') || roles.includes('Course Creator')) { - if (roles.includes('LMS Schoolchild')) { - URL = 'chatgpt-schoolchild' - nameLabel = __('ChatGPT for Schoolers') - } else if (roles.includes('LMS Student')) { - URL = 'chatgpt-schoolchild' - nameLabel = __('ChatGPT for Students') - } else if (roles.includes('Course Creator')) { - URL = 'ai-teachers' - nameLabel = __('ChatGPT for Teachers') - } + // My Points — для студентов и школьников + if (roles.includes('LMS Student') || roles.includes('LMS Schoolchild')) { + customItems.push({ + label: __('My points'), + icon: 'Award', + to: 'MyPoints', + activeFor: [], + }) + } - sidebarLinks.value.push({ - label: nameLabel, + // ChatGPT — роль-зависимая ссылка + let chatURL = '' + let chatLabel = '' + if (roles.includes('LMS Schoolchild')) { + chatURL = 'chatgpt-schoolchild' + chatLabel = __('ChatGPT for Schoolers') + } else if (roles.includes('LMS Student')) { + chatURL = 'chatgpt-schoolchild' + chatLabel = __('ChatGPT for Students') + } else if (roles.includes('Course Creator')) { + chatURL = 'ai-teachers' + chatLabel = __('ChatGPT for Teachers') + } + if (chatURL) { + customItems.push({ + label: chatLabel, icon: 'Cpu', - to: URL, + to: chatURL, external: true, activeFor: [], }) } -} -const addMyChild = () => { - const roles = userResource.data?.roles || [] + // My Child — для родителей if (roles.includes('Parent')) { - sidebarLinks.value.push({ + customItems.push({ label: __('My Child'), icon: 'User', to: 'my-child', @@ -649,39 +646,45 @@ const addMyChild = () => { external: true, }) } -} -const addProfile = () => { - const roles = userResource.data?.roles || [] + // Profile — роль-зависимый профиль if (roles.includes('LMS Student')) { - sidebarLinks.value.push({ + customItems.push({ label: __('Student Profile'), - icon: 'Home', + icon: 'UserRound', to: 'StudentProfile', activeFor: [], }) } else if (roles.includes('LMS Schoolchild')) { - sidebarLinks.value.push({ + customItems.push({ label: __('Schoolchildren Profile'), - icon: 'Home', + icon: 'UserRound', to: 'SchoolchildrenProfile', activeFor: [], }) } else if (roles.includes('Course Creator')) { - sidebarLinks.value.push({ + customItems.push({ label: __('Course Creator Profile'), - icon: 'Home', + icon: 'UserRound', to: 'CourseCreatorProfile', activeFor: [], }) - } else { - sidebarLinks.value.push({ + } else if (roles.includes('Parent')) { + customItems.push({ label: __('Parent Profile'), - icon: 'Home', + icon: 'UserRound', to: 'ParentProfile', activeFor: [], }) } + + if (customItems.length > 0) { + sidebarLinks.value.push({ + label: 'Enlight', + hideLabel: true, + items: customItems, + }) + } } watch(userResource, async () => { @@ -691,14 +694,11 @@ watch(userResource, async () => { isInstructor.value = userResource.data.is_instructor await programs.reload() setUpOnboarding() - - addMyPoints() - addLeaderBoard() - addChatGPT() - addMyChild() - addProfile() } updateSidebarLinks() + if (userResource.data) { + addEnlightCustomItems() + } }) watch(settingsStore.settings, () => {