Commit 02f3521b authored by Emmanuel Raviart's avatar Emmanuel Raviart

Rework tweet button.

parent 8a8af840
......@@ -143,46 +143,6 @@ update msg ({ editedProperty } as model) authentication language =
in
( newModel, cmd )
SelectField field ->
let
newEditedProperty =
Maybe.map
(\editedProperty -> { editedProperty | selectedField = field })
editedProperty
newModel =
{ model | editedProperty = newEditedProperty }
in
( newModel, Cmd.none )
SubmitValue selectedField ->
let
( cardId, keyId ) =
case editedProperty of
Nothing ->
Debug.crash "SubmitValue: cannot happen"
Just { cardId, keyId } ->
( cardId, keyId )
task =
Http.toTask (Requests.postValue authentication selectedField)
|> Task.andThen
(\dataIdBody ->
Http.toTask
(Requests.postProperty
authentication
cardId
keyId
dataIdBody.data.id
)
)
cmd =
Task.attempt (ForSelf << PropertyPosted) task
in
( model, cmd )
PropertyPosted (Result.Err err) ->
let
_ =
......@@ -306,6 +266,49 @@ update msg ({ editedProperty } as model) authentication language =
in
( newModel, Cmd.none )
SelectField field ->
let
newEditedProperty =
Maybe.map
(\editedProperty -> { editedProperty | selectedField = field })
editedProperty
newModel =
{ model | editedProperty = newEditedProperty }
in
( newModel, Cmd.none )
SubmitValue selectedField ->
let
( cardId, keyId ) =
case editedProperty of
Nothing ->
Debug.crash "SubmitValue: cannot happen"
Just { cardId, keyId } ->
( cardId, keyId )
task =
Http.toTask (Requests.postValue authentication selectedField)
|> Task.andThen
(\dataIdBody ->
Http.toTask
(Requests.postProperty
authentication
cardId
keyId
dataIdBody.data.id
)
)
cmd =
Task.attempt (ForSelf << PropertyPosted) task
in
( model, cmd )
Tweet twitterUrl ->
( model, Ports.tweet twitterUrl )
VotePropertyDown propertyId ->
let
cmd =
......
......@@ -40,6 +40,7 @@ type InternalMsg
| RatingPosted (Result Http.Error DataIdBody)
| SelectField Field
| SubmitValue Field
| Tweet String
| VotePropertyDown String
| VotePropertyUp String
......
......@@ -1134,49 +1134,42 @@ viewSidebar language card values =
[ h6 [ class "panel-title" ]
[ text (I18n.translate language I18n.Share) ]
, div [ class "panel-body chart" ]
-- [ button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-facebook" ]
-- []
-- ]
[ a
[ class "btn btn-default btn-action btn-round twitter-share-button"
, href
(let
cardName =
case getOneString language nameKeys card values of
Just name ->
name
Nothing ->
"Untitled Card"
url =
Urls.fullUrl
(Routes.makeUrlWithLanguage language (Routes.urlPathForCard card))
-- TODO: i18n
in
("https://twitter.com/intent/tweet?text="
++ Http.encodeUri
(I18n.translate
language
(I18n.TweetMessage cardName url)
)
)
)
]
[ i [ attribute "aria-hidden" "true", class "fa fa-twitter" ]
[]
(let
cardName =
I18n.getName language card values
url =
Urls.fullUrl
(Routes.makeUrlWithLanguage language (Routes.urlPathForCard card))
twitterUrl =
"https://twitter.com/intent/tweet?text="
++ Http.encodeUri (I18n.translate language (I18n.TweetMessage cardName url))
in
-- [ button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-facebook" ]
-- []
-- ]
[ a
[ class "btn btn-default btn-action btn-round"
, href twitterUrl
, onWithOptions
"click"
{ stopPropagation = True, preventDefault = True }
(Decode.succeed (ForSelf <| Tweet twitterUrl))
-- , onClick (ForSelf <| Tweet twitterUrl)
]
[ i [ attribute "aria-hidden" "true", class "fa fa-twitter" ] [] ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-google-plus" ]
-- []
-- ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-linkedin" ]
-- []
-- ]
]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-google-plus" ]
-- []
-- ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-linkedin" ]
-- []
-- ]
]
)
]
]
]
......
......@@ -64,3 +64,6 @@ update msg model authentication language =
|> Http.send (ForSelf << GotCollection)
in
( newModel, cmd )
Tweet twitterUrl ->
( model, Ports.tweet twitterUrl )
......@@ -16,6 +16,7 @@ type ExternalMsg
type InternalMsg
= GotCollection (Result Http.Error DataIdBody)
| LoadCollection String
| Tweet String
type Msg
......
......@@ -7,6 +7,7 @@ import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Http
import I18n
import Json.Decode as Decode
import Routes
import Types exposing (..)
import Urls
......@@ -134,41 +135,39 @@ viewCollectionContent language user collection cards values =
[ h6 [ class "panel-title" ]
[ text (I18n.translate language I18n.Share) ]
, div [ class "panel-body chart" ]
-- [ button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-facebook" ]
-- []
-- ]
[ a
[ class "btn btn-default btn-action btn-round twitter-share-button"
, href
(let
url =
Urls.fullUrl
(Routes.makeUrlWithLanguage language ("/collections/" ++ collection.id))
(let
url =
Urls.fullUrl
(Routes.makeUrlWithLanguage language ("/collections/" ++ collection.id))
-- TODO: i18n
in
("https://twitter.com/intent/tweet?text="
++ Http.encodeUri
(I18n.translate
language
(I18n.TweetMessage collection.name url)
)
)
)
]
[ i [ attribute "aria-hidden" "true", class "fa fa-twitter" ]
[]
twitterUrl =
"https://twitter.com/intent/tweet?text="
++ Http.encodeUri (I18n.translate language (I18n.TweetMessage collection.name url))
in
-- [ button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-facebook" ]
-- []
-- ]
[ a
[ class "btn btn-default btn-action btn-round"
, href twitterUrl
, onWithOptions
"click"
{ stopPropagation = True, preventDefault = True }
(Decode.succeed (ForSelf <| Tweet twitterUrl))
-- , onClick (ForSelf <| Tweet twitterUrl)
]
[ i [ attribute "aria-hidden" "true", class "fa fa-twitter" ] [] ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-google-plus" ]
-- []
-- ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-linkedin" ]
-- []
-- ]
]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-google-plus" ]
-- []
-- ]
-- , button [ class "btn btn-default btn-action btn-round", type' "button" ]
-- [ i [ attribute "aria-hidden" "true", class "fa fa-linkedin" ]
-- []
-- ]
]
)
]
]
]
......
......@@ -5,47 +5,6 @@ import Types exposing (DocumentMetadata, PopularTag, User, UserForPort)
import Urls
-- DOCUMENT METADATA
type alias DocumentMetatags =
{ description : String
, imageUrl : String
, title : String
, twitterName : String
}
setDocumentMetadata : DocumentMetadata -> Cmd msg
setDocumentMetadata metadata =
setDocumentMetatags
{ description = metadata.description
, imageUrl = Urls.fullApiUrl metadata.imageUrl ++ "?dim=500"
, title = metadata.title
, twitterName = Configuration.twitterName
}
port setDocumentMetatags : DocumentMetatags -> Cmd msg
-- IMAGE UPLOAD
type alias ImagePortData =
{ contents : String
, filename : String
}
port fileSelected : String -> Cmd msg
port fileContentRead : (ImagePortData -> msg) -> Sub msg
-- AUTHENTICATION
......@@ -94,3 +53,51 @@ port bubbleSelections : (D3BubblesPopularTag -> msg) -> Sub msg
port bubbleDeselections : (D3BubblesPopularTag -> msg) -> Sub msg
-- DOCUMENT METADATA
type alias DocumentMetatags =
{ description : String
, imageUrl : String
, title : String
, twitterName : String
}
setDocumentMetadata : DocumentMetadata -> Cmd msg
setDocumentMetadata metadata =
setDocumentMetatags
{ description = metadata.description
, imageUrl = Urls.fullApiUrl metadata.imageUrl ++ "?dim=500"
, title = metadata.title
, twitterName = Configuration.twitterName
}
port setDocumentMetatags : DocumentMetatags -> Cmd msg
-- IMAGE UPLOAD
type alias ImagePortData =
{ contents : String
, filename : String
}
port fileSelected : String -> Cmd msg
port fileContentRead : (ImagePortData -> msg) -> Sub msg
-- TWITTER
port tweet : String -> Cmd msg
......@@ -169,3 +169,18 @@ main.ports.storeAuthentication.subscribe(function (authentication) {
window.localStorage.removeItem('authentication');
}
});
main.ports.tweet.subscribe(function (url) {
var height = 420,
width = 550,
winHeight = screen.height,
winWidth = screen.width;
var left = Math.round((winWidth / 2) - (width / 2)),
top = 0;
if (winHeight > height) {
top = Math.round((winHeight / 2) - (height / 2));
}
window.open(url, 'intent', 'scrollbars=yes,resizable=yes,toolbar=no,location=yes,width=' + width +
',height=' + height + ',left=' + left + ',top=' + top);
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment