|
80 | 80 | (dom/a #js {:href (str "event/" code)} code))
|
81 | 81 |
|
82 | 82 |
|
83 |
| -;; CLOODLE CODE COMPONENT |
| 83 | +;; Component that shows the Cloodle-link of the saved event |
84 | 84 | (defcomponent cloodle-code [code owner]
|
85 | 85 |
|
86 | 86 | (render-state [this state]
|
|
311 | 311 | (let [payload {:event-id (:_id app-state) :participant new-participant}]
|
312 | 312 | payload))
|
313 | 313 |
|
| 314 | +;; Component for submitting a new vote to an event |
314 | 315 | (defcomponent vote-component [{:keys [app-state new-participant options]} owner]
|
315 | 316 |
|
316 | 317 | (init-state [_]
|
|
319 | 320 | (will-mount [_]
|
320 | 321 | (let [save (om/get-state owner :save-vote-chan)]
|
321 | 322 |
|
322 |
| - |
323 |
| - ;; SAVE VOTE |
| 323 | + ;; Saving the vote |
324 | 324 | (go (loop []
|
325 | 325 | (let [new-participant (<! save)
|
326 | 326 | payload (vote->save-payload new-participant @app-state)]
|
327 | 327 |
|
328 |
| - |
| 328 | + ;; TODO: Assuming response contains the new participant data, show it in the UI |
329 | 329 | (go
|
330 | 330 | (let [response (<! (http/post "api/event/vote" {:json-params payload}))
|
331 | 331 | status (:status response)]))
|
332 | 332 |
|
333 | 333 | (recur))))))
|
334 | 334 |
|
335 | 335 |
|
336 |
| - (render-state [this state] |
337 |
| - |
338 |
| - (dom/div #js {:style #js {:border "solid black 1px"}} |
339 |
| - |
340 |
| - (dom/div #js {:className "row form-group"} |
341 |
| - |
342 |
| - (dom/label #js {:htmlFor "participant-name" |
343 |
| - :className "col-sm-2 control-label"} |
344 |
| - "Name") |
345 |
| - |
346 |
| - (dom/div #js {:className "col-sm-6"} |
347 |
| - (dom/input #js {:id "name" |
348 |
| - :className "form-control" |
349 |
| - :type "text" |
350 |
| - :value (:name new-participant) |
351 |
| - :ref "participant-name" |
352 |
| - :onChange (fn [e] |
353 |
| - (om/transact! new-participant :name (fn [_] (.. e -target -value)))) |
354 |
| - }))) |
355 |
| - |
356 |
| - |
357 |
| - (apply dom/div nil |
358 |
| - (om/build-all option-slider |
359 |
| - (map |
360 |
| - (fn [option-cursor] {:option option-cursor |
361 |
| - :selections (:selections new-participant)}) |
362 |
| - options)) ) |
363 |
| - |
364 |
| - |
365 |
| - |
366 |
| - (dom/button #js {:type "button" |
367 |
| - :className "btn btn-success" |
368 |
| - :onClick (fn [e] (put! (:save-vote-chan state) @new-participant))} |
369 |
| - "Save vote")))) |
370 |
| - |
| 336 | + (render-state [this state] |
| 337 | + |
| 338 | + (ddom/div {:className "vote-component"} |
| 339 | + (ddom/h2 "Vote on the options") |
| 340 | + (ddom/p "Use the sliders to express your preferences.") |
| 341 | + (ddom/div {:className "row form-group"} |
| 342 | + |
| 343 | + (ddom/label {:htmlFor "participant-name" |
| 344 | + :className "col-sm-2 control-label"} |
| 345 | + "Who are you?") |
| 346 | + |
| 347 | + (ddom/div {:className "col-sm-4"} |
| 348 | + (ddom/input {:id "name" |
| 349 | + :className "form-control" |
| 350 | + :type "text" |
| 351 | + :value (:name new-participant) |
| 352 | + :ref "participant-name" |
| 353 | + :onChange (fn [e] |
| 354 | + (om/transact! |
| 355 | + new-participant |
| 356 | + :name (fn [_] (.. e -target -value))))}))) |
| 357 | + |
| 358 | + |
| 359 | + (ddom/div |
| 360 | + (om/build-all option-slider |
| 361 | + (map |
| 362 | + (fn [option-cursor] {:option option-cursor |
| 363 | + :selections (:selections new-participant)}) |
| 364 | + options))) |
| 365 | + |
| 366 | + (ddom/button {:type "button" |
| 367 | + :className "btn btn-success" |
| 368 | + :onClick (fn [e] (put! (:save-vote-chan state) @new-participant))} |
| 369 | + "Save vote")))) |
371 | 370 |
|
372 | 371 |
|
373 | 372 | (defcomponent participant-component [cursors owner]
|
|
410 | 409 |
|
411 | 410 |
|
412 | 411 | (defn saved? [app-state]
|
413 |
| - (print (str "Checking if saved: " (:cloodle-code app-state))) |
| 412 | + "Tells whether the event has been saved or is still in the process of being created. |
| 413 | + Based on the presence of :cloodle-code key in the app-state map" |
414 | 414 | (not (string/blank? (:cloodle-code app-state))))
|
415 | 415 |
|
416 | 416 | (defcomponent main-page [app-state owner]
|
|
0 commit comments