-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathFeedbackWidgetManager.tsx
More file actions
174 lines (149 loc) · 4.54 KB
/
FeedbackWidgetManager.tsx
File metadata and controls
174 lines (149 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { debug } from '@sentry/core';
import { isWeb } from '../utils/environment';
import {
lazyLoadAutoInjectFeedbackButtonIntegration,
lazyLoadAutoInjectFeedbackIntegration,
lazyLoadAutoInjectScreenshotButtonIntegration,
lazyLoadShakeToReportIntegration,
} from './lazy';
import { startShakeListener, stopShakeListener } from './ShakeToReportBug';
export const PULL_DOWN_CLOSE_THRESHOLD = 200;
export const SLIDE_ANIMATION_DURATION = 200;
export const BACKGROUND_ANIMATION_DURATION = 200;
const NOOP_SET_VISIBILITY = (): void => {
// No-op
};
abstract class FeedbackManager {
protected static _isVisible = false;
protected static _setVisibility: (visible: boolean) => void;
protected static get _feedbackComponentName(): string {
throw new Error('Subclasses must override feedbackComponentName');
}
public static initialize(setVisibility: (visible: boolean) => void): void {
this._setVisibility = setVisibility;
}
/**
* For testing purposes only.
*/
public static reset(): void {
this._isVisible = false;
this._setVisibility = NOOP_SET_VISIBILITY;
}
public static show(): void {
if (this._setVisibility !== NOOP_SET_VISIBILITY) {
this._isVisible = true;
this._setVisibility(true);
} else {
// This message should be always shown otherwise it's not possible to use the widget.
// oxlint-disable-next-line eslint(no-console)
console.warn(
`[Sentry] ${this._feedbackComponentName} requires 'Sentry.wrap(RootComponent)' to be called before 'show${this._feedbackComponentName}()'.`,
);
}
}
public static hide(): void {
if (this._setVisibility !== NOOP_SET_VISIBILITY) {
this._isVisible = false;
this._setVisibility(false);
} else {
// This message should be always shown otherwise it's not possible to use the widget.
// oxlint-disable-next-line eslint(no-console)
console.warn(
`[Sentry] ${this._feedbackComponentName} requires 'Sentry.wrap(RootComponent)' before interacting with the widget.`,
);
}
}
public static isFormVisible(): boolean {
return this._isVisible;
}
}
/**
* Provides functionality to show and hide the feedback widget.
*/
export class FeedbackWidgetManager extends FeedbackManager {
/**
* Returns the name of the feedback component.
*/
protected static get _feedbackComponentName(): string {
return 'FeedbackWidget';
}
}
/**
* Provides functionality to show and hide the feedback button.
*/
export class FeedbackButtonManager extends FeedbackManager {
/**
* Returns the name of the feedback component.
*/
protected static get _feedbackComponentName(): string {
return 'FeedbackButton';
}
}
/**
* Provides functionality to show and hide the screenshot button.
*/
export class ScreenshotButtonManager extends FeedbackManager {
/**
* Returns the name of the feedback component.
*/
protected static get _feedbackComponentName(): string {
return 'ScreenshotButton';
}
}
const showFeedbackWidget = (): void => {
lazyLoadAutoInjectFeedbackIntegration();
FeedbackWidgetManager.show();
};
const resetFeedbackWidgetManager = (): void => {
FeedbackWidgetManager.reset();
};
const showFeedbackButton = (): void => {
lazyLoadAutoInjectFeedbackButtonIntegration();
FeedbackButtonManager.show();
};
const hideFeedbackButton = (): void => {
FeedbackButtonManager.hide();
};
const resetFeedbackButtonManager = (): void => {
FeedbackButtonManager.reset();
};
const showScreenshotButton = (): void => {
if (isWeb()) {
debug.warn('ScreenshotButton is not supported on Web.');
return;
}
lazyLoadAutoInjectScreenshotButtonIntegration();
ScreenshotButtonManager.show();
};
const hideScreenshotButton = (): void => {
ScreenshotButtonManager.hide();
};
const resetScreenshotButtonManager = (): void => {
ScreenshotButtonManager.reset();
};
let _imperativeShakeListenerStarted = false;
const enableFeedbackOnShake = (): void => {
lazyLoadAutoInjectFeedbackIntegration();
lazyLoadShakeToReportIntegration();
if (!_imperativeShakeListenerStarted) {
_imperativeShakeListenerStarted = startShakeListener(showFeedbackWidget);
}
};
const disableFeedbackOnShake = (): void => {
if (_imperativeShakeListenerStarted) {
stopShakeListener();
_imperativeShakeListenerStarted = false;
}
};
export {
showFeedbackButton,
hideFeedbackButton,
showFeedbackWidget,
enableFeedbackOnShake,
disableFeedbackOnShake,
showScreenshotButton,
hideScreenshotButton,
resetFeedbackButtonManager,
resetFeedbackWidgetManager,
resetScreenshotButtonManager,
};