Skip to content

Commit 25c3de0

Browse files
committed
Update screenshot and share ux
1 parent fb4c1fd commit 25c3de0

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

app/javascript/controllers/snippets/tweet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class extends Controller {
2828

2929
const tweetText = encodeURIComponent(`Created with @joyofrails ${url}`);
3030

31-
const tweetUrl = `https://twitter.com/intent/tweet?text=${tweetText}`;
31+
const tweetUrl = `https://x.com/intent/post?text=${tweetText}`;
3232

3333
window.open(
3434
tweetUrl,

app/views/share/snippets/index.html.erb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
<% end %>
88

99
<% @snippets.each do |snippet| %>
10-
<%= link_to share_snippet_path(snippet), class: "block" do %>
11-
<%= render CodeBlock::Snippet.new(snippet) %>
12-
<% end %>
10+
<div id="<%= dom_id(snippet) %>" class="section-content">
11+
<%= link_to share_snippet_path(snippet), class: "block" do %>
12+
<%= render CodeBlock::Snippet.new(snippet) %>
13+
<% end %>
14+
<div>
15+
<%= render Share::Snippets::Toolbar.new(snippet, current_user: current_user) %>
16+
</div>
17+
</div>
1318
<% end %>
1419
</div>

app/views/share/snippets/show.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<%= render CodeBlock::Snippet.new(@snippet) %>
1717
<% end %>
1818

19-
<%= render Share::Snippets::Toolbar.new(@snippet, current_user: current_user) %>
19+
<div>
20+
<%= render Share::Snippets::Toolbar.new(@snippet, current_user: current_user) %>
21+
</div>
2022

2123
<div>
2224
<%= link_to "Back to snippets", share_snippets_path %>

app/views/share/snippets/toolbar.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ def initialize(snippet, current_user: nil)
99
end
1010

1111
def view_template
12-
div do
13-
flex_block do
14-
link_to "Share", new_share_snippet_tweet_path(@snippet, auto: "true"), class: "button primary"
15-
if @current_user&.can_edit?(@snippet)
16-
link_to "Edit this snippet", edit_share_snippet_path(@snippet), class: "button secondary"
17-
end
12+
flex_block do
13+
link_to "Share", share_url, class: "button primary"
14+
if @current_user&.can_edit?(@snippet)
15+
link_to "Edit this snippet", edit_share_snippet_path(@snippet), class: "button secondary"
1816
end
1917
end
2018
end
19+
20+
def share_url
21+
if @snippet.screenshot.attached?
22+
new_share_snippet_tweet_path(@snippet, auto: "true")
23+
else
24+
new_share_snippet_screenshot_path(@snippet)
25+
end
26+
end
2127
end

spec/rails_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@
7171
# config.filter_gems_from_backtrace("gem name")
7272

7373
config.include ActiveSupport::Testing::TimeHelpers
74+
75+
config.after(:all) do
76+
FileUtils.rm_rf(ActiveStorage::Blob.service.root)
77+
end
7478
end

spec/system/snippets_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,27 @@
4242
expect(page).to have_content("lib/models/blog.rb")
4343
expect(page).to have_content("class Blog\n has_many :posts\nend")
4444
end
45+
46+
it "can attach a screenshot" do
47+
snippet = FactoryBot.create(:snippet, author: login_as_user)
48+
49+
visit share_snippet_path(snippet)
50+
51+
click_link "Share"
52+
53+
expect(page).to have_content("Screenshot")
54+
end
55+
56+
it "can share Snippet" do
57+
snippet = FactoryBot.create(:snippet, author: login_as_user)
58+
59+
visit share_snippets_path
60+
61+
within("#snippets") do
62+
expect(page).to have_content(snippet.filename)
63+
click_link "Share"
64+
end
65+
66+
expect(page).to have_content("Screenshot")
67+
end
4568
end

0 commit comments

Comments
 (0)