Add finished/
This commit is contained in:
53
finished/src/Data/UserPhoto.elm
Normal file
53
finished/src/Data/UserPhoto.elm
Normal file
@@ -0,0 +1,53 @@
|
||||
module Data.UserPhoto exposing (UserPhoto, decoder, encode, src, toMaybeString)
|
||||
|
||||
import Html exposing (Attribute)
|
||||
import Html.Attributes
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import Json.Encode.Extra as EncodeExtra
|
||||
|
||||
|
||||
type UserPhoto
|
||||
= UserPhoto (Maybe String)
|
||||
|
||||
|
||||
src : UserPhoto -> Attribute msg
|
||||
src =
|
||||
photoToUrl >> Html.Attributes.src
|
||||
|
||||
|
||||
decoder : Decoder UserPhoto
|
||||
decoder =
|
||||
Decode.map UserPhoto (Decode.nullable Decode.string)
|
||||
|
||||
|
||||
encode : UserPhoto -> Value
|
||||
encode (UserPhoto maybeUrl) =
|
||||
EncodeExtra.maybe Encode.string maybeUrl
|
||||
|
||||
|
||||
toMaybeString : UserPhoto -> Maybe String
|
||||
toMaybeString (UserPhoto maybeUrl) =
|
||||
maybeUrl
|
||||
|
||||
|
||||
|
||||
-- INTERNAL --
|
||||
|
||||
|
||||
photoToUrl : UserPhoto -> String
|
||||
photoToUrl (UserPhoto maybeUrl) =
|
||||
case maybeUrl of
|
||||
Nothing ->
|
||||
defaultPhotoUrl
|
||||
|
||||
Just "" ->
|
||||
defaultPhotoUrl
|
||||
|
||||
Just url ->
|
||||
url
|
||||
|
||||
|
||||
defaultPhotoUrl : String
|
||||
defaultPhotoUrl =
|
||||
"https://static.productionready.io/images/smiley-cyrus.jpg"
|
||||
Reference in New Issue
Block a user