Show loader while sending mail

This commit is contained in:
Eike Kettner 2020-01-12 12:31:31 +01:00
parent d057d4de7c
commit 4b4d236ca4

View File

@ -64,6 +64,7 @@ type alias Model =
, dueDatePicker : DatePicker , dueDatePicker : DatePicker
, itemMail : Comp.ItemMail.Model , itemMail : Comp.ItemMail.Model
, mailOpen : Bool , mailOpen : Bool
, mailSending : Bool
, mailSendResult : Maybe BasicResult , mailSendResult : Maybe BasicResult
, sentMails : Comp.SentMails.Model , sentMails : Comp.SentMails.Model
, sentMailsOpen : Bool , sentMailsOpen : Bool
@ -128,6 +129,7 @@ emptyModel =
, dueDatePicker = Comp.DatePicker.emptyModel , dueDatePicker = Comp.DatePicker.emptyModel
, itemMail = Comp.ItemMail.emptyModel , itemMail = Comp.ItemMail.emptyModel
, mailOpen = False , mailOpen = False
, mailSending = False
, mailSendResult = Nothing , mailSendResult = Nothing
, sentMails = Comp.SentMails.init , sentMails = Comp.SentMails.init
, sentMailsOpen = False , sentMailsOpen = False
@ -740,7 +742,7 @@ update key flags next msg model =
, conn = sm.conn , conn = sm.conn
} }
in in
( model ( { model | mailSending = True }
, Cmd.batch , Cmd.batch
[ Cmd.map ItemMailMsg ic [ Cmd.map ItemMailMsg ic
, Api.sendMail flags mail SendMailResp , Api.sendMail flags mail SendMailResp
@ -748,7 +750,23 @@ update key flags next msg model =
) )
ToggleMail -> ToggleMail ->
( { model | mailOpen = not model.mailOpen }, Cmd.none ) let
newOpen =
not model.mailOpen
sendResult =
if newOpen then
model.mailSendResult
else
Nothing
in
( { model
| mailOpen = newOpen
, mailSendResult = sendResult
}
, Cmd.none
)
SendMailResp (Ok br) -> SendMailResp (Ok br) ->
let let
@ -761,6 +779,7 @@ update key flags next msg model =
in in
( { model ( { model
| itemMail = mm | itemMail = mm
, mailSending = False
, mailSendResult = Just br , mailSendResult = Just br
} }
, if br.success then , if br.success then
@ -775,7 +794,10 @@ update key flags next msg model =
errmsg = errmsg =
Util.Http.errorToString err Util.Http.errorToString err
in in
( { model | mailSendResult = Just (BasicResult False errmsg) } ( { model
| mailSendResult = Just (BasicResult False errmsg)
, mailSending = False
}
, Cmd.none , Cmd.none
) )
@ -1393,7 +1415,17 @@ renderMailForm model =
, ( "invisible hidden", not model.mailOpen ) , ( "invisible hidden", not model.mailOpen )
] ]
] ]
[ h4 [ class "ui header" ] [ div
[ classList
[ ( "ui dimmer", True )
, ( "active", model.mailSending )
]
]
[ div [ class "ui text loader" ]
[ text "Sending "
]
]
, h4 [ class "ui header" ]
[ text "Send this item via E-Mail" [ text "Send this item via E-Mail"
] ]
, Html.map ItemMailMsg (Comp.ItemMail.view model.itemMail) , Html.map ItemMailMsg (Comp.ItemMail.view model.itemMail)