File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 8
8
class ContactState (rx .State ):
9
9
form_data : dict = {}
10
10
did_submit : bool = False
11
+ timeleft : int = 5
12
+
13
+ @rx .var
14
+ def timeleft_label (self ):
15
+ if self .timeleft < 1 :
16
+ return "No time left"
17
+ return f"{ self .timeleft } seconds"
11
18
12
19
@rx .var
13
20
def thank_you (self ):
@@ -24,8 +31,17 @@ async def handle_submit(self, form_data: dict):
24
31
await asyncio .sleep (2 )
25
32
self .did_submit = False
26
33
yield
34
+
35
+ async def start_timer (self ):
36
+ while self .timeleft > 0 :
37
+ await asyncio .sleep (1 )
38
+ self .timeleft -= 1
39
+ yield
27
40
28
- @rx .page (route = navigation .routes .CONTACT_US_ROUTE )
41
+ @rx .page (
42
+ on_load = ContactState .start_timer ,
43
+ route = navigation .routes .CONTACT_US_ROUTE
44
+ )
29
45
def contact_page () -> rx .Component :
30
46
my_form = rx .form (
31
47
rx .vstack (
@@ -64,6 +80,7 @@ def contact_page() -> rx.Component:
64
80
)
65
81
my_child = rx .vstack (
66
82
rx .heading ("Contact Us" , size = "9" ),
83
+ rx .text (ContactState .timeleft_label ),
67
84
rx .cond (ContactState .did_submit , ContactState .thank_you , "" ),
68
85
rx .desktop_only (
69
86
rx .box (
You can’t perform that action at this time.
0 commit comments