Prefill share mail form

To have access to the translated content, the messages must be given
to the update function. There is no way to set the values in the view.
This commit is contained in:
eikek 2021-10-10 11:48:08 +02:00
parent 16ccddab9f
commit 9009ebcb39
7 changed files with 102 additions and 99 deletions

View File

@ -17,6 +17,7 @@ import Browser.Navigation as Nav
import Data.Flags
import Data.UiSettings exposing (UiSettings)
import Data.UiTheme
import Messages exposing (Messages)
import Page exposing (Page(..))
import Page.CollectiveSettings.Data
import Page.CollectiveSettings.Update
@ -59,6 +60,10 @@ update msg model =
updateWithSub : Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateWithSub msg model =
let
texts =
Messages.get <| App.Data.getUiLanguage model
in
case msg of
ToggleSidebar ->
( { model | sidebarVisible = not model.sidebarVisible }, Cmd.none, Sub.none )
@ -98,7 +103,7 @@ updateWithSub msg model =
ClientSettingsSaveResp settings (Ok res) ->
if res.success then
applyClientSettings model settings
applyClientSettings texts model settings
else
( model, Cmd.none, Sub.none )
@ -116,7 +121,7 @@ updateWithSub msg model =
( { model | anonymousUiLang = lang, langMenuOpen = False }, Cmd.none, Sub.none )
HomeMsg lm ->
updateHome lm model
updateHome texts lm model
ShareMsg lm ->
updateShare lm model
@ -131,10 +136,10 @@ updateWithSub msg model =
updateManageData lm model
CollSettingsMsg m ->
updateCollSettings m model
updateCollSettings texts m model
UserSettingsMsg m ->
updateUserSettings m model
updateUserSettings texts m model
QueueMsg m ->
updateQueue m model
@ -149,7 +154,7 @@ updateWithSub msg model =
updateNewInvite m model
ItemDetailMsg m ->
updateItemDetail m model
updateItemDetail texts m model
VersionResp (Ok info) ->
( { model | version = info }, Cmd.none, Sub.none )
@ -291,7 +296,7 @@ updateWithSub msg model =
)
GetUiSettings (Ok settings) ->
applyClientSettings model settings
applyClientSettings texts model settings
GetUiSettings (Err _) ->
( model, Cmd.none, Sub.none )
@ -301,11 +306,11 @@ updateWithSub msg model =
lm =
Page.UserSettings.Data.ReceiveBrowserSettings sett
in
updateUserSettings lm model
updateUserSettings texts lm model
applyClientSettings : Model -> UiSettings -> ( Model, Cmd Msg, Sub Msg )
applyClientSettings model settings =
applyClientSettings : Messages -> Model -> UiSettings -> ( Model, Cmd Msg, Sub Msg )
applyClientSettings texts model settings =
let
setTheme =
Ports.setUiTheme settings.uiTheme
@ -316,9 +321,9 @@ applyClientSettings model settings =
, setTheme
, Sub.none
)
, updateUserSettings Page.UserSettings.Data.UpdateSettings
, updateHome Page.Home.Data.UiSettingsUpdated
, updateItemDetail Page.ItemDetail.Data.UiSettingsUpdated
, updateUserSettings texts Page.UserSettings.Data.UpdateSettings
, updateHome texts Page.Home.Data.UiSettingsUpdated
, updateItemDetail texts Page.ItemDetail.Data.UiSettingsUpdated
]
{ model | uiSettings = settings }
@ -357,8 +362,8 @@ updateShare lmsg model =
( model, Cmd.none, Sub.none )
updateItemDetail : Page.ItemDetail.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateItemDetail lmsg model =
updateItemDetail : Messages -> Page.ItemDetail.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateItemDetail texts lmsg model =
let
inav =
Page.Home.Data.itemNav model.itemDetailModel.detail.item.id model.homeModel
@ -378,12 +383,12 @@ updateItemDetail lmsg model =
}
( hm, hc, hs ) =
updateHome (Page.Home.Data.SetLinkTarget result.linkTarget) model_
updateHome texts (Page.Home.Data.SetLinkTarget result.linkTarget) model_
( hm1, hc1, hs1 ) =
case result.removedItem of
Just removedId ->
updateHome (Page.Home.Data.RemoveItem removedId) hm
updateHome texts (Page.Home.Data.RemoveItem removedId) hm
Nothing ->
( hm, hc, hs )
@ -446,8 +451,8 @@ updateQueue lmsg model =
)
updateUserSettings : Page.UserSettings.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateUserSettings lmsg model =
updateUserSettings : Messages -> Page.UserSettings.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateUserSettings texts lmsg model =
let
result =
Page.UserSettings.Update.update model.flags model.uiSettings lmsg model.userSettingsModel
@ -458,7 +463,7 @@ updateUserSettings lmsg model =
( lm2, lc2, s2 ) =
case result.newSettings of
Just sett ->
applyClientSettings model_ sett
applyClientSettings texts model_ sett
Nothing ->
( model_, Cmd.none, Sub.none )
@ -475,11 +480,12 @@ updateUserSettings lmsg model =
)
updateCollSettings : Page.CollectiveSettings.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateCollSettings lmsg model =
updateCollSettings : Messages -> Page.CollectiveSettings.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateCollSettings texts lmsg model =
let
( lm, lc, ls ) =
Page.CollectiveSettings.Update.update model.flags
Page.CollectiveSettings.Update.update texts.collectiveSettings
model.flags
lmsg
model.collSettingsModel
in
@ -508,8 +514,8 @@ updateLogin lmsg model =
)
updateHome : Page.Home.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateHome lmsg model =
updateHome : Messages -> Page.Home.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateHome texts lmsg model =
let
mid =
case model.page of
@ -520,7 +526,7 @@ updateHome lmsg model =
Nothing
result =
Page.Home.Update.update mid model.key model.flags model.uiSettings lmsg model.homeModel
Page.Home.Update.update mid model.key model.flags texts.home model.uiSettings lmsg model.homeModel
model_ =
{ model | homeModel = result.model }
@ -528,7 +534,7 @@ updateHome lmsg model =
( lm, lc, ls ) =
case result.newSettings of
Just sett ->
applyClientSettings model_ sett
applyClientSettings texts model_ sett
Nothing ->
( model_, Cmd.none, Sub.none )
@ -562,11 +568,14 @@ initPage model_ page =
let
model =
{ model_ | page = page }
texts =
Messages.get <| App.Data.getUiLanguage model
in
case page of
HomePage ->
Util.Update.andThen2
[ updateHome Page.Home.Data.Init
[ updateHome texts Page.Home.Data.Init
, updateQueue Page.Queue.Data.StopRefresh
]
model
@ -580,7 +589,7 @@ initPage model_ page =
CollectiveSettingPage ->
Util.Update.andThen2
[ updateQueue Page.Queue.Data.StopRefresh
, updateCollSettings Page.CollectiveSettings.Data.Init
, updateCollSettings texts Page.CollectiveSettings.Data.Init
]
model
@ -608,7 +617,7 @@ initPage model_ page =
ItemDetailPage id ->
Util.Update.andThen2
[ updateItemDetail (Page.ItemDetail.Data.Init id)
[ updateItemDetail texts (Page.ItemDetail.Data.Init id)
, updateQueue Page.Queue.Data.StopRefresh
]
model

View File

@ -252,8 +252,6 @@ isValid model =
type alias ViewConfig =
{ withAttachments : Bool
, subjectTemplate : Maybe String
, bodyTemplate : Maybe String
, textAreaClass : String
, showCancel : Bool
}
@ -264,8 +262,6 @@ view2 texts settings model =
let
cfg =
{ withAttachments = True
, subjectTemplate = Nothing
, bodyTemplate = Nothing
, textAreaClass = ""
, showCancel = True
}
@ -357,11 +353,6 @@ view texts settings cfg model =
[ type_ "text"
, class S.textInput
, onInput SetSubject
, if model.subject == "" then
onFocus (SetSubject <| Maybe.withDefault "" cfg.subjectTemplate)
else
class ""
, value model.subject
]
[]
@ -373,11 +364,7 @@ view texts settings cfg model =
]
, textarea
[ onInput SetBody
, if model.body == "" then
value <| Maybe.withDefault "" cfg.bodyTemplate
else
value model.body
, value model.body
, class S.textAreaInput
, class cfg.textAreaClass
]

View File

@ -26,7 +26,6 @@ import Comp.ShareView
import Data.Flags exposing (Flags)
import Data.Icons as Icons
import Data.ItemQuery exposing (ItemQuery)
import Data.SearchMode exposing (SearchMode)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
import Html.Attributes exposing (..)
@ -131,8 +130,8 @@ type alias UpdateResult =
}
update : Flags -> Msg -> Model -> UpdateResult
update flags msg model =
update : Texts -> Flags -> Msg -> Model -> UpdateResult
update texts flags msg model =
case msg of
CancelPublish ->
{ model = model
@ -155,7 +154,7 @@ update flags msg model =
MailMsg lm ->
let
( mm, mc ) =
Comp.ShareMail.update flags lm model.mailModel
Comp.ShareMail.update texts.shareMail flags lm model.mailModel
in
{ model = { model | mailModel = mm }
, cmd = Cmd.map MailMsg mc
@ -204,7 +203,7 @@ update flags msg model =
GetShareResp (Ok share) ->
let
( mm, mc ) =
Comp.ShareMail.update flags (Comp.ShareMail.setMailInfo share) model.mailModel
Comp.ShareMail.update texts.shareMail flags (Comp.ShareMail.setMailInfo share) model.mailModel
in
{ model =
{ model

View File

@ -67,8 +67,8 @@ setMailInfo share =
SetMailInfo share
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
update flags msg model =
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg )
update texts flags msg model =
case msg of
MailMsg lm ->
let
@ -107,7 +107,22 @@ update flags msg model =
defaultResult
SetMailInfo share ->
( { model | share = share }, Cmd.none )
let
url =
flags.config.baseUrl ++ Page.pageToString (SharePage share.id)
name =
share.name
lm =
Comp.ItemMail.setMailInfo
(texts.subjectTemplate name)
(texts.bodyTemplate url)
nm =
{ model | share = share }
in
update texts flags (MailMsg lm) nm
SendMailResp (Ok res) ->
if res.success then
@ -138,19 +153,8 @@ update flags msg model =
view : Texts -> Flags -> UiSettings -> Model -> Html Msg
view texts flags settings model =
let
url =
flags.config.baseUrl ++ (Page.pageToString <| SharePage model.share.id)
subject =
texts.subjectTemplate model.share.name
body =
texts.bodyTemplate url
cfg =
{ withAttachments = False
, subjectTemplate = Just subject
, bodyTemplate = Just body
, textAreaClass = "h-52"
, showCancel = False
}

View File

@ -110,8 +110,8 @@ loadShares =
--- update
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update flags msg model =
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update texts flags msg model =
case msg of
InitNewShare ->
let
@ -121,7 +121,7 @@ update flags msg model =
share =
Api.Model.ShareDetail.empty
in
update flags (FormMsg (Comp.ShareForm.setShare { share | enabled = True })) nm
update texts flags (FormMsg (Comp.ShareForm.setShare { share | enabled = True })) nm
SetViewMode vm ->
( { model | viewMode = vm, formError = FormErrorNone }
@ -150,7 +150,7 @@ update flags msg model =
in
case action of
Comp.ShareTable.Edit share ->
setShare share flags model
setShare texts share flags model
RequestDelete ->
( { model | deleteConfirm = DeleteConfirmOn }, Cmd.none, Sub.none )
@ -209,14 +209,14 @@ update flags msg model =
( { model | loading = False, formError = FormErrorHttp err }, Cmd.none, Sub.none )
GetShareResp (Ok share) ->
setShare share flags model
setShare texts share flags model
GetShareResp (Err err) ->
( { model | formError = FormErrorHttp err }, Cmd.none, Sub.none )
DeleteShareResp (Ok res) ->
if res.success then
update flags (SetViewMode Table) { model | loading = False }
update texts flags (SetViewMode Table) { model | loading = False }
else
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none, Sub.none )
@ -227,13 +227,13 @@ update flags msg model =
MailMsg lm ->
let
( mm, mc ) =
Comp.ShareMail.update flags lm model.mailModel
Comp.ShareMail.update texts.shareMail flags lm model.mailModel
in
( { model | mailModel = mm }, Cmd.map MailMsg mc, Sub.none )
setShare : ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg )
setShare share flags model =
setShare : Texts -> ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg )
setShare texts share flags model =
let
shareUrl =
flags.config.baseUrl ++ Page.pageToString (SharePage share.id)
@ -245,10 +245,10 @@ setShare share flags model =
Ports.initClipboard (Comp.ShareView.clipboardData share)
( nm, nc, ns ) =
update flags (FormMsg <| Comp.ShareForm.setShare share) nextModel
update texts flags (FormMsg <| Comp.ShareForm.setShare share) nextModel
( nm2, nc2, ns2 ) =
update flags (MailMsg <| Comp.ShareMail.setMailInfo share) nm
update texts flags (MailMsg <| Comp.ShareMail.setMailInfo share) nm
in
( nm2, Cmd.batch [ initClipboard, nc, nc2 ], Sub.batch [ ns, ns2 ] )

View File

@ -13,11 +13,12 @@ import Comp.ShareManage
import Comp.SourceManage
import Comp.UserManage
import Data.Flags exposing (Flags)
import Messages.Page.CollectiveSettings exposing (Texts)
import Page.CollectiveSettings.Data exposing (..)
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update flags msg model =
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update texts flags msg model =
case msg of
SetTab t ->
let
@ -26,19 +27,19 @@ update flags msg model =
in
case t of
SourceTab ->
update flags (SourceMsg Comp.SourceManage.LoadSources) m
update texts flags (SourceMsg Comp.SourceManage.LoadSources) m
UserTab ->
update flags (UserMsg Comp.UserManage.LoadUsers) m
update texts flags (UserMsg Comp.UserManage.LoadUsers) m
InsightsTab ->
update flags Init m
update texts flags Init m
SettingsTab ->
update flags Init m
update texts flags Init m
ShareTab ->
update flags (ShareMsg Comp.ShareManage.loadShares) m
update texts flags (ShareMsg Comp.ShareManage.loadShares) m
SourceMsg m ->
let
@ -50,7 +51,7 @@ update flags msg model =
ShareMsg lm ->
let
( sm, sc, ss ) =
Comp.ShareManage.update flags lm model.shareModel
Comp.ShareManage.update texts.shareManage flags lm model.shareModel
in
( { model | shareModel = sm }, Cmd.map ShareMsg sc, Sub.map ShareMsg ss )

View File

@ -27,6 +27,7 @@ import Data.ItemSelection
import Data.Items
import Data.SearchMode exposing (SearchMode)
import Data.UiSettings exposing (UiSettings)
import Messages.Page.Home exposing (Texts)
import Page exposing (Page(..))
import Page.Home.Data exposing (..)
import Process
@ -48,8 +49,8 @@ type alias UpdateResult =
}
update : Maybe String -> Nav.Key -> Flags -> UiSettings -> Msg -> Model -> UpdateResult
update mId key flags settings msg model =
update : Maybe String -> Nav.Key -> Flags -> Texts -> UiSettings -> Msg -> Model -> UpdateResult
update mId key flags texts settings msg model =
case msg of
Init ->
let
@ -63,7 +64,7 @@ update mId key flags settings msg model =
in
makeResult <|
Util.Update.andThen3
[ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init)
[ update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.Init)
, doSearch searchParam
]
model
@ -73,7 +74,7 @@ update mId key flags settings msg model =
nm =
{ model | searchOffset = 0, powerSearchInput = Comp.PowerSearchInput.init }
in
update mId key flags settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
SearchMenuMsg m ->
let
@ -119,7 +120,7 @@ update mId key flags settings msg model =
SetLinkTarget lt ->
case linkTargetMsg lt of
Just m ->
update mId key flags settings m model
update mId key flags texts settings m model
Nothing ->
makeResult ( model, Cmd.none, Sub.none )
@ -167,7 +168,7 @@ update mId key flags settings msg model =
in
makeResult <|
Util.Update.andThen3
[ update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.SetResults list))
[ update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.SetResults list))
, if scroll then
scrollToCard mId
@ -189,7 +190,7 @@ update mId key flags settings msg model =
, moreAvailable = list.groups /= []
}
in
update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.AddResults list)) m
update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.AddResults list)) m
ItemSearchAddResp (Err _) ->
withSub
@ -289,18 +290,18 @@ update mId key flags settings msg model =
smMsg =
SearchMenuMsg (Comp.SearchMenu.SetTextSearch str)
in
update mId key flags settings smMsg model
update mId key flags texts settings smMsg model
ToggleSearchType ->
case model.searchTypeDropdownValue of
BasicSearch ->
update mId key flags settings (SearchMenuMsg Comp.SearchMenu.SetFulltextSearch) model
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetFulltextSearch) model
ContentOnlySearch ->
update mId key flags settings (SearchMenuMsg Comp.SearchMenu.SetNamesSearch) model
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetNamesSearch) model
KeyUpSearchbarMsg (Just Enter) ->
update mId key flags settings (DoSearch model.searchTypeDropdownValue) model
update mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
KeyUpSearchbarMsg _ ->
withSub ( model, Cmd.none )
@ -614,6 +615,7 @@ update mId key flags settings msg model =
update mId
key
flags
texts
settings
(DoSearch model.searchTypeDropdownValue)
model_
@ -676,7 +678,7 @@ update mId key flags settings msg model =
SelectView svm ->
let
result =
Comp.PublishItems.update flags lmsg svm.publishModel
Comp.PublishItems.update texts.publishItems flags lmsg svm.publishModel
nextView =
case result.outcome of
@ -693,6 +695,7 @@ update mId key flags settings msg model =
update mId
key
flags
texts
settings
(DoSearch model.searchTypeDropdownValue)
model_
@ -809,7 +812,7 @@ update mId key flags settings msg model =
model_ =
{ model | viewMode = viewMode }
in
update mId key flags settings (DoSearch model.lastSearchType) model_
update mId key flags texts settings (DoSearch model.lastSearchType) model_
SearchStatsResp result ->
let
@ -819,7 +822,7 @@ update mId key flags settings msg model =
stats =
Result.withDefault model.searchStats result
in
update mId key flags settings lm { model | searchStats = stats }
update mId key flags texts settings lm { model | searchStats = stats }
TogglePreviewFullWidth ->
let
@ -861,16 +864,16 @@ update mId key flags settings msg model =
makeResult ( model_, cmd_, Sub.map PowerSearchMsg result.subs )
Comp.PowerSearchInput.SubmitSearch ->
update mId key flags settings (DoSearch model_.searchTypeDropdownValue) model_
update mId key flags texts settings (DoSearch model_.searchTypeDropdownValue) model_
KeyUpPowerSearchbarMsg (Just Enter) ->
update mId key flags settings (DoSearch model.searchTypeDropdownValue) model
update mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
KeyUpPowerSearchbarMsg _ ->
withSub ( model, Cmd.none )
RemoveItem id ->
update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
TogglePublishCurrentQueryView ->
case createQuery model of
@ -889,7 +892,7 @@ update mId key flags settings msg model =
PublishView inPM ->
let
result =
Comp.PublishItems.update flags lmsg inPM
Comp.PublishItems.update texts.publishItems flags lmsg inPM
in
case result.outcome of
Comp.PublishItems.OutcomeInProgress ->