Skip to content

Commit

Permalink
Add share button after you've commented
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed May 17, 2024
1 parent 81ebd34 commit c1ed46e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 2 additions & 3 deletions app/components/tailwind/share_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<button class="inline-block px-10 py-3 text-2xl font-semibold border-2 sm:py-4"
x-bind:class="{'bg-white': !copied, 'bg-light-grey2': copied,
'border-light-grey2': copied,
'text-green': !copied, 'text-navy': copied}"
'<%= @text_class %>': !copied, 'text-navy': copied}"
x-on:click="if (navigator.canShare && navigator.canShare(shareData)) {
try {
await navigator.share(shareData);
Expand All @@ -18,8 +18,7 @@
navigator.clipboard.writeText('<%= @url %>');
copied = true;
setTimeout(() => { copied = false }, 2000);
}"
>
}">
<%# Giving this a constant height to avoid any content shifts when button is clicked %>
<div class="flex items-center justify-center h-8 gap-4">
<div>
Expand Down
12 changes: 10 additions & 2 deletions app/components/tailwind/share_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ module Tailwind
class ShareButton < ViewComponent::Base
extend T::Sig

sig { params(url: String).void }
def initialize(url:)
sig { params(url: String, color: Symbol).void }
def initialize(url:, color:)
super
@url = url
case color
when :green
@text_class = T.let("text-green", String)
when :lavender
@text_class = "text-lavender"
else
raise "Unexpected color: #{color}"
end
end
end
end
6 changes: 3 additions & 3 deletions app/views/_tailwind/applications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</div>

<div class="mt-6 md:mt-2">
<%= render Tailwind::ShareButton.new(url: application_url(@application)) do %>
<%= render Tailwind::ShareButton.new(url: application_url(@application), color: :green) do %>
Share this application
<% end %>
</div>
Expand Down Expand Up @@ -141,8 +141,8 @@
Thanks, your comment has been sent to <%= comment.comment_recipient_full_name %> and posted below!
</p>
<%# TODO: Use the new share method here %>
<%= render Tailwind::ButtonComponent.new(tag: :a, size: "2xl", icon: :share, type: :inverse_lavender, href: "https://www.facebook.com/sharer/sharer.php?u=#{comment_url(Comment.first)}&t=") do %>
Share on Facebook
<%= render Tailwind::ShareButton.new(url: comment_url(comment), color: :lavender) do %>
Share your comment
<% end %>
</div>
<% end %>
Expand Down

0 comments on commit c1ed46e

Please sign in to comment.