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