|
@@ -20,24 +20,29 @@ import logger from '../logger';
|
20
|
20
|
const backgroundsLimit = 25;
|
21
|
21
|
const images = [
|
22
|
22
|
{
|
23
|
|
- id: 1,
|
|
23
|
+ id: '1',
|
24
|
24
|
src: 'images/virtual-background/background-1.jpg'
|
25
|
25
|
},
|
26
|
26
|
{
|
27
|
|
- id: 2,
|
|
27
|
+ id: '2',
|
28
|
28
|
src: 'images/virtual-background/background-2.jpg'
|
29
|
29
|
},
|
30
|
30
|
{
|
31
|
|
- id: 3,
|
|
31
|
+ id: '3',
|
32
|
32
|
src: 'images/virtual-background/background-3.jpg'
|
33
|
33
|
},
|
34
|
34
|
{
|
35
|
|
- id: 4,
|
|
35
|
+ id: '4',
|
36
|
36
|
src: 'images/virtual-background/background-4.jpg'
|
37
|
37
|
}
|
38
|
38
|
];
|
39
|
39
|
type Props = {
|
40
|
40
|
|
|
41
|
+ /**
|
|
42
|
+ * Returns the selected thumbnail identifier.
|
|
43
|
+ */
|
|
44
|
+ _selectedThumbnail: string,
|
|
45
|
+
|
41
|
46
|
/**
|
42
|
47
|
* The redux {@code dispatch} function.
|
43
|
48
|
*/
|
|
@@ -54,7 +59,7 @@ type Props = {
|
54
|
59
|
*
|
55
|
60
|
* @returns {ReactElement}
|
56
|
61
|
*/
|
57
|
|
-function VirtualBackground({ dispatch, t }: Props) {
|
|
62
|
+function VirtualBackground({ _selectedThumbnail, dispatch, t }: Props) {
|
58
|
63
|
const localImages = jitsiLocalStorage.getItem('virtualBackgrounds');
|
59
|
64
|
const [ storedImages, setStoredImages ] = useState((localImages && JSON.parse(localImages)) || []);
|
60
|
65
|
const [ loading, isloading ] = useState(false);
|
|
@@ -78,15 +83,14 @@ function VirtualBackground({ dispatch, t }: Props) {
|
78
|
83
|
}
|
79
|
84
|
}, [ storedImages ]);
|
80
|
85
|
|
81
|
|
- const [ selected, setSelected ] = useState('');
|
82
|
86
|
const enableBlur = async (blurValue, selection) => {
|
83
|
87
|
isloading(true);
|
84
|
|
- setSelected(selection);
|
85
|
88
|
await dispatch(
|
86
|
89
|
toggleBackgroundEffect({
|
87
|
90
|
backgroundType: 'blur',
|
88
|
91
|
enabled: true,
|
89
|
|
- blurValue
|
|
92
|
+ blurValue,
|
|
93
|
+ selectedThumbnail: selection
|
90
|
94
|
})
|
91
|
95
|
);
|
92
|
96
|
isloading(false);
|
|
@@ -94,10 +98,10 @@ function VirtualBackground({ dispatch, t }: Props) {
|
94
|
98
|
|
95
|
99
|
const removeBackground = async () => {
|
96
|
100
|
isloading(true);
|
97
|
|
- setSelected('none');
|
98
|
101
|
await dispatch(
|
99
|
102
|
toggleBackgroundEffect({
|
100
|
|
- enabled: false
|
|
103
|
+ enabled: false,
|
|
104
|
+ selectedThumbnail: 'none'
|
101
|
105
|
})
|
102
|
106
|
);
|
103
|
107
|
isloading(false);
|
|
@@ -105,12 +109,12 @@ function VirtualBackground({ dispatch, t }: Props) {
|
105
|
109
|
|
106
|
110
|
const setUploadedImageBackground = async image => {
|
107
|
111
|
isloading(true);
|
108
|
|
- setSelected(image.id);
|
109
|
112
|
await dispatch(
|
110
|
113
|
toggleBackgroundEffect({
|
111
|
114
|
backgroundType: 'image',
|
112
|
115
|
enabled: true,
|
113
|
|
- url: image.src
|
|
116
|
+ url: image.src,
|
|
117
|
+ selectedThumbnail: image.id
|
114
|
118
|
})
|
115
|
119
|
);
|
116
|
120
|
isloading(false);
|
|
@@ -118,14 +122,14 @@ function VirtualBackground({ dispatch, t }: Props) {
|
118
|
122
|
|
119
|
123
|
const setImageBackground = async image => {
|
120
|
124
|
isloading(true);
|
121
|
|
- setSelected(image.id);
|
122
|
125
|
const url = await toDataURL(image.src);
|
123
|
126
|
|
124
|
127
|
await dispatch(
|
125
|
128
|
toggleBackgroundEffect({
|
126
|
129
|
backgroundType: 'image',
|
127
|
130
|
enabled: true,
|
128
|
|
- url
|
|
131
|
+ url,
|
|
132
|
+ selectedThumbnail: image.id
|
129
|
133
|
})
|
130
|
134
|
);
|
131
|
135
|
isloading(false);
|
|
@@ -137,12 +141,13 @@ function VirtualBackground({ dispatch, t }: Props) {
|
137
|
141
|
reader.readAsDataURL(imageFile[0]);
|
138
|
142
|
reader.onload = async () => {
|
139
|
143
|
const url = await resizeImage(reader.result);
|
|
144
|
+ const uuId = uuid.v4();
|
140
|
145
|
|
141
|
146
|
isloading(true);
|
142
|
147
|
setStoredImages([
|
143
|
148
|
...storedImages,
|
144
|
149
|
{
|
145
|
|
- id: uuid.v4(),
|
|
150
|
+ id: uuId,
|
146
|
151
|
src: url
|
147
|
152
|
}
|
148
|
153
|
]);
|
|
@@ -150,7 +155,8 @@ function VirtualBackground({ dispatch, t }: Props) {
|
150
|
155
|
toggleBackgroundEffect({
|
151
|
156
|
backgroundType: 'image',
|
152
|
157
|
enabled: true,
|
153
|
|
- url
|
|
158
|
+ url,
|
|
159
|
+ selectedThumbnail: uuId
|
154
|
160
|
})
|
155
|
161
|
);
|
156
|
162
|
isloading(false);
|
|
@@ -181,7 +187,8 @@ function VirtualBackground({ dispatch, t }: Props) {
|
181
|
187
|
content = { t('virtualBackground.removeBackground') }
|
182
|
188
|
position = { 'top' }>
|
183
|
189
|
<div
|
184
|
|
- className = { selected === 'none' ? 'none-selected' : 'virtual-background-none' }
|
|
190
|
+ className = { _selectedThumbnail === 'none'
|
|
191
|
+ ? 'none-selected' : 'virtual-background-none' }
|
185
|
192
|
onClick = { removeBackground }>
|
186
|
193
|
{t('virtualBackground.none')}
|
187
|
194
|
</div>
|
|
@@ -190,7 +197,7 @@ function VirtualBackground({ dispatch, t }: Props) {
|
190
|
197
|
content = { t('virtualBackground.slightBlur') }
|
191
|
198
|
position = { 'top' }>
|
192
|
199
|
<Icon
|
193
|
|
- className = { selected === 'slight-blur' ? 'blur-selected' : '' }
|
|
200
|
+ className = { _selectedThumbnail === 'slight-blur' ? 'blur-selected' : '' }
|
194
|
201
|
onClick = { () => enableBlur(8, 'slight-blur') }
|
195
|
202
|
size = { 50 }
|
196
|
203
|
src = { IconBlurBackground } />
|
|
@@ -199,14 +206,14 @@ function VirtualBackground({ dispatch, t }: Props) {
|
199
|
206
|
content = { t('virtualBackground.blur') }
|
200
|
207
|
position = { 'top' }>
|
201
|
208
|
<Icon
|
202
|
|
- className = { selected === 'blur' ? 'blur-selected' : '' }
|
|
209
|
+ className = { _selectedThumbnail === 'blur' ? 'blur-selected' : '' }
|
203
|
210
|
onClick = { () => enableBlur(25, 'blur') }
|
204
|
211
|
size = { 50 }
|
205
|
212
|
src = { IconBlurBackground } />
|
206
|
213
|
</Tooltip>
|
207
|
214
|
{images.map((image, index) => (
|
208
|
215
|
<img
|
209
|
|
- className = { selected === image.id ? 'thumbnail-selected' : 'thumbnail' }
|
|
216
|
+ className = { _selectedThumbnail === image.id ? 'thumbnail-selected' : 'thumbnail' }
|
210
|
217
|
key = { index }
|
211
|
218
|
onClick = { () => setImageBackground(image) }
|
212
|
219
|
onError = { event => event.target.style.display = 'none' }
|
|
@@ -235,7 +242,7 @@ function VirtualBackground({ dispatch, t }: Props) {
|
235
|
242
|
className = { 'thumbnail-container' }
|
236
|
243
|
key = { index }>
|
237
|
244
|
<img
|
238
|
|
- className = { selected === image.id ? 'thumbnail-selected' : 'thumbnail' }
|
|
245
|
+ className = { _selectedThumbnail === image.id ? 'thumbnail-selected' : 'thumbnail' }
|
239
|
246
|
onClick = { () => setUploadedImageBackground(image) }
|
240
|
247
|
onError = { event => event.target.style.display = 'none' }
|
241
|
248
|
src = { image.src } />
|
|
@@ -253,4 +260,20 @@ function VirtualBackground({ dispatch, t }: Props) {
|
253
|
260
|
);
|
254
|
261
|
}
|
255
|
262
|
|
256
|
|
-export default translate(connect()(VirtualBackground));
|
|
263
|
+/**
|
|
264
|
+ * Maps (parts of) the redux state to the associated props for the
|
|
265
|
+ * {@code VirtualBackground} component.
|
|
266
|
+ *
|
|
267
|
+ * @param {Object} state - The Redux state.
|
|
268
|
+ * @private
|
|
269
|
+ * @returns {{
|
|
270
|
+ * _selectedThumbnail: string
|
|
271
|
+ * }}
|
|
272
|
+ */
|
|
273
|
+function _mapStateToProps(state): Object {
|
|
274
|
+ return {
|
|
275
|
+ _selectedThumbnail: state['features/virtual-background'].selectedThumbnail
|
|
276
|
+ };
|
|
277
|
+}
|
|
278
|
+
|
|
279
|
+export default translate(connect(_mapStateToProps)(VirtualBackground));
|