55import reflex as rx
66import reflex_chakra as rc
77from pcweb .components .docpage .navbar .state import NavbarState
8- from .state import SidebarState , SidebarItem
8+ from .state import SidebarState , SideBarItem , SideBarBase
99import reflex_chakra as rc
1010
1111from .sidebar_items .learn import learn , frontend , backend , hosting
1717from .sidebar_items .recipes import recipes
1818from pcweb .styles .colors import c_color
1919
20+
2021def sidebar_link (* children , ** props ):
2122 """Create a sidebar link that closes the sidebar when clicked."""
2223 return rx .link (
@@ -28,7 +29,7 @@ def sidebar_link(*children, **props):
2829
2930
3031def sidebar_leaf (
31- item : SidebarItem ,
32+ item : SideBarItem ,
3233 url : str ,
3334) -> rx .Component :
3435 """Get the leaf node of the sidebar."""
@@ -124,7 +125,7 @@ def sidebar_icon(name):
124125
125126
126127def sidebar_item_comp (
127- item : SidebarItem ,
128+ item : SideBarItem ,
128129 index : list [int ],
129130 url : str ,
130131):
@@ -221,6 +222,18 @@ def get_prev_next(url):
221222 return None , None
222223
223224
225+ def filter_out_non_sidebar_items (items : list [SideBarBase ]) -> list [SideBarItem ]:
226+ """Filter out non-sidebar items making sure only SideBarItems are present.
227+
228+ Args:
229+ items: The items to filter.
230+
231+ Return:
232+ The filtered side bar items.
233+ """
234+ return [item for item in items if isinstance (item , SideBarItem )]
235+
236+
224237def sidebar_category (name : str , url : str , icon : str , index : int ):
225238 return rx .el .li (
226239 rx .link (
@@ -267,7 +280,13 @@ def sidebar_category(name: str, url: str, icon: str, index: int):
267280 )
268281
269282
270- def create_sidebar_section (section_title , section_url , items , index , url ):
283+ def create_sidebar_section (
284+ section_title : str ,
285+ section_url : str ,
286+ items : list [SideBarItem ],
287+ index : rx .Var [list [str ]] | list [str ],
288+ url : rx .Var [str ] | str ,
289+ ) -> rx .Component :
271290 # Check if the section has any nested sections (Like the Other Libraries Section)
272291 nested = any (len (child .children ) > 0 for item in items for child in item .children )
273292 # Make sure the index is a list
@@ -313,7 +332,6 @@ def sidebar_comp(
313332 tutorials_index : list [int ],
314333 width : str = "100%" ,
315334):
316-
317335 from pcweb .pages .docs .recipes_overview import overview
318336 from pcweb .pages .docs .library import library
319337 from pcweb .pages .docs .custom_components import custom_components
@@ -351,12 +369,12 @@ def sidebar_comp(
351369 create_sidebar_section (
352370 "User Interface" ,
353371 ui .overview .path ,
354- frontend ,
372+ filter_out_non_sidebar_items ( frontend ) ,
355373 frontend_index ,
356374 url ,
357375 ),
358376 create_sidebar_section (
359- "State" , state .overview .path , backend , backend_index , url
377+ "State" , state .overview .path , filter_out_non_sidebar_items ( backend ) , backend_index , url
360378 ),
361379 create_sidebar_section (
362380 "Hosting" ,
0 commit comments