File tree Expand file tree Collapse file tree 5 files changed +36
-10
lines changed
javascript/controllers/snippets Expand file tree Collapse file tree 5 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ def new
14
14
def create
15
15
@snippet = Snippet . find ( params [ :snippet_id ] )
16
16
@snippet . attach_screenshot_from_base64 ( params [ :screenshot ] )
17
- redirect_to new_share_snippet_tweet_path ( @snippet ) , notice : "Screenshot attached" . emojoy
17
+ redirect_to new_share_snippet_tweet_path ( @snippet , auto : true ) , notice : "Screenshot attached" . emojoy
18
18
end
19
19
end
Original file line number Diff line number Diff line change @@ -3,5 +3,6 @@ class Share::SnippetTweetsController < ApplicationController
3
3
4
4
def new
5
5
@snippet = Snippet . find ( params [ :snippet_id ] )
6
+ @auto = params [ :auto ] == "true"
6
7
end
7
8
end
Original file line number Diff line number Diff line change @@ -7,20 +7,27 @@ const console = debug('app:javascript:controllers:snippets:tweet');
7
7
export default class extends Controller {
8
8
static values = {
9
9
url : String ,
10
+ auto : Boolean ,
10
11
} ;
11
12
12
13
declare urlValue : string ;
14
+ declare autoValue : boolean ;
13
15
14
16
connect ( ) {
15
17
console . log ( 'Connect!' ) ;
16
18
17
- this . tweet ( ) ;
19
+ if ( this . autoValue ) {
20
+ this . tweet ( ) ;
21
+ }
18
22
}
19
23
20
24
tweet ( ) {
21
25
console . log ( 'Tweet!' ) ;
22
26
23
- const tweetText = encodeURIComponent ( this . urlValue ) ;
27
+ const url = this . urlValue ;
28
+
29
+ const tweetText = encodeURIComponent ( `Created with @joyofrails ${ url } ` ) ;
30
+
24
31
const tweetUrl = `https://twitter.com/intent/tweet?text=${ tweetText } ` ;
25
32
26
33
window . open (
Original file line number Diff line number Diff line change 1
1
<%= render Pages::Header.new(title: "Share Snippet: Tweet") %>
2
2
<div class ="section-content container py-gap ">
3
3
<%= turbo_frame_tag :snippet_form , data : { turbo_action : "advance" } do %>
4
- <%= render Share ::SnippetTweets ::Tweet . new ( @snippet ) %>
4
+ <%= render Share ::SnippetTweets ::Tweet . new ( @snippet , auto : @auto ) %>
5
5
<% end %>
6
6
7
7
< div >
Original file line number Diff line number Diff line change 1
1
class Share ::SnippetTweets ::Tweet < ApplicationComponent
2
- def initialize ( snippet )
2
+ include Phlex ::Rails ::Helpers ::ButtonTag
3
+ include Phlex ::Rails ::Helpers ::ClassNames
4
+ include PhlexConcerns ::FlexBlock
5
+
6
+ def initialize ( snippet , auto : false )
3
7
@snippet = snippet
8
+ @auto = auto
4
9
end
5
10
6
11
def view_template
7
- render CodeBlock ::Snippet . new (
8
- @snippet ,
9
- screenshot : true ,
12
+ div (
13
+ class : "snippet-tweet grid-content" ,
10
14
data : {
11
15
controller : "snippet-tweet" ,
12
- snippet_tweet_url_value : tweet_url
16
+ snippet_tweet_url_value : tweet_url ,
17
+ snippet_tweet_auto_value : auto? . to_s
13
18
}
14
- )
19
+ ) do
20
+ render CodeBlock ::Snippet . new (
21
+ @snippet ,
22
+ screenshot : true
23
+ )
24
+
25
+ flex_block do
26
+ button_tag "Tweet" ,
27
+ class : class_names ( "button" , "primary" , hidden : auto? ) ,
28
+ data : { action : "click->snippet-tweet#tweet" }
29
+ end
30
+ end
15
31
end
16
32
17
33
def tweet_url
18
34
@snippet . screenshot . attached? ? rails_storage_proxy_url ( @snippet . screenshot ) : share_snippet_url ( @snippet )
19
35
end
36
+
37
+ def auto? = !!@auto
20
38
end
You can’t perform that action at this time.
0 commit comments