Files
elm-0.19-workshop/intro/part4/src/Views/User/Follow.elm
Richard Feldman d57dec1681 Rename more stuff
2018-08-05 04:49:15 -04:00

42 lines
1.2 KiB
Elm
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module Views.User.Follow exposing (State, button)
{-| The Follow button.
This API accepts a "toggle follow" message and the current state of whether
the user is already being followed. It's very lightweight!
It would be overkill to give something this simple its own Model, Msg, and
update. That would make it way more work to use than it needed to be,
and for no benefit.
-}
import Data.User as User exposing (Username)
import Html exposing (Html, i, text)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick)
type alias State record =
{ record | following : Bool, username : Username }
button : (Username -> msg) -> State record -> Html msg
button toggleFollow { following, username } =
let
( prefix, secondaryClass ) =
if following then
( "Unfollow", "btn-secondary" )
else
( "Follow", "btn-outline-secondary" )
classes =
[ "btn", "btn-sm", secondaryClass, "action-btn" ]
|> String.join " "
|> class
in
Html.button [ classes, onClick (toggleFollow username) ]
[ i [ class "ion-plus-round" ] []
, text (" " ++ prefix ++ " " ++ User.usernameToString username)
]