@atlaskit/reactions 22.2.0 → 22.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/MockReactionsClient.js +1 -49
- package/dist/cjs/analytics/analytics.js +1 -40
- package/dist/cjs/analytics/index.js +0 -7
- package/dist/cjs/analytics/ufo.js +8 -20
- package/dist/cjs/client/ReactionServiceClient.js +2 -16
- package/dist/cjs/client/index.js +0 -1
- package/dist/cjs/components/Counter/Counter.js +10 -24
- package/dist/cjs/components/Counter/index.js +0 -6
- package/dist/cjs/components/Counter/styles.js +1 -3
- package/dist/cjs/components/EmojiButton/EmojiButton.js +3 -18
- package/dist/cjs/components/EmojiButton/index.js +0 -1
- package/dist/cjs/components/EmojiButton/styles.js +1 -2
- package/dist/cjs/components/FlashAnimation/FlashAnimation.js +1 -11
- package/dist/cjs/components/FlashAnimation/index.js +0 -1
- package/dist/cjs/components/FlashAnimation/styles.js +1 -3
- package/dist/cjs/components/Reaction/Reaction.js +23 -62
- package/dist/cjs/components/Reaction/index.js +0 -1
- package/dist/cjs/components/Reaction/styles.js +1 -4
- package/dist/cjs/components/ReactionDialog/ReactionView.js +6 -29
- package/dist/cjs/components/ReactionDialog/ReactionsDialog.js +19 -48
- package/dist/cjs/components/ReactionDialog/ReactionsList.js +18 -34
- package/dist/cjs/components/ReactionDialog/index.js +0 -1
- package/dist/cjs/components/ReactionDialog/styles.js +3 -13
- package/dist/cjs/components/ReactionPicker/ReactionPicker.js +41 -71
- package/dist/cjs/components/ReactionPicker/index.js +0 -1
- package/dist/cjs/components/ReactionPicker/styles.js +1 -4
- package/dist/cjs/components/ReactionTooltip/ReactionTooltip.js +13 -28
- package/dist/cjs/components/ReactionTooltip/index.js +0 -1
- package/dist/cjs/components/ReactionTooltip/styles.js +1 -3
- package/dist/cjs/components/Reactions/Reactions.js +48 -86
- package/dist/cjs/components/Reactions/index.js +0 -1
- package/dist/cjs/components/Reactions/styles.js +1 -2
- package/dist/cjs/components/Selector/Selector.js +12 -34
- package/dist/cjs/components/Selector/index.js +0 -6
- package/dist/cjs/components/Selector/styles.js +2 -5
- package/dist/cjs/components/ShowMore/ShowMore.js +5 -19
- package/dist/cjs/components/ShowMore/index.js +0 -1
- package/dist/cjs/components/ShowMore/styles.js +1 -4
- package/dist/cjs/components/Trigger/Trigger.js +6 -22
- package/dist/cjs/components/Trigger/index.js +0 -1
- package/dist/cjs/components/Trigger/styles.js +3 -13
- package/dist/cjs/components/UfoErrorBoundary/UfoErrorBoundary.js +1 -19
- package/dist/cjs/components/UfoErrorBoundary/index.js +0 -1
- package/dist/cjs/components/index.js +0 -5
- package/dist/cjs/containers/ConnectedReactionPicker/ConnectedReactionPicker.js +2 -17
- package/dist/cjs/containers/ConnectedReactionPicker/index.js +0 -1
- package/dist/cjs/containers/ConnectedReactionsView/ConnectedReactionsView.js +17 -62
- package/dist/cjs/containers/ConnectedReactionsView/index.js +0 -1
- package/dist/cjs/containers/index.js +0 -4
- package/dist/cjs/hooks/index.js +0 -1
- package/dist/cjs/hooks/useClickAway.js +2 -5
- package/dist/cjs/i18n/cs.js +0 -1
- package/dist/cjs/i18n/da.js +0 -1
- package/dist/cjs/i18n/de.js +0 -1
- package/dist/cjs/i18n/en.js +0 -1
- package/dist/cjs/i18n/en_GB.js +0 -1
- package/dist/cjs/i18n/en_ZZ.js +0 -1
- package/dist/cjs/i18n/es.js +0 -1
- package/dist/cjs/i18n/et.js +0 -1
- package/dist/cjs/i18n/fi.js +0 -1
- package/dist/cjs/i18n/fr.js +0 -1
- package/dist/cjs/i18n/hu.js +0 -1
- package/dist/cjs/i18n/index.js +0 -30
- package/dist/cjs/i18n/it.js +0 -1
- package/dist/cjs/i18n/ja.js +0 -1
- package/dist/cjs/i18n/ko.js +0 -1
- package/dist/cjs/i18n/nb.js +0 -1
- package/dist/cjs/i18n/nl.js +0 -1
- package/dist/cjs/i18n/pl.js +0 -1
- package/dist/cjs/i18n/pt_BR.js +0 -1
- package/dist/cjs/i18n/pt_PT.js +0 -1
- package/dist/cjs/i18n/ru.js +0 -1
- package/dist/cjs/i18n/sk.js +0 -1
- package/dist/cjs/i18n/sv.js +0 -1
- package/dist/cjs/i18n/th.js +0 -1
- package/dist/cjs/i18n/tr.js +0 -1
- package/dist/cjs/i18n/uk.js +0 -1
- package/dist/cjs/i18n/vi.js +0 -1
- package/dist/cjs/i18n/zh.js +0 -1
- package/dist/cjs/i18n/zh_TW.js +0 -1
- package/dist/cjs/index.js +0 -6
- package/dist/cjs/shared/constants.js +5 -6
- package/dist/cjs/shared/i18n.js +0 -2
- package/dist/cjs/shared/index.js +0 -9
- package/dist/cjs/shared/utils.js +6 -25
- package/dist/cjs/store/MemoryReactionsStore.js +21 -74
- package/dist/cjs/store/ReactionConsumer.js +0 -28
- package/dist/cjs/store/batched.js +0 -6
- package/dist/cjs/store/index.js +0 -2
- package/dist/cjs/store/utils.js +0 -25
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/types/reaction.js +0 -10
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/MockReactionsClient.js +7 -21
- package/dist/es2019/analytics/analytics.js +3 -9
- package/dist/es2019/analytics/ufo.js +11 -13
- package/dist/es2019/client/ReactionServiceClient.js +4 -13
- package/dist/es2019/components/Counter/Counter.js +5 -7
- package/dist/es2019/components/EmojiButton/EmojiButton.js +0 -3
- package/dist/es2019/components/FlashAnimation/FlashAnimation.js +1 -2
- package/dist/es2019/components/Reaction/Reaction.js +3 -12
- package/dist/es2019/components/Reaction/styles.js +1 -1
- package/dist/es2019/components/ReactionDialog/ReactionView.js +0 -4
- package/dist/es2019/components/ReactionDialog/ReactionsDialog.js +6 -15
- package/dist/es2019/components/ReactionDialog/ReactionsList.js +4 -3
- package/dist/es2019/components/ReactionDialog/styles.js +2 -5
- package/dist/es2019/components/ReactionPicker/ReactionPicker.js +14 -19
- package/dist/es2019/components/ReactionTooltip/ReactionTooltip.js +1 -2
- package/dist/es2019/components/Reactions/Reactions.js +16 -25
- package/dist/es2019/components/Selector/Selector.js +5 -11
- package/dist/es2019/components/Selector/styles.js +1 -1
- package/dist/es2019/components/ShowMore/ShowMore.js +1 -2
- package/dist/es2019/components/Trigger/Trigger.js +1 -5
- package/dist/es2019/components/UfoErrorBoundary/UfoErrorBoundary.js +0 -3
- package/dist/es2019/containers/ConnectedReactionPicker/ConnectedReactionPicker.js +0 -4
- package/dist/es2019/containers/ConnectedReactionsView/ConnectedReactionsView.js +8 -20
- package/dist/es2019/hooks/useClickAway.js +3 -4
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/shared/constants.js +5 -5
- package/dist/es2019/shared/utils.js +7 -15
- package/dist/es2019/store/MemoryReactionsStore.js +36 -61
- package/dist/es2019/store/ReactionConsumer.js +1 -12
- package/dist/es2019/store/batched.js +0 -2
- package/dist/es2019/store/utils.js +4 -8
- package/dist/es2019/types/reaction.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/MockReactionsClient.js +1 -42
- package/dist/esm/analytics/analytics.js +1 -12
- package/dist/esm/analytics/ufo.js +11 -13
- package/dist/esm/client/ReactionServiceClient.js +2 -14
- package/dist/esm/components/Counter/Counter.js +12 -15
- package/dist/esm/components/EmojiButton/EmojiButton.js +2 -6
- package/dist/esm/components/FlashAnimation/FlashAnimation.js +1 -2
- package/dist/esm/components/Reaction/Reaction.js +23 -40
- package/dist/esm/components/Reaction/styles.js +1 -1
- package/dist/esm/components/ReactionDialog/ReactionView.js +5 -14
- package/dist/esm/components/ReactionDialog/ReactionsDialog.js +20 -35
- package/dist/esm/components/ReactionDialog/ReactionsList.js +17 -20
- package/dist/esm/components/ReactionDialog/styles.js +2 -5
- package/dist/esm/components/ReactionPicker/ReactionPicker.js +42 -52
- package/dist/esm/components/ReactionTooltip/ReactionTooltip.js +14 -16
- package/dist/esm/components/Reactions/Reactions.js +49 -62
- package/dist/esm/components/Selector/Selector.js +13 -22
- package/dist/esm/components/Selector/styles.js +1 -1
- package/dist/esm/components/ShowMore/ShowMore.js +6 -7
- package/dist/esm/components/Trigger/Trigger.js +7 -11
- package/dist/esm/components/Trigger/styles.js +3 -6
- package/dist/esm/components/UfoErrorBoundary/UfoErrorBoundary.js +1 -14
- package/dist/esm/containers/ConnectedReactionPicker/ConnectedReactionPicker.js +2 -9
- package/dist/esm/containers/ConnectedReactionsView/ConnectedReactionsView.js +17 -43
- package/dist/esm/hooks/useClickAway.js +3 -4
- package/dist/esm/index.js +2 -1
- package/dist/esm/shared/constants.js +5 -5
- package/dist/esm/shared/utils.js +7 -17
- package/dist/esm/store/MemoryReactionsStore.js +22 -78
- package/dist/esm/store/ReactionConsumer.js +0 -23
- package/dist/esm/store/batched.js +0 -4
- package/dist/esm/store/utils.js +0 -9
- package/dist/esm/types/reaction.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/components/ReactionDialog/styles.d.ts +1 -2
- package/package.json +6 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Custom hook to detect when user action is outside given container ref
|
|
4
5
|
* @param ref ref object to an html element
|
|
@@ -7,7 +8,6 @@ import { useEffect } from 'react';
|
|
|
7
8
|
* @param useCapture (Optional) use capture phase of event. @default false
|
|
8
9
|
* @param enabled (Optional) enable/disable the outside click handler. @default true
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
export function useClickAway(ref, callback, type = 'click', useCapture = false, enabled = true) {
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
/**
|
|
@@ -17,9 +17,8 @@ export function useClickAway(ref, callback, type = 'click', useCapture = false,
|
|
|
17
17
|
if (ref.current && event.target instanceof Node && !ref.current.contains(event.target) && enabled) {
|
|
18
18
|
callback();
|
|
19
19
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
}
|
|
21
|
+
// Bind the event listener
|
|
23
22
|
document.addEventListener(type, handleClickOutside, useCapture);
|
|
24
23
|
return () => {
|
|
25
24
|
// Unbind the event listener on clean up
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { UFO } from './analytics';
|
|
2
|
-
export { ReactionServiceClient } from './client';
|
|
2
|
+
export { ReactionServiceClient } from './client';
|
|
3
|
+
// TODO: Convert all calls for ReactionRequest to Request, RequestClient to Client and ReactionsStore to Store
|
|
3
4
|
|
|
4
5
|
export { constants } from './shared';
|
|
5
6
|
export { Reaction, ReactionPicker, Reactions } from './components';
|
|
@@ -20,10 +20,10 @@ export const DefaultReactions = [{
|
|
|
20
20
|
id: '1f914',
|
|
21
21
|
shortName: ':thinking:'
|
|
22
22
|
}];
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* Extended list of reactions used only for examples
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
27
|
export const ExtendedReactions = [{
|
|
28
28
|
id: '1f44d',
|
|
29
29
|
shortName: ':thumbsup:'
|
|
@@ -67,25 +67,25 @@ export const ExtendedReactions = [{
|
|
|
67
67
|
id: '1f642',
|
|
68
68
|
shortName: ':slight_smile:'
|
|
69
69
|
}];
|
|
70
|
+
|
|
70
71
|
/**
|
|
71
72
|
* ES6 Map object from default emoji reactions (with key => shortName, value => entire emoji item)
|
|
72
73
|
*/
|
|
73
|
-
|
|
74
74
|
export const DefaultReactionsByShortName = new Map(DefaultReactions.map(reaction => [reaction.shortName, reaction]));
|
|
75
|
+
|
|
75
76
|
/**
|
|
76
77
|
* ES6 Map object from default emoji reactions (with key => shortName, value => entire emoji item)
|
|
77
78
|
* Only for use in extended reaction examples
|
|
78
79
|
*/
|
|
79
|
-
|
|
80
80
|
export const ExtendedReactionsByShortName = new Map(ExtendedReactions.map(reaction => [reaction.shortName, reaction]));
|
|
81
|
+
|
|
81
82
|
/**
|
|
82
83
|
* Maximum number of users to show in the tooltip for an emoji reaction
|
|
83
84
|
*/
|
|
84
|
-
|
|
85
85
|
export const TOOLTIP_USERS_LIMIT = 5;
|
|
86
|
+
|
|
86
87
|
/**
|
|
87
88
|
* Maximum number of reactions that will fit in the horizontal scroll of
|
|
88
89
|
* reactions dialog
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
91
|
export const NUMBER_OF_REACTIONS_TO_DISPLAY = 9;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { DefaultReactions } from './constants';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Is selected mouse event a left click
|
|
4
5
|
* @param event event data
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export const isLeftClick = event => event.button === 0 && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Does provided item part of the default emoji ids
|
|
10
11
|
* @param item selected emoji item
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
export const isDefaultReaction = item => DefaultReactions.some(otherEmojiId => isEqualEmojiId(otherEmojiId, item));
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* compare 2 emoji items if they are same input
|
|
16
17
|
* @param a first emoji item
|
|
17
18
|
* @param b second emoji item
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
20
|
const isEqualEmojiId = (a, b) => {
|
|
21
21
|
if (isEmojiId(a) && isEmojiId(b)) {
|
|
22
22
|
return a === b || a && b && a.id === b.id && a.shortName === b.shortName;
|
|
@@ -24,37 +24,32 @@ const isEqualEmojiId = (a, b) => {
|
|
|
24
24
|
return a === b;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
|
|
27
28
|
/**
|
|
28
29
|
* Type guard if provided object is a string id or an object info collection for the emoji
|
|
29
30
|
* @param item given item
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
32
|
const isEmojiId = item => {
|
|
34
33
|
return item.id !== undefined;
|
|
35
34
|
};
|
|
36
|
-
|
|
37
35
|
export const formatStringWithDecimal = (value, decimalPlaces) => {
|
|
38
36
|
const decimalIndex = value.indexOf('.');
|
|
39
|
-
|
|
40
37
|
if (decimalIndex === -1) {
|
|
41
38
|
// Integers with trailing 0s will have no decimal (Ex. 18000, 7700000, 500)
|
|
42
39
|
return value.substring(0, value.length);
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
if (decimalPlaces === 0) {
|
|
46
42
|
// Return an integer value
|
|
47
43
|
return value.substring(0, decimalIndex);
|
|
48
44
|
}
|
|
49
|
-
|
|
50
45
|
return value.substring(0, decimalIndex + decimalPlaces + 1);
|
|
51
46
|
};
|
|
47
|
+
|
|
52
48
|
/**
|
|
53
49
|
* Truncates numbers >= 1000 to shorthand representations with a maximum of one decimal point.
|
|
54
50
|
* If the first decimal number is a zero then it's also truncated.
|
|
55
51
|
* (Ex: 9085 will return 9K, 787555 will return 787.5M)
|
|
56
52
|
*/
|
|
57
|
-
|
|
58
53
|
export const formatLargeNumber = value => {
|
|
59
54
|
// 999M+
|
|
60
55
|
const maxLimit = 999999999;
|
|
@@ -62,11 +57,9 @@ export const formatLargeNumber = value => {
|
|
|
62
57
|
const millionSeparator = 1000 * 1000;
|
|
63
58
|
const valueInK = value / thounsandSeparator;
|
|
64
59
|
const valueInM = value / millionSeparator;
|
|
65
|
-
|
|
66
60
|
if (value > maxLimit) {
|
|
67
61
|
return '999.9M+';
|
|
68
62
|
}
|
|
69
|
-
|
|
70
63
|
if (value >= 1000000) {
|
|
71
64
|
// determine the decimal breakpoints by length and check its value
|
|
72
65
|
// 1234567 -> 1.234567 and decimal value is 2
|
|
@@ -74,13 +67,12 @@ export const formatLargeNumber = value => {
|
|
|
74
67
|
const decimalIndexValue = valueInM.toString().charAt(numDigits - 5);
|
|
75
68
|
return decimalIndexValue === '0' ? formatStringWithDecimal(valueInM.toString(), 0) + 'M' : formatStringWithDecimal(valueInM.toString(), 1) + 'M';
|
|
76
69
|
}
|
|
77
|
-
|
|
78
70
|
if (value >= 1000) {
|
|
79
71
|
const numDigits = value.toString().length;
|
|
80
72
|
const decimalIndexValue = valueInK.toString().charAt(numDigits - 2);
|
|
81
73
|
return decimalIndexValue === '0' ? formatStringWithDecimal(valueInK.toString(), 0) + 'K' : formatStringWithDecimal(valueInK.toString(), 1) + 'K';
|
|
82
|
-
}
|
|
83
|
-
|
|
74
|
+
}
|
|
84
75
|
|
|
76
|
+
// <999
|
|
85
77
|
return value.toString();
|
|
86
78
|
};
|
|
@@ -7,31 +7,29 @@ import { isRealErrorFromService } from './utils';
|
|
|
7
7
|
import { SAMPLING_RATE_REACTIONS_RENDERED_EXP } from '../analytics/constants';
|
|
8
8
|
import { sampledReactionsRendered } from '../analytics/ufo';
|
|
9
9
|
import { extractErrorInfo } from '../analytics/analytics';
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Set of all available UFO experiences relating to reaction element
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
export const ufoExperiences = {
|
|
15
15
|
/**
|
|
16
16
|
* Experience when a reaction emoji gets added
|
|
17
17
|
*/
|
|
18
18
|
add: UFO.ReactionsAdd,
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* Experience when a reaction emoji gets removed/decrement
|
|
22
21
|
*/
|
|
23
22
|
remove: UFO.ReactionsRemove,
|
|
24
|
-
|
|
25
23
|
/**
|
|
26
24
|
* Experience when the list of reactions gets rendered with sampling
|
|
27
25
|
*/
|
|
28
26
|
render: instanceId => sampledReactionsRendered(instanceId),
|
|
29
|
-
|
|
30
27
|
/**
|
|
31
28
|
* Experience when a reaction details gets fetched
|
|
32
29
|
*/
|
|
33
30
|
fetchDetails: UFO.ReactionDetailsFetch
|
|
34
31
|
};
|
|
32
|
+
|
|
35
33
|
/**
|
|
36
34
|
* Optional metadata information in the store used in sending the API client requests
|
|
37
35
|
*/
|
|
@@ -40,47 +38,44 @@ export class MemoryReactionsStore {
|
|
|
40
38
|
/**
|
|
41
39
|
* default initial store data
|
|
42
40
|
*/
|
|
41
|
+
|
|
43
42
|
constructor(client, state, metadata) {
|
|
44
43
|
_defineProperty(this, "callbacks", []);
|
|
45
|
-
|
|
46
44
|
_defineProperty(this, "initialState", {
|
|
47
45
|
reactions: {},
|
|
48
46
|
flash: {}
|
|
49
47
|
});
|
|
50
|
-
|
|
51
48
|
_defineProperty(this, "setState", newState => {
|
|
52
|
-
this.state = {
|
|
49
|
+
this.state = {
|
|
50
|
+
...this.state,
|
|
53
51
|
...newState
|
|
54
52
|
};
|
|
55
53
|
this.triggerOnChange();
|
|
56
54
|
});
|
|
57
|
-
|
|
58
55
|
_defineProperty(this, "triggerOnChange", batch(() => this.callbacks.forEach(callback => callback(this.state))));
|
|
59
|
-
|
|
60
56
|
_defineProperty(this, "setReactions", (containerAri, ari, reactions) => {
|
|
61
57
|
this.setState({
|
|
62
|
-
reactions: {
|
|
58
|
+
reactions: {
|
|
59
|
+
...this.state.reactions,
|
|
63
60
|
[`${containerAri}|${ari}`]: reactions
|
|
64
61
|
}
|
|
65
62
|
});
|
|
66
63
|
});
|
|
67
|
-
|
|
68
64
|
_defineProperty(this, "handleDetailedReactionResponse", detailedReaction => {
|
|
69
65
|
const {
|
|
70
66
|
containerAri,
|
|
71
67
|
ari,
|
|
72
68
|
emojiId
|
|
73
69
|
} = detailedReaction;
|
|
74
|
-
this.withReaction(reaction => ({
|
|
70
|
+
this.withReaction(reaction => ({
|
|
71
|
+
...reaction,
|
|
75
72
|
users: detailedReaction.users
|
|
76
73
|
}))(containerAri, ari, emojiId);
|
|
77
74
|
});
|
|
78
|
-
|
|
79
75
|
_defineProperty(this, "flash", reaction => {
|
|
80
76
|
this.setFlash(reaction.containerAri, reaction.ari, reaction.emojiId, true);
|
|
81
77
|
window.setTimeout(() => this.setFlash(reaction.containerAri, reaction.ari, reaction.emojiId, false), 700);
|
|
82
78
|
});
|
|
83
|
-
|
|
84
79
|
_defineProperty(this, "optmisticUpdate", (containerAri, ari, emojiId) => updater => {
|
|
85
80
|
this.withReadyReaction(containerAri, ari)(reactionState => {
|
|
86
81
|
let found = false;
|
|
@@ -88,17 +83,15 @@ export class MemoryReactionsStore {
|
|
|
88
83
|
if (reaction.emojiId === emojiId) {
|
|
89
84
|
found = true;
|
|
90
85
|
const updated = updater(reaction);
|
|
91
|
-
|
|
92
86
|
if (updated) {
|
|
93
|
-
return {
|
|
87
|
+
return {
|
|
88
|
+
...updated,
|
|
94
89
|
optimisticallyUpdated: true
|
|
95
90
|
};
|
|
96
91
|
}
|
|
97
92
|
}
|
|
98
|
-
|
|
99
93
|
return reaction;
|
|
100
94
|
});
|
|
101
|
-
|
|
102
95
|
if (!found) {
|
|
103
96
|
const updated = updater({
|
|
104
97
|
containerAri,
|
|
@@ -107,18 +100,16 @@ export class MemoryReactionsStore {
|
|
|
107
100
|
count: 0,
|
|
108
101
|
reacted: false
|
|
109
102
|
});
|
|
110
|
-
|
|
111
103
|
if (updated) {
|
|
112
|
-
reactions.push({
|
|
104
|
+
reactions.push({
|
|
105
|
+
...updated,
|
|
113
106
|
optimisticallyUpdated: true
|
|
114
107
|
});
|
|
115
108
|
}
|
|
116
109
|
}
|
|
117
|
-
|
|
118
110
|
return utils.readyState(reactions);
|
|
119
111
|
});
|
|
120
112
|
});
|
|
121
|
-
|
|
122
113
|
_defineProperty(this, "doAddReaction", reaction => {
|
|
123
114
|
const {
|
|
124
115
|
containerAri,
|
|
@@ -127,8 +118,8 @@ export class MemoryReactionsStore {
|
|
|
127
118
|
} = reaction;
|
|
128
119
|
this.optmisticUpdate(containerAri, ari, emojiId)(utils.addOne);
|
|
129
120
|
this.flash(reaction);
|
|
130
|
-
const exp = ufoExperiences.add.getInstance(`${ari}|${emojiId}`);
|
|
131
|
-
|
|
121
|
+
const exp = ufoExperiences.add.getInstance(`${ari}|${emojiId}`);
|
|
122
|
+
// ufo start reaction experience
|
|
132
123
|
exp.start();
|
|
133
124
|
exp.addMetadata({
|
|
134
125
|
source: 'MemoryReactionsStore',
|
|
@@ -140,14 +131,13 @@ export class MemoryReactionsStore {
|
|
|
140
131
|
this.client.addReaction(containerAri, ari, emojiId, this.metadata).then(_ => {
|
|
141
132
|
if (this.createAnalyticsEvent) {
|
|
142
133
|
Analytics.createAndFireSafe(this.createAnalyticsEvent, Analytics.createRestSucceededEvent, 'addReaction');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
}
|
|
135
|
+
// ufo add reaction success
|
|
146
136
|
exp.success();
|
|
147
137
|
}).catch(error => {
|
|
148
138
|
if (isRealErrorFromService(error.code)) {
|
|
149
|
-
this.createAnalyticsEvent && Analytics.createAndFireSafe(this.createAnalyticsEvent, Analytics.createRestFailedEvent, 'addReaction', error.code);
|
|
150
|
-
|
|
139
|
+
this.createAnalyticsEvent && Analytics.createAndFireSafe(this.createAnalyticsEvent, Analytics.createRestFailedEvent, 'addReaction', error.code);
|
|
140
|
+
// ufo add reaction failure
|
|
151
141
|
exp.failure({
|
|
152
142
|
metadata: {
|
|
153
143
|
error: extractErrorInfo(error),
|
|
@@ -155,18 +145,18 @@ export class MemoryReactionsStore {
|
|
|
155
145
|
}
|
|
156
146
|
});
|
|
157
147
|
}
|
|
158
|
-
|
|
159
148
|
return Promise.reject(error);
|
|
160
149
|
});
|
|
161
150
|
});
|
|
162
|
-
|
|
163
151
|
_defineProperty(this, "doRemoveReaction", reaction => {
|
|
164
152
|
const {
|
|
165
153
|
containerAri,
|
|
166
154
|
ari,
|
|
167
155
|
emojiId
|
|
168
156
|
} = reaction;
|
|
169
|
-
const exp = ufoExperiences.remove.getInstance(`${ari}|${emojiId}`);
|
|
157
|
+
const exp = ufoExperiences.remove.getInstance(`${ari}|${emojiId}`);
|
|
158
|
+
|
|
159
|
+
// ufo start reaction experience
|
|
170
160
|
|
|
171
161
|
exp.start();
|
|
172
162
|
exp.addMetadata({
|
|
@@ -190,19 +180,17 @@ export class MemoryReactionsStore {
|
|
|
190
180
|
});
|
|
191
181
|
});
|
|
192
182
|
});
|
|
193
|
-
|
|
194
183
|
_defineProperty(this, "setCreateAnalyticsEvent", createAnalyticsEvent => {
|
|
195
184
|
this.createAnalyticsEvent = createAnalyticsEvent;
|
|
196
185
|
});
|
|
197
|
-
|
|
198
186
|
_defineProperty(this, "getReactions", batchByKey((containerAri, aris) => {
|
|
199
187
|
/**
|
|
200
188
|
* TODO:
|
|
201
189
|
* All reactions are usually fetched in a single call to reactions-service. Need to check why "getReactions" gets called randomly 1-2 times everytime on each fetch request despite using same containerAri.
|
|
202
190
|
*/
|
|
203
191
|
const sampledExp = ufoExperiences.render(containerAri);
|
|
204
|
-
const arisArr = aris.reduce(utils.flattenAris);
|
|
205
|
-
|
|
192
|
+
const arisArr = aris.reduce(utils.flattenAris);
|
|
193
|
+
// ufo start reaction experience
|
|
206
194
|
sampledExp.start({
|
|
207
195
|
samplingRate: SAMPLING_RATE_REACTIONS_RENDERED_EXP
|
|
208
196
|
});
|
|
@@ -222,14 +210,12 @@ export class MemoryReactionsStore {
|
|
|
222
210
|
if (this.createAnalyticsEvent) {
|
|
223
211
|
Analytics.createAndFireSafe(this.createAnalyticsEvent, Analytics.createRestSucceededEvent, 'getReactions');
|
|
224
212
|
}
|
|
225
|
-
|
|
226
213
|
sampledExp.success();
|
|
227
214
|
}).catch(error => {
|
|
228
215
|
if (isRealErrorFromService(error.code)) {
|
|
229
216
|
if (this.createAnalyticsEvent) {
|
|
230
217
|
Analytics.createAndFireSafe(this.createAnalyticsEvent, Analytics.createRestFailedEvent, 'getReactions');
|
|
231
218
|
}
|
|
232
|
-
|
|
233
219
|
sampledExp.failure({
|
|
234
220
|
metadata: {
|
|
235
221
|
error: extractErrorInfo(error),
|
|
@@ -237,26 +223,25 @@ export class MemoryReactionsStore {
|
|
|
237
223
|
}
|
|
238
224
|
});
|
|
239
225
|
}
|
|
240
|
-
|
|
241
|
-
|
|
226
|
+
const reactionsState = arisArr.reduce((acc, ari) => ({
|
|
227
|
+
...acc,
|
|
242
228
|
[`${containerAri}|${ari}`]: {
|
|
243
229
|
reactions: [],
|
|
244
230
|
status: Types.ReactionStatus.error
|
|
245
231
|
}
|
|
246
232
|
}), {});
|
|
247
|
-
this.setState({
|
|
248
|
-
|
|
233
|
+
this.setState({
|
|
234
|
+
...this.state,
|
|
235
|
+
reactions: {
|
|
236
|
+
...this.state.reactions,
|
|
249
237
|
...reactionsState
|
|
250
238
|
}
|
|
251
239
|
});
|
|
252
240
|
return Promise.reject(error);
|
|
253
241
|
});
|
|
254
242
|
}));
|
|
255
|
-
|
|
256
243
|
_defineProperty(this, "toggleReaction", this.withReaction(this.doRemoveReaction, this.doAddReaction));
|
|
257
|
-
|
|
258
244
|
_defineProperty(this, "addReaction", this.withReaction(this.flash, this.doAddReaction));
|
|
259
|
-
|
|
260
245
|
_defineProperty(this, "getDetailedReaction", (containerAri, ari, emojiId) => {
|
|
261
246
|
const exp = ufoExperiences.fetchDetails.getInstance(`${ari}|${emojiId}`);
|
|
262
247
|
exp.start();
|
|
@@ -281,41 +266,37 @@ export class MemoryReactionsStore {
|
|
|
281
266
|
});
|
|
282
267
|
});
|
|
283
268
|
});
|
|
284
|
-
|
|
285
269
|
_defineProperty(this, "getState", () => this.state);
|
|
286
|
-
|
|
287
270
|
_defineProperty(this, "onChange", callback => {
|
|
288
271
|
this.callbacks.push(callback);
|
|
289
272
|
});
|
|
290
|
-
|
|
291
273
|
_defineProperty(this, "removeOnChangeListener", toRemove => {
|
|
292
274
|
this.callbacks = this.callbacks.filter(callback => callback !== toRemove);
|
|
293
275
|
});
|
|
294
|
-
|
|
295
276
|
this.client = client;
|
|
296
277
|
this.state = state !== null && state !== void 0 ? state : this.initialState;
|
|
297
278
|
this.metadata = metadata;
|
|
298
279
|
}
|
|
280
|
+
|
|
299
281
|
/**
|
|
300
282
|
* Update the store state data with a new data
|
|
301
283
|
* @param newState new store data
|
|
302
284
|
*/
|
|
303
285
|
|
|
304
|
-
|
|
305
286
|
getReactionsState(containerAri, ari) {
|
|
306
287
|
return this.state.reactions[`${containerAri}|${ari}`];
|
|
307
288
|
}
|
|
308
|
-
|
|
309
289
|
setFlash(containerAri, ari, emojiId, flash) {
|
|
310
290
|
this.setState({
|
|
311
|
-
flash: {
|
|
312
|
-
|
|
291
|
+
flash: {
|
|
292
|
+
...this.state.flash,
|
|
293
|
+
[`${containerAri}|${ari}`]: {
|
|
294
|
+
...this.state.flash[`${containerAri}|${ari}`],
|
|
313
295
|
[emojiId]: flash
|
|
314
296
|
}
|
|
315
297
|
}
|
|
316
298
|
});
|
|
317
299
|
}
|
|
318
|
-
|
|
319
300
|
/**
|
|
320
301
|
* Utility function to help execute a callback to Reaction if its state is ready.
|
|
321
302
|
*
|
|
@@ -330,16 +311,15 @@ export class MemoryReactionsStore {
|
|
|
330
311
|
withReadyReaction(containerAri, ari) {
|
|
331
312
|
return updater => {
|
|
332
313
|
const reactionsState = this.getReactionsState(containerAri, ari);
|
|
333
|
-
|
|
334
314
|
if (reactionsState && reactionsState.status === Types.ReactionStatus.ready) {
|
|
335
315
|
const updated = updater(reactionsState);
|
|
336
|
-
|
|
337
316
|
if (updated) {
|
|
338
317
|
this.setReactions(containerAri, ari, updated);
|
|
339
318
|
}
|
|
340
319
|
}
|
|
341
320
|
};
|
|
342
321
|
}
|
|
322
|
+
|
|
343
323
|
/**
|
|
344
324
|
* Utility function to help execute actions with a reaction. It handles reaction discovery
|
|
345
325
|
* and branching between reacted and not reacted.
|
|
@@ -353,8 +333,6 @@ export class MemoryReactionsStore {
|
|
|
353
333
|
* A function that will execute the correct callback to the triple containerAri, ari and
|
|
354
334
|
* emojiId. If some state is returned, the new state will be applied.
|
|
355
335
|
*/
|
|
356
|
-
|
|
357
|
-
|
|
358
336
|
withReaction(reactedCallback, notReactedCallback) {
|
|
359
337
|
return (containerAri, ari, emojiId) => {
|
|
360
338
|
this.withReadyReaction(containerAri, ari)(reactionsState => {
|
|
@@ -367,14 +345,11 @@ export class MemoryReactionsStore {
|
|
|
367
345
|
};
|
|
368
346
|
const callback = reaction.reacted || !notReactedCallback ? reactedCallback : notReactedCallback;
|
|
369
347
|
const updatedReaction = callback(reaction);
|
|
370
|
-
|
|
371
348
|
if (updatedReaction && !(updatedReaction instanceof Function)) {
|
|
372
349
|
return utils.readyState(reactionsState.reactions.map(utils.updateByEmojiId(emojiId, updatedReaction)));
|
|
373
350
|
}
|
|
374
|
-
|
|
375
351
|
return;
|
|
376
352
|
});
|
|
377
353
|
};
|
|
378
354
|
}
|
|
379
|
-
|
|
380
355
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* A custom mapper class that takes the store instance and mapper functions "mapStateToProps" and "mapActionsToProps" to return the renderProps pattern as a child component
|
|
6
5
|
* @deprecated please avoid using this class as it will be removed in a future release
|
|
@@ -8,38 +7,31 @@ import React from 'react';
|
|
|
8
7
|
export class ReactionConsumer extends React.PureComponent {
|
|
9
8
|
constructor(props) {
|
|
10
9
|
super(props);
|
|
11
|
-
|
|
12
10
|
_defineProperty(this, "getPropsFromActions", actions => {
|
|
13
11
|
const {
|
|
14
12
|
mapActionsToProps
|
|
15
13
|
} = this.props;
|
|
16
|
-
|
|
17
14
|
if (mapActionsToProps) {
|
|
18
15
|
if (!this.previousActions || !this.propsFromActions || this.previousActions !== actions) {
|
|
19
16
|
this.propsFromActions = mapActionsToProps(actions);
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
this.previousActions = actions;
|
|
24
20
|
return this.propsFromActions;
|
|
25
21
|
});
|
|
26
|
-
|
|
27
22
|
_defineProperty(this, "getPropsFromState", state => {
|
|
28
23
|
const {
|
|
29
24
|
mapStateToProps
|
|
30
25
|
} = this.props;
|
|
31
26
|
return mapStateToProps ? mapStateToProps(state) : undefined;
|
|
32
27
|
});
|
|
33
|
-
|
|
34
28
|
_defineProperty(this, "handleOnChange", () => {
|
|
35
29
|
this.forceUpdate();
|
|
36
30
|
});
|
|
37
|
-
|
|
38
31
|
this.state = {
|
|
39
32
|
store: undefined
|
|
40
33
|
};
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
componentDidMount() {
|
|
44
36
|
Promise.resolve(this.props.store).then(store => {
|
|
45
37
|
this.setState({
|
|
@@ -48,23 +40,20 @@ export class ReactionConsumer extends React.PureComponent {
|
|
|
48
40
|
store.onChange(this.handleOnChange);
|
|
49
41
|
});
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
async componentWillUnmount() {
|
|
53
44
|
if (this.state.store) {
|
|
54
45
|
this.state.store.removeOnChangeListener(this.handleOnChange);
|
|
55
46
|
}
|
|
56
47
|
}
|
|
48
|
+
|
|
57
49
|
/**
|
|
58
50
|
* Get the actions the child component might need to dispatch from its props
|
|
59
51
|
*/
|
|
60
52
|
|
|
61
|
-
|
|
62
53
|
render() {
|
|
63
54
|
if (!this.state.store) {
|
|
64
55
|
return null;
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
return this.props.children(Object.assign({}, this.getPropsFromState(this.state.store.getState()), this.getPropsFromActions(this.state.store)));
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ReactionStatus } from '../types';
|
|
2
|
-
|
|
3
2
|
const compareEmojiId = (l, r) => {
|
|
4
3
|
return l.localeCompare(r);
|
|
5
4
|
};
|
|
6
|
-
|
|
7
5
|
const sortByRelevance = (a, b) => {
|
|
8
6
|
if (a.count > b.count) {
|
|
9
7
|
return -1;
|
|
@@ -13,30 +11,28 @@ const sortByRelevance = (a, b) => {
|
|
|
13
11
|
return compareEmojiId(a.emojiId, b.emojiId);
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
|
-
|
|
17
14
|
const sortByPreviousPosition = reactions => {
|
|
18
15
|
const indexes = reactions.reduce((map, reaction, index) => {
|
|
19
16
|
map[reaction.emojiId] = index;
|
|
20
17
|
return map;
|
|
21
18
|
}, {});
|
|
22
|
-
|
|
23
19
|
const getPosition = ({
|
|
24
20
|
emojiId
|
|
25
21
|
}) => indexes[emojiId] === undefined ? reactions.length : indexes[emojiId];
|
|
26
|
-
|
|
27
22
|
return (a, b) => getPosition(a) - getPosition(b);
|
|
28
23
|
};
|
|
29
|
-
|
|
30
24
|
export const readyState = reactions => ({
|
|
31
25
|
status: ReactionStatus.ready,
|
|
32
26
|
reactions: reactions.filter(reaction => reaction.count > 0)
|
|
33
27
|
});
|
|
34
28
|
export const byEmojiId = emojiId => reaction => reaction.emojiId === emojiId;
|
|
35
|
-
export const addOne = reaction => ({
|
|
29
|
+
export const addOne = reaction => ({
|
|
30
|
+
...reaction,
|
|
36
31
|
count: reaction.count + 1,
|
|
37
32
|
reacted: true
|
|
38
33
|
});
|
|
39
|
-
export const removeOne = reaction => ({
|
|
34
|
+
export const removeOne = reaction => ({
|
|
35
|
+
...reaction,
|
|
40
36
|
count: reaction.count - 1,
|
|
41
37
|
reacted: false
|
|
42
38
|
});
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
* Condition of the reaction when gets loaded from the store
|
|
39
39
|
*/
|
|
40
40
|
export let ReactionStatus;
|
|
41
|
+
|
|
41
42
|
/**
|
|
42
43
|
* state in which the reaction is at
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
45
|
(function (ReactionStatus) {
|
|
46
46
|
ReactionStatus["ready"] = "READY";
|
|
47
47
|
ReactionStatus["loading"] = "LOADING";
|
package/dist/es2019/version.json
CHANGED