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
|
|
|
|
2021-05-26 23:07:36 +00:00
|
|
|
module Page.UserSettings.Update exposing (UpdateResult, update)
|
2019-07-22 22:53:30 +00:00
|
|
|
|
|
|
|
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
|
2020-06-13 12:09:46 +00:00
|
|
|
import Comp.NotificationManage
|
2021-08-30 21:54:37 +00:00
|
|
|
import Comp.OtpSetup
|
2020-05-21 18:50:40 +00:00
|
|
|
import Comp.ScanMailboxManage
|
2020-06-06 22:51:11 +00:00
|
|
|
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 (..)
|
|
|
|
|
2019-07-22 22:53:30 +00:00
|
|
|
|
2021-05-26 23:07:36 +00:00
|
|
|
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 =
|
2019-07-22 22:53:30 +00:00
|
|
|
case msg of
|
|
|
|
SetTab t ->
|
|
|
|
let
|
2019-12-29 20:55:12 +00:00
|
|
|
m =
|
|
|
|
{ model | currentTab = Just t }
|
2020-06-06 22:51:11 +00:00
|
|
|
in
|
|
|
|
case t of
|
|
|
|
EmailSettingsTab ->
|
|
|
|
let
|
|
|
|
( em, c ) =
|
|
|
|
Comp.EmailSettingsManage.init flags
|
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ model = { m | emailSettingsModel = em }
|
|
|
|
, cmd = Cmd.map EmailSettingsMsg c
|
|
|
|
, sub = Sub.none
|
|
|
|
, newSettings = Nothing
|
|
|
|
}
|
2020-01-06 23:20:28 +00:00
|
|
|
|
2020-06-06 22:51:11 +00:00
|
|
|
ImapSettingsTab ->
|
|
|
|
let
|
|
|
|
( em, c ) =
|
|
|
|
Comp.ImapSettingsManage.init flags
|
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ model = { m | imapSettingsModel = em }
|
|
|
|
, cmd = Cmd.map ImapSettingsMsg c
|
|
|
|
, sub = Sub.none
|
|
|
|
, newSettings = Nothing
|
|
|
|
}
|
2020-01-06 23:20:28 +00:00
|
|
|
|
2020-06-06 22:51:11 +00:00
|
|
|
ChangePassTab ->
|
2021-05-26 23:07:36 +00:00
|
|
|
UpdateResult m Cmd.none Sub.none Nothing
|
2020-05-05 20:48:08 +00:00
|
|
|
|
2020-06-06 22:51:11 +00:00
|
|
|
NotificationTab ->
|
|
|
|
let
|
|
|
|
initCmd =
|
|
|
|
Cmd.map NotificationMsg
|
2020-06-13 12:09:46 +00:00
|
|
|
(Tuple.second (Comp.NotificationManage.init flags))
|
2020-06-06 22:51:11 +00:00
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
UpdateResult m initCmd Sub.none Nothing
|
2020-04-17 22:50:46 +00:00
|
|
|
|
2020-06-06 22:51:11 +00:00
|
|
|
ScanMailboxTab ->
|
|
|
|
let
|
|
|
|
initCmd =
|
|
|
|
Cmd.map ScanMailboxMsg
|
|
|
|
(Tuple.second (Comp.ScanMailboxManage.init flags))
|
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
UpdateResult m initCmd Sub.none Nothing
|
2020-05-18 07:55:49 +00:00
|
|
|
|
2020-06-06 22:51:11 +00:00
|
|
|
UiSettingsTab ->
|
2021-05-26 23:07:36 +00:00
|
|
|
UpdateResult m Cmd.none Sub.none Nothing
|
2019-07-22 22:53:30 +00:00
|
|
|
|
2021-08-30 21:54:37 +00:00
|
|
|
OtpTab ->
|
|
|
|
UpdateResult m Cmd.none Sub.none Nothing
|
|
|
|
|
2019-07-22 22:53:30 +00:00
|
|
|
ChangePassMsg m ->
|
|
|
|
let
|
2019-12-29 20:55:12 +00:00
|
|
|
( m2, c2 ) =
|
|
|
|
Comp.ChangePasswordForm.update flags m model.changePassModel
|
2019-07-22 22:53:30 +00:00
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ 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
|
2021-05-26 23:07:36 +00:00
|
|
|
{ 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
|
2021-05-26 23:07:36 +00:00
|
|
|
{ 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 ) =
|
2020-06-13 12:09:46 +00:00
|
|
|
Comp.NotificationManage.update flags lm model.notificationModel
|
2020-04-17 22:50:46 +00:00
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ 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 ) =
|
2020-05-21 18:50:40 +00:00
|
|
|
Comp.ScanMailboxManage.update flags lm model.scanMailboxModel
|
2020-05-18 07:55:49 +00:00
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ model = { model | scanMailboxModel = m2 }
|
|
|
|
, cmd = Cmd.map ScanMailboxMsg c2
|
|
|
|
, sub = Sub.none
|
|
|
|
, newSettings = Nothing
|
|
|
|
}
|
2020-06-06 22:51:11 +00:00
|
|
|
|
|
|
|
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
|
2020-06-06 22:51:11 +00:00
|
|
|
in
|
2021-05-26 23:07:36 +00:00
|
|
|
{ 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
|
2021-05-26 23:07:36 +00:00
|
|
|
|
|
|
|
ReceiveBrowserSettings sett ->
|
|
|
|
let
|
|
|
|
lm =
|
|
|
|
Comp.UiSettingsManage.ReceiveBrowserSettings sett
|
|
|
|
in
|
|
|
|
update flags settings (UiSettingsMsg lm) model
|