8
8
class CubeModel (Model ):
9
9
color : str = "#ff0000" # Default red color
10
10
rotation_speed : float = 1.0 # Default rotation speed
11
+ first_time : bool = True # First time start
11
12
12
13
13
14
# Initialize FastTEA app
@@ -148,22 +149,53 @@ def update(msg: Msg, model: CubeModel) -> tuple[CubeModel, Optional[Cmd]]:
148
149
if msg .action == "changeColor" :
149
150
new_model = CubeModel (
150
151
color = msg .value ,
151
- rotation_speed = model .rotation_speed
152
+ rotation_speed = model .rotation_speed ,
153
+ first_time = False
152
154
)
153
155
return new_model , Cmd (action = "setColor" , payload = {"color" : msg .value })
154
156
155
157
elif msg .action == "changeSpeed" :
156
158
speed = float (msg .value )
157
159
new_model = CubeModel (
158
160
color = model .color ,
159
- rotation_speed = speed
161
+ rotation_speed = speed ,
162
+ first_time = False
160
163
)
161
164
return new_model , Cmd (action = "setSpeed" , payload = {"speed" : speed })
162
165
163
166
return model , None
164
167
165
168
169
+
166
170
# View function
171
+ def view_controlls (model : CubeModel ) -> Element :
172
+ # Controls card
173
+ return card ({"id" :"view_controlls" }, [
174
+ div ({}, [
175
+ label ({"for" : "colorPicker" }, "Cube Color:" ),
176
+ input_ ({
177
+ "type" : "color" ,
178
+ "id" : "colorPicker" ,
179
+ "value" : model .color ,
180
+ "onChange" : "changeColor" ,
181
+ "hx-target" : "#view_controlls"
182
+ }, [])
183
+ ]),
184
+ div ({"style" : "margin-top: 1rem;" }, [
185
+ label ({"for" : "speedSlider" }, f"Rotation Speed ({ model .rotation_speed } x):" ),
186
+ input_ ({
187
+ "type" : "range" ,
188
+ "id" : "speedSlider" ,
189
+ "min" : "0" ,
190
+ "max" : "3" ,
191
+ "step" : "0.1" ,
192
+ "value" : str (model .rotation_speed ),
193
+ "onChange" : "changeSpeed" ,
194
+ "hx-target" : "#view_controlls"
195
+ ""
196
+ }, [])
197
+ ])
198
+ ])
167
199
@app .view
168
200
def view (model : CubeModel ) -> Element :
169
201
return container ({}, [
@@ -180,33 +212,8 @@ def view(model: CubeModel) -> Element:
180
212
}, [])
181
213
])
182
214
]),
183
- # Controls card
184
- card ({}, [
185
- div ({}, [
186
- label ({"for" : "colorPicker" }, "Cube Color:" ),
187
- input_ ({
188
- "type" : "color" ,
189
- "id" : "colorPicker" ,
190
- "value" : model .color ,
191
- "onChange" : "changeColor"
192
- }, [])
193
- ]),
194
- div ({"style" : "margin-top: 1rem;" }, [
195
- label ({"for" : "speedSlider" }, f"Rotation Speed ({ model .rotation_speed } x):" ),
196
- input_ ({
197
- "type" : "range" ,
198
- "id" : "speedSlider" ,
199
- "min" : "0" ,
200
- "max" : "3" ,
201
- "step" : "0.1" ,
202
- "value" : str (model .rotation_speed ),
203
- "onChange" : "changeSpeed"
204
- }, [])
205
- ])
206
- ])
215
+ view_controlls (model )
207
216
])
208
- ])
209
-
210
-
217
+ ]) if model .first_time else view_controlls (model )
211
218
212
219
app .run ()
0 commit comments