Skip to content

Commit

Permalink
Move publish button next to edit button
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislo committed Dec 11, 2024
1 parent 4b8356d commit 4044653
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
24 changes: 11 additions & 13 deletions app/views/albums/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
%>

<div class="flex flex-row justify-end">
<div class="flex flex-row gap-3 justify-end mb-3">
<% if policy(@album).edit? %>
<%= link_to edit_artist_album_path(@album.artist, @album), class: 'flex gap-2 items-center px-3 py-2 border-2 border-rose-400 text-rose-400 cursor-pointer' do %>
<svg class="fill-rose-400" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -20,6 +20,16 @@
Edit
<% end %>
<% end %>

<% if policy(@album).request_publication? && !@album.published? %>
<%= button_to [:request_publication, @album.artist, @album], disabled: @album.pending?, class: 'flex gap-2 px-3 py-3 bg-rose-400 hover:bg-rose-500 text-white cursor-pointer disabled:cursor-not-allowed disabled:bg-slate-300' do %>
<% if @album.pending? %>
Pending publication
<% else %>
Publish
<% end %>
<% end %>
<% end %>
</div>

<div data-controller="player">
Expand Down Expand Up @@ -127,18 +137,6 @@
<% end %>
</div>

<% content_for :navbar do %>
<% if policy(@album).request_publication? && !@album.published? %>
<%= button_to [:request_publication, @album.artist, @album], disabled: @album.pending?, class: 'px-2 py-1 bg-amber-600 hover:bg-amber-500 text-white cursor-pointer text-sm disabled:cursor-not-allowed disabled:bg-slate-300' do %>
<% if @album.pending? %>
Pending publication
<% else %>
Publish
<% end %>
<% end %>
<% end %>
<% end %>

<% content_for :admin do %>
<div>
<h2 class="text-2xl mb-3">Published state</h2>
Expand Down
18 changes: 6 additions & 12 deletions test/controllers/albums_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ def setup
assert_select 'li', "#{track.title} mp3v0"
end

test '#show when the album is not published has no publish button in the navbar' do
test '#show when the album is not published has no publish button' do
@album.unpublish
get artist_album_url(@album.artist, @album)

assert_select 'nav' do
assert_select 'button', text: 'Publish', count: 0
end
assert_select 'button', text: 'Publish', count: 0
end

test '#show shows the release date of the album' do
Expand Down Expand Up @@ -160,22 +158,18 @@ class AlbumsControllerTestSignedInAsArtist < ActionDispatch::IntegrationTest
assert_select 'a', text: 'Edit'
end

test '#show when the album is not published has a publish button in the navbar' do
test '#show when the album is not published has a publish button' do
@album.unpublish
get artist_album_url(@album.artist, @album)

assert_select 'nav' do
assert_select 'button', text: 'Publish'
end
assert_select 'button', text: 'Publish'
end

test '#show when the album is pending publication has a disabled pending publication button in the navbar' do
test '#show when the album is pending publication has a disabled pending publication button' do
@album.pending
get artist_album_url(@album.artist, @album)

assert_select 'nav' do
assert_select 'button[disabled=disabled]', text: 'Pending publication'
end
assert_select 'button[disabled=disabled]', text: 'Pending publication'
end

test '#request_publication sets the pending state of the album' do
Expand Down

0 comments on commit 4044653

Please sign in to comment.