docspell/modules/webapp/src/main/elm/Page/UserSettings/Update.elm

175 lines
5.4 KiB
Elm
Raw Normal View History

2021-07-04 08:24:49 +00:00
{-
2021-09-21 20:32:47 +00:00
Copyright 2020 Eike K. & Contributors
2021-07-04 08:24:49 +00:00
2021-09-21 20:32:47 +00:00
SPDX-License-Identifier: AGPL-3.0-or-later
2021-07-04 08:24:49 +00:00
-}
2021-07-25 12:00:11 +00:00
module Page.UserSettings.Update exposing (UpdateResult, update)
import Comp.ChangePasswordForm
2020-01-04 23:12:23 +00:00
import Comp.EmailSettingsManage
2020-05-05 20:48:08 +00:00
import Comp.ImapSettingsManage
import Comp.NotificationManage
2021-08-30 21:54:37 +00:00
import Comp.OtpSetup
import Comp.ScanMailboxManage
import Comp.UiSettingsManage
2019-12-29 20:55:12 +00:00
import Data.Flags exposing (Flags)
2020-06-07 22:54:47 +00:00
import Data.UiSettings exposing (UiSettings)
2019-12-29 20:55:12 +00:00
import Page.UserSettings.Data exposing (..)
type alias UpdateResult =
{ model : Model
, cmd : Cmd Msg
, sub : Sub Msg
, newSettings : Maybe UiSettings
}
update : Flags -> UiSettings -> Msg -> Model -> UpdateResult
2020-06-07 22:54:47 +00:00
update flags settings msg model =
case msg of
SetTab t ->
let
2019-12-29 20:55:12 +00:00
m =
{ model | currentTab = Just t }
in
case t of
EmailSettingsTab ->
let
( em, c ) =
Comp.EmailSettingsManage.init flags
in
{ model = { m | emailSettingsModel = em }
, cmd = Cmd.map EmailSettingsMsg c
, sub = Sub.none
, newSettings = Nothing
}
2020-01-06 23:20:28 +00:00
ImapSettingsTab ->
let
( em, c ) =
Comp.ImapSettingsManage.init flags
in
{ model = { m | imapSettingsModel = em }
, cmd = Cmd.map ImapSettingsMsg c
, sub = Sub.none
, newSettings = Nothing
}
2020-01-06 23:20:28 +00:00
ChangePassTab ->
UpdateResult m Cmd.none Sub.none Nothing
2020-05-05 20:48:08 +00:00
NotificationTab ->
let
initCmd =
Cmd.map NotificationMsg
(Tuple.second (Comp.NotificationManage.init flags))
in
UpdateResult m initCmd Sub.none Nothing
2020-04-17 22:50:46 +00:00
ScanMailboxTab ->
let
initCmd =
Cmd.map ScanMailboxMsg
(Tuple.second (Comp.ScanMailboxManage.init flags))
in
UpdateResult m initCmd Sub.none Nothing
2020-05-18 07:55:49 +00:00
UiSettingsTab ->
UpdateResult m Cmd.none Sub.none Nothing
2021-08-30 21:54:37 +00:00
OtpTab ->
UpdateResult m Cmd.none Sub.none Nothing
ChangePassMsg m ->
let
2019-12-29 20:55:12 +00:00
( m2, c2 ) =
Comp.ChangePasswordForm.update flags m model.changePassModel
in
{ model = { model | changePassModel = m2 }
, cmd = Cmd.map ChangePassMsg c2
, sub = Sub.none
, newSettings = Nothing
}
2020-01-04 23:12:23 +00:00
EmailSettingsMsg m ->
let
( m2, c2 ) =
Comp.EmailSettingsManage.update flags m model.emailSettingsModel
in
{ model = { model | emailSettingsModel = m2 }
, cmd = Cmd.map EmailSettingsMsg c2
, sub = Sub.none
, newSettings = Nothing
}
2020-04-17 22:50:46 +00:00
2020-05-05 20:48:08 +00:00
ImapSettingsMsg m ->
let
( m2, c2 ) =
Comp.ImapSettingsManage.update flags m model.imapSettingsModel
in
{ model = { model | imapSettingsModel = m2 }
, cmd = Cmd.map ImapSettingsMsg c2
, sub = Sub.none
, newSettings = Nothing
}
2020-05-05 20:48:08 +00:00
2020-04-17 22:50:46 +00:00
NotificationMsg lm ->
let
( m2, c2 ) =
Comp.NotificationManage.update flags lm model.notificationModel
2020-04-17 22:50:46 +00:00
in
{ model = { model | notificationModel = m2 }
, cmd = Cmd.map NotificationMsg c2
, sub = Sub.none
, newSettings = Nothing
}
2020-05-18 07:55:49 +00:00
ScanMailboxMsg lm ->
let
( m2, c2 ) =
Comp.ScanMailboxManage.update flags lm model.scanMailboxModel
2020-05-18 07:55:49 +00:00
in
{ model = { model | scanMailboxModel = m2 }
, cmd = Cmd.map ScanMailboxMsg c2
, sub = Sub.none
, newSettings = Nothing
}
UiSettingsMsg lm ->
let
2021-05-25 23:14:30 +00:00
res =
2020-06-07 22:54:47 +00:00
Comp.UiSettingsManage.update flags settings lm model.uiSettingsModel
in
{ model = { model | uiSettingsModel = res.model }
, cmd = Cmd.map UiSettingsMsg res.cmd
, sub = Sub.map UiSettingsMsg res.sub
, newSettings = res.newSettings
}
2020-06-07 22:54:47 +00:00
2021-08-30 21:54:37 +00:00
OtpSetupMsg lm ->
let
( otpm, otpc ) =
Comp.OtpSetup.update flags lm model.otpSetupModel
in
{ model = { model | otpSetupModel = otpm }
, cmd = Cmd.map OtpSetupMsg otpc
, sub = Sub.none
, newSettings = Nothing
}
2020-06-07 22:54:47 +00:00
UpdateSettings ->
update flags
settings
(UiSettingsMsg Comp.UiSettingsManage.UpdateSettings)
model
ReceiveBrowserSettings sett ->
let
lm =
Comp.UiSettingsManage.ReceiveBrowserSettings sett
in
update flags settings (UiSettingsMsg lm) model