Apply tag colors from settings

This commit is contained in:
Eike Kettner
2020-06-08 00:54:47 +02:00
parent 1cd65b7b7c
commit 1dd84c11bd
39 changed files with 375 additions and 341 deletions

View File

@ -37,6 +37,7 @@ all =
, Pink
, Brown
, Grey
, Black
]

View File

@ -4,9 +4,13 @@ module Data.UiSettings exposing
, defaults
, merge
, mergeDefaults
, tagColor
, tagColorString
, toStoredUiSettings
)
import Api.Model.Tag exposing (Tag)
import Data.Color exposing (Color)
import Dict exposing (Dict)
@ -66,6 +70,27 @@ toStoredUiSettings settings =
}
tagColor : Tag -> UiSettings -> Maybe Color
tagColor tag settings =
let
readColor c =
Dict.get c settings.tagCategoryColors
|> Maybe.andThen Data.Color.fromString
in
Maybe.andThen readColor tag.category
tagColorString : Tag -> UiSettings -> String
tagColorString tag settings =
tagColor tag settings
|> Maybe.map Data.Color.toString
|> Maybe.withDefault ""
--- Helpers
choose : Maybe a -> a -> a
choose m1 m2 =
Maybe.withDefault m2 m1