@@ -34,14 +34,15 @@ class CustomComponentGalleryState(rx.State):
3434 # Added available limits for the number of items per page
3535 limits : list [str ] = ["10" , "20" , "50" , "100" ]
3636
37- @rx .event
38- def fetch_components_list (self ):
37+ @rx .event ( background = True , temporal = True )
38+ async def fetch_components_list (self ):
3939 try :
40- response = httpx .get (
41- f"{ os .getenv ('RCC_ENDPOINT' )} /custom-components/gallery"
42- )
43- response .raise_for_status ()
44- component_list = response .json ()
40+ async with httpx .AsyncClient () as client :
41+ response = await client .get (
42+ f"{ os .getenv ('RCC_ENDPOINT' )} /custom-components/gallery"
43+ )
44+ response .raise_for_status ()
45+ component_list = response .json ()
4546 except (httpx .HTTPError , json .JSONDecodeError ) as ex :
4647 print (f"Internal error: failed to fetch components list due to: { ex } " )
4748 return
@@ -55,12 +56,13 @@ def fetch_components_list(self):
5556 ]
5657 c ["download_url" ] = package_url (c ["package_name" ])
5758
58- self .original_components_list = component_list
59- self .number_of_rows = len (component_list )
60- self .total_pages = (
61- self .number_of_rows + self .current_limit - 1
62- ) // self .current_limit
63- self .paginate ()
59+ async with self :
60+ self .original_components_list = component_list
61+ self .number_of_rows = len (component_list )
62+ self .total_pages = (
63+ self .number_of_rows + self .current_limit - 1
64+ ) // self .current_limit
65+ yield CustomComponentGalleryState .paginate ()
6466
6567 @rx .event
6668 def paginate (self ) -> None :
0 commit comments