Add mute action support in user action handler

This commit is contained in:
Andreas Nedbal 2022-12-28 03:00:52 +01:00 committed by Andreas Nedbal
parent 361b8df798
commit 409c8372ba
6 changed files with 44 additions and 3 deletions

View File

@ -27,6 +27,14 @@ export function userActionHandler(event: Event): void {
targetURL = '/ajax/destroy_relationship';
relationshipType = 'block';
break;
case 'mute':
targetURL = '/ajax/create_relationship';
relationshipType = 'mute';
break;
case 'unmute':
targetURL = '/ajax/destroy_relationship';
relationshipType = 'mute';
break;
}
let success = false;
@ -77,6 +85,22 @@ export function userActionHandler(event: Event): void {
button.classList.add('btn-primary');
}
break;
case 'mute':
button.dataset.action = 'unmute';
button.querySelector('span').innerText = I18n.translate('voc.unmute');
if (button.classList.contains('btn')) {
button.classList.remove('btn-primary');
button.classList.add('btn-default');
}
break;
case 'unmute':
button.dataset.action = 'mute';
button.querySelector('span').innerText = I18n.translate('voc.mute');
if (button.classList.contains('btn')) {
button.classList.remove('btn-default');
button.classList.add('btn-primary');
}
break;
}
});
}
@ -86,4 +110,4 @@ function resetFollowButton(button: HTMLButtonElement) {
button.innerText = I18n.translate('voc.follow');
button.classList.remove('btn-default');
button.classList.add('btn-primary');
}
}

View File

@ -6,6 +6,7 @@ export default (): void => {
registerEvents([
{ type: 'click', target: 'button[name=user-action]', handler: userActionHandler, global: true },
{ type: 'click', target: '[data-action=block], [data-action=unblock]', handler: userActionHandler, global: true },
{ type: 'click', target: '[data-action=mute], [data-action=unmute]', handler: userActionHandler, global: true },
{ type: 'click', target: 'a[data-action=report-user]', handler: userReportHandler, global: true }
]);
}
}

View File

@ -25,6 +25,14 @@
%a.dropdown-item{ href: '#', data: { action: :block, target: user.screen_name } }
%i.fa.fa-minus-circle
%span.pe-none= t("voc.block")
- if current_user.muting?(user)
%a.dropdown-item{ href: '#', data: { action: :unmute, target: user.screen_name } }
%i.fa.fa-volume-off
%span.pe-none= t("voc.unmute")
- else
%a.dropdown-item{ href: '#', data: { action: :mute, target: user.screen_name } }
%i.fa.fa-volume-off
%span.pe-none= t("voc.mute")
%a.dropdown-item{ href: '#', data: { action: 'report-user', target: user.screen_name } }
%i.fa.fa-exclamation-triangle
= t("voc.report")

View File

@ -107,6 +107,9 @@ en:
follow:
success: "Successfully followed user."
error: "You are already following that user."
mute:
success: "Successfully muted user."
error: "You are already muting that user."
destroy:
block:
success: "Successfully unblocked user."
@ -114,6 +117,9 @@ en:
follow:
success: "Successfully unfollowed user."
error: "You are not following that user."
mute:
success: "Successfully unmuted user."
error: "You are not muting that user."
report:
create:
noauth: :ajax.noauth

View File

@ -13,6 +13,7 @@ en:
load: "Load more"
login: "Sign in"
logout: "Sign out"
mute: "Mute"
save: "Save changes"
show_anonymous_questions: "Show all questions from this user"
subscribe: "Subscribe"
@ -23,6 +24,7 @@ en:
terms: "Terms of Service"
unblock: "Unblock"
unfollow: "Unfollow"
unmute: "Unmute"
update: "Update"
view_in_rails_admin: "View in Rails Admin"
"y": "Yes"

View File

@ -5,5 +5,5 @@ require "dry-types"
module Types
include Dry.Types()
RelationshipTypes = Types::String.enum("follow", "block")
RelationshipTypes = Types::String.enum("follow", "block", "mute")
end