Bulma modal, refactored and simplified.

beta
Philippe Pittoli 2024-02-17 05:31:55 +01:00
parent fefe6769f2
commit 1a0b48134e
3 changed files with 60 additions and 46 deletions

View File

@ -62,6 +62,8 @@ data AddUserInput
data Action
= HandleAddUserInput AddUserInput
| CancelModal
| AddUserAttempt
| SearchUserAttempt
| PreventSubmit Event
@ -109,7 +111,7 @@ initialState _ = { addUserForm: { login: "", admin: false, email: "", pass: "
render :: forall m. State -> H.ComponentHTML Action () m
render { addUserForm, searchUserForm, page, wsUp }
= case page of
Home -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
Home -> Bulma.modal "Hello lol" [Bulma.h3 "This is the body lol"] [routing_search_button, routing_add_button]
Search -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Search users", render_searchuser_form ] ]
, Bulma.column_ [ Bulma.h3 "Result", Bulma.subtitle "TODO" ] ]
Add -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
@ -117,26 +119,34 @@ render { addUserForm, searchUserForm, page, wsUp }
active = (if wsUp then (HP.enabled true) else (HP.disabled true))
render_adduser_form = HH.form
[ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" (up ADDUSER_INP_login) addUserForm.login active
, Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
, Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
, generic_button AddUserAttempt wsUp
render_adduser_form = Bulma.box [
HH.form
[ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" (up ADDUSER_INP_login) addUserForm.login active
, Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
, Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
, generic_button AddUserAttempt wsUp
]
]
up x = HandleAddUserInput <<< x
render_searchuser_form = HH.form
[ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" (up SEARCHUSER_INP_login) searchUserForm.login active
, Bulma.btn (show searchUserForm.admin) (HandleAddUserInput SEARCHUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
-- (up SEARCHUSER_INP_domain) searchUserForm.email active
, generic_button SearchUserAttempt wsUp
render_searchuser_form = Bulma.box [
HH.form
[ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" (up SEARCHUSER_INP_login) searchUserForm.login active
, Bulma.btn (show searchUserForm.admin) (HandleAddUserInput SEARCHUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
-- (up SEARCHUSER_INP_domain) searchUserForm.email active
, generic_button SearchUserAttempt wsUp
]
]
routing_search_button = Bulma.btn "Search" $ Routing Search
routing_add_button = Bulma.btn "Add" $ Routing Add
cancel_button = Bulma.modal_cancel_button CancelModal
generic_button :: forall w. Action -> Boolean -> HH.HTML w Action
generic_button action active =
HH.button
@ -170,6 +180,9 @@ handleAction = case _ of
PreventSubmit ev -> H.liftEffect $ Event.preventDefault ev
CancelModal -> do
handleAction $ Routing Search
AddUserAttempt -> do
{ addUserForm } <- H.get
let login = addUserForm.login

View File

@ -265,23 +265,18 @@ render state
# A.concat -- -> [x1 x2 y z1 z2 z3]
modal_rr_delete :: forall w. Int -> HH.HTML w Action
modal_rr_delete rr_id =
Bulma.modal
[ Bulma.modal_background
, Bulma.modal_card [Bulma.modal_header "Deleting a resource record"
, Bulma.modal_body [ warning_message ]]
, Bulma.modal_foot [modal_delete_button, Bulma.modal_cancel_button CancelModal]
]
where
modal_delete_button
= HH.button [ HP.classes (C.button <> C.is_success)
, HE.onClick \_ -> RemoveRR rr_id
] [HH.text "Delete the resource record."]
warning_message
= HH.p [] [ HH.text $ "You are about to delete a resource record, this actions is "
, HH.strong_ [ HH.text "irreversible" ]
, HH.text "."
]
modal_rr_delete rr_id = Bulma.modal "Deleting a resource record"
[warning_message] [modal_delete_button, Bulma.modal_cancel_button CancelModal]
where
modal_delete_button
= HH.button [ HP.classes (C.button <> C.is_success)
, HE.onClick \_ -> RemoveRR rr_id
] [HH.text "Delete the resource record."]
warning_message
= HH.p [] [ HH.text $ "You are about to delete a resource record, this actions is "
, HH.strong_ [ HH.text "irreversible" ]
, HH.text "."
]
render_current_rr_modal :: forall w. HH.HTML w Action
render_current_rr_modal =
@ -379,16 +374,14 @@ render state
UpdateRRModal -> Bulma.btn_save ValidateLocal
_ -> Bulma.p "state.rr_modal should either be NewRRModal or UpdateRRModal."
]
template content foot = Bulma.modal
[ Bulma.modal_background
, Bulma.modal_card [Bulma.modal_header $ case state.rr_modal of
NoModal -> "Error: no modal should be displayed"
NewRRModal t_ -> "New " <> show_accepted_type t_ <> " resource record"
UpdateRRModal -> "Update RR " <> show state._currentRR.rrid <> " resource record"
RemoveRRModal rr_id -> "Error: should display removal modal instead (for RR " <> show rr_id <> ")"
, Bulma.modal_body content ]
, Bulma.modal_foot (foot <> [Bulma.modal_cancel_button CancelModal])
]
template content foot_ = Bulma.modal title content foot
where
title = case state.rr_modal of
NoModal -> "Error: no modal should be displayed"
NewRRModal t_ -> "New " <> show_accepted_type t_ <> " resource record"
UpdateRRModal -> "Update RR " <> show state._currentRR.rrid <> " resource record"
RemoveRRModal rr_id -> "Error: should display removal modal instead (for RR " <> show rr_id <> ")"
foot = foot_ <> [Bulma.modal_cancel_button CancelModal]
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of

View File

@ -315,8 +315,8 @@ container = HH.div [HP.classes (C.container <> C.is_info)]
data_target :: forall r i. String -> HP.IProp r i
data_target = HP.attr (AttrName "data-target")
modal :: forall w i. Array (HH.HTML w i) -> HH.HTML w i
modal = HH.div [HP.classes (C.modal <> C.is_active)]
modal_ :: forall w i. Array (HH.HTML w i) -> HH.HTML w i
modal_ = HH.div [HP.classes (C.modal <> C.is_active)]
modal_background :: forall w i. HH.HTML w i
modal_background = HH.div [HP.classes C.modal_background] []
modal_card :: forall w i. Array (HH.HTML w i) -> HH.HTML w i
@ -338,7 +338,7 @@ modal_cancel_button action
modal_domain_delete :: forall w i. String -> HH.HTML w i
modal_domain_delete domain =
modal
modal_
[ modal_background
, modal_card [modal_header "Deleting a domain", modal_body]
, modal_foot [modal_delete_button, modal_cancel_button]
@ -411,3 +411,11 @@ input_with_side_text id title placeholder action value sidetext
[HH.text sidetext] ]
]
]
modal :: forall w i. String -> Array (HH.HTML w i) -> Array (HH.HTML w i) -> HH.HTML w i
modal title body foot =
modal_
[ modal_background
, modal_card [modal_header title, modal_body body]
, modal_foot foot
]