From 992c032e9f9151d1a34ee9f34f9150d4b086e443 Mon Sep 17 00:00:00 2001 From: Ryan Fox Date: Mon, 11 Jan 2021 03:12:21 +0000 Subject: [PATCH] Fix default draft settings; Reset draft on load --- src/Command.elm | 5 +++++ src/Update/Draft.elm | 11 +++++++++-- src/Update/Mastodon.elm | 10 ++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Command.elm b/src/Command.elm index 69b8d6e..b27efa6 100644 --- a/src/Command.elm +++ b/src/Command.elm @@ -44,6 +44,7 @@ module Command , search , notifyStatus , notifyNotification + , clearDraft ) import Dom @@ -729,3 +730,7 @@ notifyNotification notification = _ -> Cmd.none + +clearDraft : Cmd Msg +clearDraft = + Task.perform identity (Task.succeed (DraftEvent ClearDraft)) diff --git a/src/Update/Draft.elm b/src/Update/Draft.elm index 2b31395..bd9678b 100644 --- a/src/Update/Draft.elm +++ b/src/Update/Draft.elm @@ -78,8 +78,15 @@ update : DraftMsg -> Account -> Model -> ( Model, Cmd Msg ) update draftMsg currentUser ({ draft } as model) = case draftMsg of ClearDraft -> - { model | draft = empty } - ! [ Command.updateDomStatus empty.status ] + let + newDraft = + { empty + | visibility = currentUser.source.privacy + , sensitive = currentUser.source.sensitive + } + in + { model | draft = newDraft } + ! [ Command.updateDomStatus newDraft.status ] ToggleSpoiler enabled -> let diff --git a/src/Update/Mastodon.elm b/src/Update/Mastodon.elm index 999896b..12a8c00 100644 --- a/src/Update/Mastodon.elm +++ b/src/Update/Mastodon.elm @@ -159,7 +159,7 @@ update msg ({ accountInfo, search } as model) = model.clients in { model | currentUser = Just decoded, clients = updatedClients } - ! [ Command.saveClients updatedClients ] + ! [ Command.saveClients updatedClients, Command.clearDraft ] Err error -> { model | errors = addErrorNotification (errorText error) model } ! [] @@ -249,13 +249,7 @@ update msg ({ accountInfo, search } as model) = { model | errors = addErrorNotification (errorText error) model } ! [] StatusPosted _ -> - -- FIXME: here we should rather send a ClearDraft command, and update the - -- ClearDraft message handler to update DOM status - let - draft = - Update.Draft.empty - in - { model | draft = draft } ! [ Command.updateDomStatus draft.status ] + model ! [ Command.clearDraft ] StatusDeleted result -> case result of