Skip to content

Commit 5d46e43

Browse files
committed
feature/Use tooltips to denote current page
1 parent f4f83b1 commit 5d46e43

File tree

10 files changed

+60
-18
lines changed

10 files changed

+60
-18
lines changed

app/controllers/folders_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
class FoldersController < ApplicationController
2-
# layout 'application_mid_width', only: :index
3-
42
MINIMUM_FOLDERS = 1.freeze
53

64
before_action :authenticate_user!
@@ -17,12 +15,9 @@ def popover
1715

1816
def index
1917
@snippets = Snippet.last(5)
20-
@page_title = 'Folders'
2118

2219
@folders = current_user.folders
23-
2420
@folders = @folders.where('name ILIKE ?', "%#{params[:search]}%") if params[:search].present?
25-
2621
@folders = @folders
2722
.order(name: :asc)
2823
.paginate(page: params[:page] || 1, per_page: 30)

app/controllers/home_controller.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def index
55
@languages = Language.order(name: :asc).to_json
66

77
if user_signed_in?
8-
@page_title = 'Feed'
98
@snippets = current_user
109
.snippets_for_feed
1110
.includes(:language)
@@ -31,8 +30,6 @@ def index
3130
end
3231

3332
def connect
34-
@page_title = 'Connect'
35-
3633
@users = if user_signed_in?
3734
current_user.not_following
3835
.paginate(page: params[:page] || 1, per_page: 16)

app/controllers/notifications_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class NotificationsController < ApplicationController
22
after_action -> { current_user.mark_notifications_as_read }, only: :index
33

44
def index
5-
@page_title = 'Notifications'
65
@notifications = current_user.notifications.order(created_at: :desc)
76
end
87
end

app/controllers/registrations_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def create
3333
end
3434

3535
def edit
36+
@page_title = 'Account'
3637
@tab_id = params[:tab_id] || :account
3738
super
3839
end

app/controllers/snippets_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class SnippetsController < ApplicationController
22
before_action :authenticate_user!, except: :show
33

44
def index
5-
@page_title = "Snippets"
65
@user = User.find_by(id: params[:user_id]) || current_user
76
@display_popover = true
87
@snippets = @user.filed_snippets.includes(:user, :folders)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Controller } from 'stimulus';
2+
import { events } from '../mixins/events'
3+
4+
export default class extends Controller {
5+
static targets = ['tooltip']
6+
7+
initialize() {
8+
events(this);
9+
}
10+
11+
display() {
12+
this.tooltipTarget.classList.remove('hidden')
13+
this.emitEvent('hide-tooltip')
14+
}
15+
16+
hide() {
17+
this.tooltipTarget.classList.add('hidden')
18+
this.emitEvent('display-tooltip')
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Controller } from 'stimulus';
2+
3+
export default class extends Controller {
4+
static targets = ['tooltip']
5+
6+
display() {
7+
this.tooltipTarget.classList.remove('hidden')
8+
}
9+
10+
hide() {
11+
this.tooltipTarget.classList.add('hidden')
12+
}
13+
}

app/views/layouts/application.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
</main>
6363
<aside class="xl:block xl:col-span-3">
6464
<div class="sticky position-sticky--topbar space-y-4">
65-
6665
<% if user_signed_in? %>
6766
<%=
6867
button_tag(

app/views/shared/_nav_item.html.erb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
<% color = active ? 'text-cyan' : 'text-gray-400 hover:text-cyan transition' %>
44
<% css_class = active ? 'active' : 'inactive' %>
55

6-
<%= link_to(path, class: 'relative px-3') do %>
6+
<%= link_to(path, class: 'relative px-3', data: { controller: 'tooltip', action: 'mouseenter->tooltip#display mouseleave->tooltip#hide' }) do %>
77
<%= render partial: "shared/icons/#{icon}", locals: { width: 7, height: 7, color: color } %>
88
<% if path == notifications_path %>
99
<%= notification_counter(current_user) %>
1010
<% end %>
11+
12+
<div
13+
class="hidden shadow-sm transition px-2 absolute text-sm bg-white text-cyan transform rounded-sm m-auto -bottom-6 left-1/2 -translate-x-2/4"
14+
data-tooltip-target="tooltip"
15+
>
16+
<span><%= page_title %></span>
17+
</div>
18+
19+
<% if active %>
20+
<div data-controller="tooltip-listener" data-tooltip-listener-target="tooltip" data-action="hide-tooltip@window->tooltip-listener#hide display-tooltip@window->tooltip-listener#display" class="transition shadow-sm px-2 absolute text-sm bg-white text-cyan transform rounded-sm m-auto -bottom-6 left-1/2 -translate-x-2/4">
21+
<span><%= page_title %></span>
22+
</div>
23+
<% end %>
1124
<% end %>

app/views/shared/_topbar.html.erb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
<% end %>
88
</div>
99

10-
<div class="flex v-center">
10+
<div class="flex v-center relative">
1111
<% if user_signed_in? %>
12-
<%= render partial: 'shared/nav_item', locals: { path: root_path, icon: 'home' } %>
13-
<%= render partial: 'shared/nav_item', locals: { path: folders_path, icon: 'folder' } %>
14-
<%= render partial: 'shared/nav_item', locals: { path: snippets_path, icon: 'snippet' } %>
15-
<%= render partial: 'shared/nav_item', locals: { path: notifications_path, icon: 'bell' } %>
16-
<%= render partial: 'shared/nav_item', locals: { path: connect_path, icon: 'connect' } %>
12+
<%= render partial: 'shared/nav_item', locals: { path: root_path, page_title: 'Feed', icon: 'home' } %>
13+
<%= render partial: 'shared/nav_item', locals: { path: folders_path, page_title: 'Folders', icon: 'folder' } %>
14+
<%= render partial: 'shared/nav_item', locals: { path: snippets_path, page_title: 'Snippets', icon: 'snippet' } %>
15+
<%= render partial: 'shared/nav_item', locals: { path: notifications_path, page_title: 'Notifications', icon: 'bell' } %>
16+
<%= render partial: 'shared/nav_item', locals: { path: connect_path, page_title: 'Connect', icon: 'connect' } %>
17+
<% end %>
18+
19+
<% if @page_title %>
20+
<div data-controller="tooltip-listener" data-tooltip-listener-target="tooltip" data-action="hide-tooltip@window->tooltip-listener#hide display-tooltip@window->tooltip-listener#display" class="transition shadow-sm px-2 absolute text-sm bg-white text-cyan transform rounded-sm m-auto -bottom-2.5 left-1/2 -translate-x-2/4">
21+
<span><%= @page_title %></span>
22+
</div>
1723
<% end %>
1824
</div>
1925

0 commit comments

Comments
 (0)