Selaa lähdekoodia

fix(virtual-background) keep selected state on dialog

master
Tudor D. Pop 4 vuotta sitten
vanhempi
commit
7ca04ccb0f
No account linked to committer's email address

+ 2
- 0
react/features/virtual-background/actionTypes.js Näytä tiedosto

18
  *     type: SET_VIRTUAL_BACKGROUND,
18
  *     type: SET_VIRTUAL_BACKGROUND,
19
  *     virtualSource: string,
19
  *     virtualSource: string,
20
  *     blurValue: number,
20
  *     blurValue: number,
21
+ *     backgroundType: string,
22
+ *     selectedThumbnail: string
21
  * }}
23
  * }}
22
  */
24
  */
23
 export const SET_VIRTUAL_BACKGROUND = 'SET_VIRTUAL_BACKGROUND';
25
 export const SET_VIRTUAL_BACKGROUND = 'SET_VIRTUAL_BACKGROUND';

+ 2
- 1
react/features/virtual-background/actions.js Näytä tiedosto

50
         type: SET_VIRTUAL_BACKGROUND,
50
         type: SET_VIRTUAL_BACKGROUND,
51
         virtualSource: options?.url,
51
         virtualSource: options?.url,
52
         blurValue: options?.blurValue,
52
         blurValue: options?.blurValue,
53
-        backgroundType: options?.backgroundType
53
+        backgroundType: options?.backgroundType,
54
+        selectedThumbnail: options?.selectedThumbnail
54
     };
55
     };
55
 }
56
 }
56
 
57
 

+ 45
- 22
react/features/virtual-background/components/VirtualBackgroundDialog.js Näytä tiedosto

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

+ 3
- 2
react/features/virtual-background/reducer.js Näytä tiedosto

23
  * specified action.
23
  * specified action.
24
  */
24
  */
25
 ReducerRegistry.register(STORE_NAME, (state = {}, action) => {
25
 ReducerRegistry.register(STORE_NAME, (state = {}, action) => {
26
-    const { virtualSource, backgroundEffectEnabled, blurValue, backgroundType } = action;
26
+    const { virtualSource, backgroundEffectEnabled, blurValue, backgroundType, selectedThumbnail } = action;
27
 
27
 
28
     switch (action.type) {
28
     switch (action.type) {
29
     case SET_VIRTUAL_BACKGROUND: {
29
     case SET_VIRTUAL_BACKGROUND: {
31
             ...state,
31
             ...state,
32
             virtualSource,
32
             virtualSource,
33
             blurValue,
33
             blurValue,
34
-            backgroundType
34
+            backgroundType,
35
+            selectedThumbnail
35
         };
36
         };
36
     }
37
     }
37
     case BACKGROUND_ENABLED: {
38
     case BACKGROUND_ENABLED: {

Loading…
Peruuta
Tallenna