fix(frontend): dynamically determine menus based on mode

fixes next/previous buttons leading to menus not usually visible in noob mode
This commit is contained in:
Viren070
2025-08-29 21:29:00 +01:00
parent df97bde45c
commit 5e969ff2dc
2 changed files with 32 additions and 12 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import { cn } from '@/components/ui/core/styling';
import { VerticalMenu, VerticalMenuItem } from '@/components/ui/vertical-menu';
import { Button } from '@/components/ui/button';
import { useStatus } from '@/context/status';
import { useMenu, MenuId, VALID_MENUS } from '@/context/menu';
import { useMenu, MenuId } from '@/context/menu';
import { useUserData } from '@/context/userData';
import { ConfigModal } from '@/components/config-modal';
import {
+31 -11
View File
@@ -1,8 +1,9 @@
'use client';
import React, { createContext, useContext, useState, useEffect } from 'react';
import { useMode } from './mode';
export const VALID_MENUS = [
const VALID_MENUS = [
'about',
'services',
'addons',
@@ -14,6 +15,8 @@ export const VALID_MENUS = [
'save-install',
];
const PRO_ONLY_MENUS = ['proxy', 'sorting'];
export type MenuId = (typeof VALID_MENUS)[number];
type MenuContextType = {
@@ -35,12 +38,30 @@ const MenuContext = createContext<MenuContextType>({
});
export function MenuProvider({ children }: { children: React.ReactNode }) {
const { mode } = useMode();
const menus = [
'about',
'services',
'addons',
'filters',
'sorting',
'formatter',
'proxy',
'miscellaneous',
'save-install',
].filter((menu) => {
if (mode === 'noob') {
return !PRO_ONLY_MENUS.includes(menu);
}
return true;
});
// Get initial menu from URL or default to 'about'
const initialMenu = (() => {
if (typeof window !== 'undefined') {
const url = new URL(window.location.href);
const menu = url.searchParams.get('menu');
if (menu && VALID_MENUS.includes(menu)) {
if (menu && menus.includes(menu)) {
return menu as MenuId;
}
}
@@ -55,20 +76,19 @@ export function MenuProvider({ children }: { children: React.ReactNode }) {
setInternalSelectedMenu(menu);
};
const firstMenu = VALID_MENUS[0];
const lastMenu = VALID_MENUS[VALID_MENUS.length - 1];
const firstMenu = menus[0];
const lastMenu = menus[menus.length - 1];
const nextMenu = () => {
const currentIndex = VALID_MENUS.indexOf(selectedMenu);
const nextIndex = (currentIndex + 1) % VALID_MENUS.length;
setSelectedMenu(VALID_MENUS[nextIndex]);
const currentIndex = menus.indexOf(selectedMenu);
const nextIndex = (currentIndex + 1) % menus.length;
setSelectedMenu(menus[nextIndex]);
};
const previousMenu = () => {
const currentIndex = VALID_MENUS.indexOf(selectedMenu);
const previousIndex =
(currentIndex - 1 + VALID_MENUS.length) % VALID_MENUS.length;
setSelectedMenu(VALID_MENUS[previousIndex]);
const currentIndex = menus.indexOf(selectedMenu);
const previousIndex = (currentIndex - 1 + menus.length) % menus.length;
setSelectedMenu(menus[previousIndex]);
};
// Update URL when menu changes