Skip to content

Commit

Permalink
Adapt NotificationActionBarComponent to use state
Browse files Browse the repository at this point in the history
Instead of type.
  • Loading branch information
saraycp committed May 22, 2024
1 parent 35eccdb commit e94910a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/api/app/components/notification_action_bar_component.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

class NotificationActionBarComponent < ApplicationComponent
attr_accessor :type, :update_path, :show_read_all_button
attr_accessor :state, :update_path, :show_read_all_button

def initialize(type:, update_path:, show_read_all_button: false)
def initialize(state:, update_path:, show_read_all_button: false)
super

@type = type
@state = state
@update_path = add_params(update_path)
@show_read_all_button = show_read_all_button
end

def button_text(all: false)
text = type == 'read' ? 'Unread' : 'Read'
text = state == 'read' ? 'Unread' : 'Read'
if all
"Mark all as '#{text}'"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
project: selected_filter[:project], group: selected_filter[:group],
page: params[:page], show_more: params[:show_more])
= form_tag(update_path, method: :put, remote: true) do
= render(NotificationActionBarComponent.new(type: selected_filter[:kind], update_path: update_path, show_read_all_button: show_read_all_button))
= render(NotificationActionBarComponent.new(state: selected_filter[:state], update_path: update_path, show_read_all_button: show_read_all_button))
.card
.card-body
.text-center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
context 'for unread notifications' do
before do
User.session = create(:user)
render_inline(described_class.new(type: 'unread', update_path: 'my/notifications', show_read_all_button: true))
render_inline(described_class.new(state: 'unread', update_path: 'my/notifications', show_read_all_button: true))
end

it do
Expand All @@ -25,15 +25,15 @@
context 'for read notifications' do
before do
User.session = create(:user)
render_inline(described_class.new(type: 'read', update_path: 'my/notifications?type=read', show_read_all_button: true))
render_inline(described_class.new(state: 'read', update_path: 'my/notifications?state=read', show_read_all_button: true))
end

it do
expect(rendered_content).to have_text("Mark all as 'Unread'")
end

it do
expect(rendered_content).to have_link(href: 'my/notifications?type=read&update_all=true')
expect(rendered_content).to have_link(href: 'my/notifications?state=read&update_all=true')
end

it do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class NotificationActionBarComponentPreview < ViewComponent::Preview
# Preview at http://HOST:PORT/rails/view_components/notification_action_bar_component/type_read
def type_read
render(NotificationActionBarComponent.new(type: 'read', update_path: 'my/notifications?type=read&update_all=true', show_read_all_button: true))
# Preview at http://HOST:PORT/rails/view_components/notification_action_bar_component/state_read
def state_read
render(NotificationActionBarComponent.new(state: 'read', update_path: 'my/notifications?state=read&update_all=true', show_read_all_button: true))
end

# Preview at http://HOST:PORT/rails/view_components/notification_action_bar_component/type_unread
def type_unread
render(NotificationActionBarComponent.new(type: 'unread', update_path: 'my/notifications?type=unread&update_all=true', show_read_all_button: true))
# Preview at http://HOST:PORT/rails/view_components/notification_action_bar_component/state_unread
def state_unread
render(NotificationActionBarComponent.new(state: 'unread', update_path: 'my/notifications?state=unread&update_all=true', show_read_all_button: true))
end
end

0 comments on commit e94910a

Please sign in to comment.