File tree 3 files changed +43
-0
lines changed
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ def blog_post_add_form() -> rx.Component:
39
39
def blog_post_edit_form () -> rx .Component :
40
40
post = BlogEditFormState .post
41
41
title = post .title
42
+ publish_active = post .publish_active
42
43
post_content = BlogEditFormState .post_content
43
44
return rx .form (
44
45
rx .box (
@@ -70,6 +71,34 @@ def blog_post_edit_form() -> rx.Component:
70
71
height = '50vh' ,
71
72
width = '100%' ,
72
73
),
74
+ rx .flex (
75
+ rx .switch (
76
+ default_checked = BlogEditFormState .post_publish_active ,
77
+ on_change = BlogEditFormState .set_post_publish_active ,
78
+ name = 'publish_active' ,
79
+ ),
80
+ rx .text ("Publish Active" ),
81
+ spacing = "2" ,
82
+ ),
83
+ rx .cond (
84
+ BlogEditFormState .post_publish_active ,
85
+ rx .box (
86
+ rx .hstack (
87
+ rx .input (
88
+ type = 'date' ,
89
+ name = 'publish_date' ,
90
+ width = '100%'
91
+ ),
92
+ rx .input (
93
+ type = 'time' ,
94
+ name = 'publish_time' ,
95
+ width = '100%'
96
+ ),
97
+ width = '100%'
98
+ ),
99
+ width = '100%'
100
+ )
101
+ ),
73
102
rx .button ("Submit" , type = "submit" ),
74
103
),
75
104
on_submit = BlogEditFormState .handle_submit ,
Original file line number Diff line number Diff line change @@ -28,5 +28,6 @@ class BlogPostModel(rx.Model, table=True):
28
28
},
29
29
nullable = False
30
30
)
31
+ publish_active : bool = False
31
32
# publish_date
32
33
# publish_time
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ class BlogPostState(rx.State):
14
14
posts : List ['BlogPostModel' ] = []
15
15
post : Optional ['BlogPostModel' ] = None
16
16
post_content : str = ""
17
+ post_publish_active : bool = False
17
18
18
19
@rx .var
19
20
def blog_post_id (self ):
@@ -46,6 +47,7 @@ def get_post_detail(self):
46
47
self .post_content = ""
47
48
return
48
49
self .post_content = self .post .content
50
+ self .post_publish_active = self .post .publish_active
49
51
# return
50
52
51
53
@@ -108,6 +110,17 @@ class BlogEditFormState(BlogPostState):
108
110
def handle_submit (self , form_data ):
109
111
self .form_data = form_data
110
112
post_id = form_data .pop ('post_id' )
113
+ publish_date = None
114
+ if 'publish_date' in form_data :
115
+ publish_date = form_data .pop ('publish_date' )
116
+ publish_time = None
117
+ if 'publish_time' in form_data :
118
+ publish_time = form_data .pop ('publish_time' )
119
+ print (publish_date , publish_time )
120
+ publish_active = False
121
+ if 'publish_active' in form_data :
122
+ publish_active = form_data .pop ('publish_active' ) == "on"
111
123
updated_data = {** form_data }
124
+ updated_data ['publish_active' ] = publish_active
112
125
self .save_post_edits (post_id , updated_data )
113
126
return self .to_blog_post ()
You can’t perform that action at this time.
0 commit comments