Path: blob/main/src/vs/workbench/contrib/comments/browser/reactionsAction.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as nls from '../../../../nls.js';6import * as dom from '../../../../base/browser/dom.js';7import * as cssJs from '../../../../base/browser/cssValue.js';8import { Action, IAction } from '../../../../base/common/actions.js';9import { URI, UriComponents } from '../../../../base/common/uri.js';10import { ActionViewItem } from '../../../../base/browser/ui/actionbar/actionViewItems.js';1112export class ToggleReactionsAction extends Action {13static readonly ID = 'toolbar.toggle.pickReactions';14private _menuActions: IAction[] = [];15private toggleDropdownMenu: () => void;16constructor(toggleDropdownMenu: () => void, title?: string) {17super(ToggleReactionsAction.ID, title || nls.localize('pickReactions', "Pick Reactions..."), 'toggle-reactions', true);18this.toggleDropdownMenu = toggleDropdownMenu;19}20override run(): Promise<any> {21this.toggleDropdownMenu();22return Promise.resolve(true);23}24get menuActions() {25return this._menuActions;26}27set menuActions(actions: IAction[]) {28this._menuActions = actions;29}30}31export class ReactionActionViewItem extends ActionViewItem {32constructor(action: ReactionAction) {33super(null, action, {});34}35protected override updateLabel(): void {36if (!this.label) {37return;38}3940const action = this.action as ReactionAction;41if (action.class) {42this.label.classList.add(action.class);43}44if (!action.icon) {45const reactionLabel = dom.append(this.label, dom.$('span.reaction-label'));46reactionLabel.innerText = action.label;47} else {48const reactionIcon = dom.append(this.label, dom.$('.reaction-icon'));49const uri = URI.revive(action.icon);50reactionIcon.style.backgroundImage = cssJs.asCSSUrl(uri);51}52if (action.count) {53const reactionCount = dom.append(this.label, dom.$('span.reaction-count'));54reactionCount.innerText = `${action.count}`;55}56}5758protected override getTooltip(): string | undefined {59const action = this.action as ReactionAction;60const toggleMessage = action.enabled ? nls.localize('comment.toggleableReaction', "Toggle reaction, ") : '';6162if (action.count === undefined) {63return nls.localize({64key: 'comment.reactionLabelNone', comment: [65'This is a tooltip for an emoji button so that the current user can toggle their reaction to a comment.',66'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is the name of the reaction.']67}, "{0}{1} reaction", toggleMessage, action.label);68} else if (action.reactors === undefined || action.reactors.length === 0) {69if (action.count === 1) {70return nls.localize({71key: 'comment.reactionLabelOne', comment: [72'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is 1.',73'The emoji is also a button so that the current user can also toggle their own emoji reaction.',74'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is the name of the reaction.']75}, "{0}1 reaction with {1}", toggleMessage, action.label);76} else if (action.count > 1) {77return nls.localize({78key: 'comment.reactionLabelMany', comment: [79'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is greater than 1.',80'The emoji is also a button so that the current user can also toggle their own emoji reaction.',81'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is number of users who have reacted with that reaction, and the third is the name of the reaction.']82}, "{0}{1} reactions with {2}", toggleMessage, action.count, action.label);83}84} else {85if (action.reactors.length <= 10 && action.reactors.length === action.count) {86return nls.localize({87key: 'comment.reactionLessThanTen', comment: [88'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is less than or equal to 10.',89'The emoji is also a button so that the current user can also toggle their own emoji reaction.',90'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second iis a list of the reactors, and the third is the name of the reaction.']91}, "{0}{1} reacted with {2}", toggleMessage, action.reactors.join(', '), action.label);92} else if (action.count > 1) {93const displayedReactors = action.reactors.slice(0, 10);94return nls.localize({95key: 'comment.reactionMoreThanTen', comment: [96'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is less than or equal to 10.',97'The emoji is also a button so that the current user can also toggle their own emoji reaction.',98'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second iis a list of the reactors, and the third is the name of the reaction.']99}, "{0}{1} and {2} more reacted with {3}", toggleMessage, displayedReactors.join(', '), action.count - displayedReactors.length, action.label);100}101}102return undefined;103}104}105export class ReactionAction extends Action {106static readonly ID = 'toolbar.toggle.reaction';107constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Promise<any>, public readonly reactors?: readonly string[], public icon?: UriComponents, public count?: number) {108super(ReactionAction.ID, label, cssClass, enabled, actionCallback);109}110}111112113