Fix setting ui theme for anonymous

This commit is contained in:
Eike Kettner 2021-02-18 22:02:56 +01:00
parent 3c0abcadb9
commit 70fa57587b
2 changed files with 18 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import Browser exposing (UrlRequest)
import Browser.Navigation exposing (Key)
import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings)
import Data.UiTheme exposing (UiTheme)
import Http
import Page exposing (Page(..))
import Page.CollectiveSettings.Data
@ -46,6 +47,7 @@ type alias Model =
, subs : Sub Msg
, uiSettings : UiSettings
, sidebarVisible : Bool
, anonymousTheme : UiTheme
}
@ -94,6 +96,7 @@ init key url flags_ settings =
, subs = Sub.none
, uiSettings = settings
, sidebarVisible = settings.sideMenuVisible
, anonymousTheme = Data.UiTheme.Light
}
, Cmd.batch
[ Cmd.map UserSettingsMsg uc

View File

@ -52,18 +52,18 @@ updateWithSub msg model =
( { model | sidebarVisible = not model.sidebarVisible }, Cmd.none, Sub.none )
ToggleDarkMode ->
let
settings =
model.uiSettings
next =
Data.UiTheme.cycle settings.uiTheme
newSettings =
{ settings | uiTheme = next }
in
case model.flags.account of
Just _ ->
let
settings =
model.uiSettings
next =
Data.UiTheme.cycle settings.uiTheme
newSettings =
{ settings | uiTheme = next }
in
-- when authenticated, store it in settings only
-- once new settings arrive via a subscription,
-- the ui is updated. so it is also updated on
@ -74,8 +74,12 @@ updateWithSub msg model =
)
Nothing ->
let
next =
Data.UiTheme.cycle model.anonymousTheme
in
-- when not logged in, simply set the theme
( { model | userMenuOpen = False }
( { model | userMenuOpen = False, anonymousTheme = next }
, Ports.setUiTheme next
, Sub.none
)