Update part1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
module Avatar exposing (Avatar, decoder, encode, src, toMaybeString)
|
||||
|
||||
import Asset
|
||||
import Html exposing (Attribute)
|
||||
import Html.Attributes
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
@@ -29,38 +30,27 @@ decoder =
|
||||
|
||||
encode : Avatar -> Value
|
||||
encode (Avatar maybeUrl) =
|
||||
maybeUrl
|
||||
|> Maybe.map Encode.string
|
||||
|> Maybe.withDefault Encode.null
|
||||
case maybeUrl of
|
||||
Just url ->
|
||||
Encode.string url
|
||||
|
||||
Nothing ->
|
||||
Encode.null
|
||||
|
||||
|
||||
src : Avatar -> Attribute msg
|
||||
src avatar =
|
||||
Html.Attributes.src (avatarToUrl avatar)
|
||||
src (Avatar maybeUrl) =
|
||||
case maybeUrl of
|
||||
Nothing ->
|
||||
Asset.src Asset.defaultAvatar
|
||||
|
||||
Just "" ->
|
||||
Asset.src Asset.defaultAvatar
|
||||
|
||||
Just url ->
|
||||
Html.Attributes.src url
|
||||
|
||||
|
||||
toMaybeString : Avatar -> Maybe String
|
||||
toMaybeString (Avatar maybeUrl) =
|
||||
maybeUrl
|
||||
|
||||
|
||||
|
||||
-- INTERNAL
|
||||
|
||||
|
||||
avatarToUrl : Avatar -> String
|
||||
avatarToUrl (Avatar maybeUrl) =
|
||||
case maybeUrl of
|
||||
Nothing ->
|
||||
defaultPhotoUrl
|
||||
|
||||
Just "" ->
|
||||
defaultPhotoUrl
|
||||
|
||||
Just url ->
|
||||
url
|
||||
|
||||
|
||||
defaultPhotoUrl : String
|
||||
defaultPhotoUrl =
|
||||
"http://localhost:3000/images/smiley-cyrus.jpg"
|
||||
|
||||
Reference in New Issue
Block a user