Skip to content

Commit

Permalink
Implement share link in Victory screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ufocoder committed Jan 4, 2017
1 parent b2a9386 commit af2ec6b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
42 changes: 29 additions & 13 deletions src/Render.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Http exposing (encodeUri)
import Style
import Type exposing (..)

url: String
url = "https://ufocoder.github.io/sokoban/dist/index.html"

layout: List (Html msg) -> Html msg
layout children =
Expand All @@ -27,31 +29,45 @@ title message =
Html.div [Style.title] [text message]


share: Level -> String -> Html msg
share level message =
shareVictory: String -> Html msg
shareVictory linkText =
let
tweetText = "I win the sokoban game, URL: " ++ url
in
Html.div [Style.share] [
shareTwitterLink linkText tweetText
]


shareLevel: Level -> String -> Html msg
shareLevel level linkText =
let
baseText = (
"passed level #" ++ (toString level.number) ++ ", with " ++
"passed level #" ++ (toString (level.number + 1)) ++ ", with " ++
(toString level.statistic.moves) ++ " moves and " ++
(toString level.statistic.pushes) ++ " pushes"
)
shareText = "You " ++ baseText
tweetText = "I " ++ baseText
tweetText = "I " ++ baseText ++ ", URL: " ++ url
in
Html.div [Style.share] [
Html.div [] [text shareText],
Html.a [
target "_blank",
href ("https://twitter.com/intent/tweet?text=" ++ (encodeUri tweetText)),
style [
("color", "#FFFFFF")
]
] [
text message
]
shareTwitterLink linkText tweetText
]


shareTwitterLink: String -> String -> Html msg
shareTwitterLink linkText tweetText =
Html.a [
target "_blank",
href ("https://twitter.com/intent/tweet?text=" ++ (encodeUri tweetText)),
style [
("color", "#FFFFFF")
]
] [
text linkText
]

reset: String -> Html msg
reset message =
Html.div [Style.reset] [text message]
Expand Down
2 changes: 1 addition & 1 deletion src/Screen/Complete.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ render model =
Just level ->
Render.layout [
Render.menu "Press spacebar to play next level",
Render.share level "Share your results in Twitter",
Render.shareLevel level "Share your results in Twitter",
Render.background
]

Expand Down
3 changes: 2 additions & 1 deletion src/Screen/Victory.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Type exposing (..)
render: Model -> Html Msg
render model =
Render.layout [
Render.title "You win!",
Render.menu "Congratulations! You win the game!",
Render.shareVictory "Share your victory in Twitter",
Render.background
]

0 comments on commit af2ec6b

Please sign in to comment.