Rank 2: Process
I will just be straight on.
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 2: Process
I will just be straight on.
Rank 2: Process
did this to fetch the label
Rank 2: Process
if (!item.hidden) { return ( <div key={item.path} className="text-white"> {item.submenu ? ( <> <button //Sub Menus onClick={toggleSubMenu} className={`flex flex-row items-center p-2 rounded-lg w-full justify-between hover:bg-white hover:text-black ${ pathname.includes(item.path) ? 'bg-white text-black ' : '' }`} > <div className="flex flex-row space-x-4 items-center"> {item.icon} <span className="font-semibold text-xl flex">{item.title}</span> </div>
<div className={`${subMenuOpen ? 'rotate-180' : ''} flex`}> <Icon icon="lucide:chevron-down" width="24" height="24" /> </div> </button>
{subMenuOpen && ( <div className="my-2 ml-12 flex flex-col space-y-4"> {item.subMenuItems?.map((subItem, idx) => { return ( <Link key={idx} href={subItem.path} className={`${ subItem.path === pathname ? 'font-bold' : '' }`} > <span>{subItem.title}</span> </Link> ); })} </div> )} </> ) : ( //Menus <Link href={item.path} className={`flex flex-row space-x-4 items-center p-2 rounded-lg hover:bg-zinc-100 hover:text-black ${ item.path === pathname ? 'bg-zinc-100 text-black' : '' }`} > {item.icon} <span className="font-semibold text-xl flex">{item.title}</span> </Link> )} </div> ); }This is Sidebar.tsx, currently hides items that has the hidden variable in my constants which is:
import { Icon } from '@iconify/react';import { SideNavItem } from './types';import appwriteService from "@/appwrite/config";
const userLabel = appwriteService.getCurrentUserLabel();
export const SIDENAV_ITEMS: SideNavItem[] = [ { title: 'Home', path: '/dashboard/home', icon: <Icon icon="lucide:home" width="24" height="24" />, }, { title: 'Controls', path: '/dashboard/controls', icon: <Icon icon="lucide:folder" width="24" height="24" />, hidden: true, }, { title: 'Messages', path: '/dashboard/messages', icon: <Icon icon="lucide:mail" width="24" height="24" />, }, { title: 'Settings', path: '/dashboard/settings', icon: <Icon icon="lucide:settings" width="24" height="24" />, submenu: true, subMenuItems: [ { title: 'Account', path: '/dashboard/settings/account' }, { title: 'Privacy', path: '/dashboard/settings/privacy' }, ], },Rank 2: Process
now i'm stuck not knowing what to do
Rank 2: Process
I gave up on this before, but came back in order to finish it. I'm lost
No worries. We all start somewhere!
Rank 2: Process
But if you dont mind, how would i exactly going to test account.get to be shown in the logs
Do you know how to log things?
Rank 2: Process
That should be the console in the site itself
Yes. Do you know how to log things there?
Rank 2: Process
Not sure though. The only thing that comes in my mind is running it and just checking the console
Yes but how to do make stuff show up in the console?
Rank 2: Process
That i do not know
Have you used console.log()?
Have you done any courses or tutorials on JavaScript?
Rank 2: Process
Forgot about that, and as for js. I haven't actually. Only watched a few and know how some of the function works when i look at it but can't really do it when i try to implement it, i really have no knowledge on making websites. Its just that my professor gave me this without him teaching us basic java or javascript properly
console.log() is used to log things. So you can call account.get() and then log the result to see the details about it.
Anyways, you should probably learn some more programming or JavaScript basics before trying to learn react
Rank 2: Process
apologies for not replying for like a week. Homeworks and tp's are a hassle. Just got back on this project again, it does show the user having the label ['admin']. Now I tried a couple of things so that it will actually be only shown if the user is an admin. But still couldn't work it around.
Rank 2: Process
now I was wondering whether i have to do something with this, cause I am sure that im lacking something. Its just basically checking for the label only
Rank 2: Process
tried playing around with useEffect but I still can't find a solution
Rank 2: Process
Wait. I might have actually done it. But its late to appear? on the console, its printing "User is an admin" 12 times
How is setUserRole() related to item?
Rank 2: Process
i used a useState so i can set a boolean whether the user does or does not have the label admin.
I managed to make it work but its mapping through every single item slowly. Its printing 12 times and the controls element will show at around the 5th print
Please share your of your code
Mapping through? Where are you fetching the user?
Rank 2: Process
Sorry for not replying for a couple of days. Do you mind setting this as solved? I managed to make things work now