Thanks, I managed to use the data in LocalStorage and its work well. I also manage to put the data in my component, but when the data changes in the LS, my component doesn´t render again
This is my dashboard State
import reflex as rx
from ..services.shiftServices import startShiftServices, endShiftServices,checkOpenShiftStatusService, getUnfinishdOrders
from ..services.productServices import getAllProductsServices
from ..services.orderServices import cleanData, createOrderServices,getAllOrdersServices, updateFinishtime, getDataCard
from ..services.waitinglistservices import getNumOrdersServices
from ..models.product_model import Products
from ..models.dashboardModel import OrderType
import json
class DashboardState(rx.State):
shift_status:bool
products: list[Products] = []
orderTable: list[OrderType] = []
order_data: dict = {}
openedDialog: bool = False
productconfirm: list[dict]=[]
statusCards: dict={}
lsprep: str=rx.LocalStorage("{}",sync=True)
lsret: str=rx.LocalStorage("{}",sync=True)
def closeDialog(self):
self.openedDialog=False
def handle_submit(self,data={}):
items=cleanData(data)
self.productconfirm = items.productos
self.order_data=items
self.openedDialog = True
def waitingOrders(self):
ordenes= getNumOrdersServices(self.orderTable)
self.lsprep= json.dumps(ordenes[0])
self.lsret= json.dumps(ordenes[1])
@rx.event(background=True)
async def createOrder(self):
async with self:
createOrderServices(self.order_data)
self.openedDialog = False
self.orderTable= await getAllOrdersServices()
self.statusCards = getDataCard()
self.waitingOrders()
My other Waiting State for the other page
import reflex as rx
from ..states.dashboardState import DashboardState
import json
class WaitState(rx.State):
prep:list=[]
ready:list=[]
async def getLsdata(self):
state= await self.get_state(DashboardState)
self.prep= self.get_value(json.loads(state.lsprep))
self.ready= self.get_value(json.loads(state.lsret))
print(self.prep)
print(self.ready)
async def onload(self):
await self.getLsdata()
And the component of my page
import reflex as rx
from ..styles.styles import Size
from ..states.waintingState import WaitState
def waiting() -> rx.Component:
return rx.vstack(
rx.heading(
"Listado de Ordenes",
font_size=Size.VERY_BIG,
text_align="center",
width="100%",
margin=Size.MEDIUM
),
rx.button("Prueba",
on_click=WaitState.onload),
rx.grid(
rx.vstack(
rx.heading("En Preparacion",
text_align="center",
font_size=Size.BIG,
width="100%",
margin="20px 0px",
border_bottom="2px solid black"),
rx.box(
rx.cond(
WaitState.prep,
rx.foreach(
WaitState.prep,orderitem
)
)
),
width="100%",
height="100vh"
),
rx.vstack(
rx.heading("Para Retirar",
text_align="center",
font_size=Size.BIG,
width="100%",
margin="20px 0px",
border_bottom="2px solid black"),
rx.box(
rx.cond(
WaitState.ready,
rx.foreach(
WaitState.ready,orderitem
)
)
),
width="100%",
height="100vh"
),
columns="2",
#spacing="9",
width="100%"
)
)
def orderitem(x: rx.Var[int])->rx.Component:
return rx.text(x)
I need that this component change everytime the LS changes.
thanks
[mod edit: formatting]