Created
January 19, 2022 11:26
-
-
Save stefan-wullems/ece0e8ee7395134fbe4acb976abc7260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{------------------------- | |
src/Lib/Language | |
-------------------------} | |
module Lib.Language | |
type Language | |
= Swedish | |
| English | |
| .. | |
allLanguages : List Language | |
allLanguages = | |
[ Swedish | |
, English | |
, .. | |
] | |
encodeLanguageShort : Language -> String | |
encodeLanguageShort lang = | |
case lang of | |
Swedish -> | |
"sv" | |
English -> | |
"en" | |
.. -> .. | |
encodeLanguage : Language -> String | |
encodeLanguage lang = | |
case lang of | |
Swedish -> | |
"Swedish" | |
English -> | |
"English" | |
.. -> .. | |
enumLanguage : Enum Language | |
enumLanguage = | |
makeEnum allLanguages encodeLanguageShort encodeLanguage | |
{------------------------- | |
src/AdminOnly/UserAdmin/DetailsTab.elm | |
-------------------------} | |
type Msg | |
= SetLanguage String | |
| .. | |
modifyUser : (User -> User) -> Model -> Model | |
modifyUser modify model = | |
{ model | user = Status.map modify model.user } | |
handleSetEnum : Mdel -> Enum a -> String -> (User -> a -> User) -> Model | |
handleSetEnum model enum str setter = | |
case findEnumValue enum str of | |
Err _ -> | |
model | |
Ok value -> | |
modifyUser (\u -> setter u value) model | |
update : Msg -> Model -> (Model, Cmd msg) | |
update msg model = | |
case msg of | |
SetLanguage str -> | |
Cmd.pure <| (handleSetEnum model enumLanguage str (\u v -> { u | language })) | |
view = | |
Select.viewEnum { | |
enum = Language.enum, | |
value = user.language | |
onSelect = SetLanguage | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{------------------------- | |
src/Lib/Language | |
-------------------------} | |
module Lib.Language | |
type Language | |
= Swedish | |
| English | |
| .. | |
allLanguages : List Language | |
allLanguages = | |
[ Swedish | |
, English | |
, .. | |
] | |
encodeLanguageShort : Language -> String | |
encodeLanguageShort lang = | |
case lang of | |
Swedish -> | |
"sv" | |
English -> | |
"en" | |
.. -> .. | |
encodeLanguage : Language -> String | |
encodeLanguage lang = | |
case lang of | |
Swedish -> | |
"Swedish" | |
English -> | |
"English" | |
.. -> .. | |
{------------------------- | |
src/AdminOnly/UserAdmin/DetailsTab.elm | |
-------------------------} | |
type Msg | |
= SetLanguage Language | |
| .. | |
modifyUser : (User -> User) -> Model -> Model | |
modifyUser modify model = | |
{ model | user = Status.map modify model.user } | |
update : Msg -> Model -> (Model, Cmd msg) | |
update msg model = | |
case msg of | |
SetLanguage language -> | |
Cmd.pure <| (modifyUser (\u v -> { u | language } model)) | |
view = | |
Select.viewNoEnum { | |
items = Language.allLanguages, | |
getId = Language.encodeLanguageShort | |
getLabel = Language.encodeLanguage | |
value = user.language | |
onSelect = SetLanguage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment