Update part1

This commit is contained in:
Richard Feldman
2018-08-13 05:11:14 -04:00
parent 493b5681d4
commit 1688e5ec38
19 changed files with 854 additions and 530 deletions

View File

@@ -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"