Fix default draft settings; Reset draft on load

This commit is contained in:
Ryan Fox 2021-01-11 03:12:21 +00:00
parent e6a7eb4146
commit 992c032e9f
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
3 changed files with 16 additions and 10 deletions

View File

@ -44,6 +44,7 @@ module Command
, search , search
, notifyStatus , notifyStatus
, notifyNotification , notifyNotification
, clearDraft
) )
import Dom import Dom
@ -729,3 +730,7 @@ notifyNotification notification =
_ -> _ ->
Cmd.none Cmd.none
clearDraft : Cmd Msg
clearDraft =
Task.perform identity (Task.succeed (DraftEvent ClearDraft))

View File

@ -78,8 +78,15 @@ update : DraftMsg -> Account -> Model -> ( Model, Cmd Msg )
update draftMsg currentUser ({ draft } as model) = update draftMsg currentUser ({ draft } as model) =
case draftMsg of case draftMsg of
ClearDraft -> ClearDraft ->
{ model | draft = empty } let
! [ Command.updateDomStatus empty.status ] newDraft =
{ empty
| visibility = currentUser.source.privacy
, sensitive = currentUser.source.sensitive
}
in
{ model | draft = newDraft }
! [ Command.updateDomStatus newDraft.status ]
ToggleSpoiler enabled -> ToggleSpoiler enabled ->
let let

View File

@ -159,7 +159,7 @@ update msg ({ accountInfo, search } as model) =
model.clients model.clients
in in
{ model | currentUser = Just decoded, clients = updatedClients } { model | currentUser = Just decoded, clients = updatedClients }
! [ Command.saveClients updatedClients ] ! [ Command.saveClients updatedClients, Command.clearDraft ]
Err error -> Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! [] { model | errors = addErrorNotification (errorText error) model } ! []
@ -249,13 +249,7 @@ update msg ({ accountInfo, search } as model) =
{ model | errors = addErrorNotification (errorText error) model } ! [] { model | errors = addErrorNotification (errorText error) model } ! []
StatusPosted _ -> StatusPosted _ ->
-- FIXME: here we should rather send a ClearDraft command, and update the model ! [ Command.clearDraft ]
-- ClearDraft message handler to update DOM status
let
draft =
Update.Draft.empty
in
{ model | draft = draft } ! [ Command.updateDomStatus draft.status ]
StatusDeleted result -> StatusDeleted result ->
case result of case result of