Skip to content

Commit

Permalink
AO3-5901 Pseud switcher text on the New Pseud page (#4579)
Browse files Browse the repository at this point in the history
* AO3-5901 Pseud switcher text on the New Pseud page

Provide fallback text for the edge case of the New Pseud page, where `@pseud` is defined, but doesn't have a `name` yet.

* Update app/views/users/_sidebar.html.erb

Co-authored-by: sarken <[email protected]>

* AO3-5901 Ensure pseud switcher shows current pseud

When we started limiting the number of pseuds in the sidebar, the way to guarantee that the current pseud would show up in the sidebar was to show it at the top of the pseud switcher.

However, [AO3-6249](https://otwarchive.atlassian.net/browse/AO3-6249) decided that the pseud switcher should always say "Pseuds" at the top.

We broke this behaviour in #4554.

Fixing it in c3e4ab9 resulted in the current pseud not showing in the sidebar in some conditions.

Move or add the current pseud at the beginning of the list, whether or not it is present in the abbreviated list.

We are aware that this could make the abbreviated list in the pseud switcher show `ITEMS_PER_PAGE` + 1 pseuds in some cases, discuss with @sarken if you disagree.

* AO3-5901 Don't use instance vars in helpers

The Hound has arisen from its slumber as soon as I touched some ancient scrolls, and so I've tried to appease it with the following sacrifices:
- add spaces after and before curly bois (`{` and `}`)
- IN-TER-PO-LATE! IN-TER-PO-LATE! (AKA prefer interpolation to string concatenation)
- stop using instance vars in helper method

The latter change has morally forced my hand to:
-  separate the method that determines which pseuds to show in the sidebar selector from the method that outputs the HTML
- remove the `print_` prefix from the method that I touched, as [per precedent](50f7b7e)

* AO3-5901 Remove code unused since 2013

This method has had no callers since c10ef8a#diff-638a702b43ccba6b5dcb42edd2c6f8bb4ba56c492cb2ef7ccf56815663743e07.

Tacking it onto this issue because its presence confused me when deciding whether the `pseuds_for_sidebar` method belonged in the user helper or the pseud helper.

---------

Co-authored-by: sarken <[email protected]>
  • Loading branch information
neuroalien and sarken authored Jul 16, 2023
1 parent ff9f334 commit d997475
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
12 changes: 9 additions & 3 deletions app/helpers/pseuds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ def print_pseud_list(user, pseuds, first: true)
end
end

def pseuds_for_sidebar(user, pseud)
pseuds = user.pseuds.abbreviated_list - [pseud]
pseuds = pseuds.sort
pseuds = [pseud] + pseuds if pseud && !pseud.new_record?
pseuds
end

# used in the sidebar
def print_pseud_selector(pseuds)
pseuds -= [@pseud] if @pseud && @pseud.new_record?
list = pseuds.sort.collect {|pseud| "<li>" + span_if_current(pseud.name, [pseud.user, pseud]) + "</li>"}.join("").html_safe
def pseud_selector(pseuds)
pseuds.collect { |pseud| "<li>#{span_if_current(pseud.name, [pseud.user, pseud])}</li>" }.join.html_safe
end
end
11 changes: 0 additions & 11 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ def is_maintainer?
current_user.is_a?(User) ? current_user.maintained_collections.present? : false
end

def sidebar_pseud_link_text(user, pseud)
text = if current_page?(user)
ts('Pseuds')
elsif pseud.present? && !pseud.new_record?
pseud.name
else
user.login
end
(text + ' &#8595;').html_safe
end

# Prints user pseuds with links to anchors for each pseud on the page and the description as the title
def print_pseuds(user)
user.pseuds.collect(&:name).join(', ')
Expand Down
5 changes: 2 additions & 3 deletions app/views/users/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<li><%= span_if_current ts("Profile"), user_profile_path(@user) %></li>
<% if @user.pseuds.size > 1 %>
<li class="pseud" aria-haspopup="true">
<% pseud_link_text = current_page?(@user) ? ts("Pseuds") : (@pseud ? @pseud.name : @user.login) %>
<a href="#" title="<%= ts("Pseud Switcher") %>"><%= pseud_link_text %></a>
<a href="#" title="<%= ts("Pseud Switcher") %>"><%= ts("Pseuds") %></a>
<ul class="expandable secondary">
<%= print_pseud_selector(@user.pseuds.abbreviated_list) %>
<%= pseud_selector(pseuds_for_sidebar(@user, @pseud)) %>
<li><%= span_if_current ts("All Pseuds (%{pseud_number})", :pseud_number => @user.pseuds.count), user_pseuds_path(@user) %></li>
</ul>
</li>
Expand Down
4 changes: 2 additions & 2 deletions features/other_a/pseuds.feature
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ Scenario: Many pseuds
And I should see "All Pseuds (4)" within "ul.expandable"

When I go to my "Slartibartfast" pseud page
Then I should see "Slartibartfast" within "li.pseud > a"
And I should not see "Slartibartfast" within "ul.expandable"
Then I should see "Pseuds" within "li.pseud > a"
And I should see "Slartibartfast" within "ul.expandable"

When I go to my pseuds page
Then I should not see "Zaphod (Zaphod)" within "ul.pseud.index"
Expand Down

0 comments on commit d997475

Please sign in to comment.