소스 검색

fix(virtual-background) keep selected state on dialog

j8
Tudor D. Pop 4 년 전
부모
커밋
7ca04ccb0f
No account linked to committer's email address

+ 2
- 0
react/features/virtual-background/actionTypes.js 파일 보기

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

+ 2
- 1
react/features/virtual-background/actions.js 파일 보기

@@ -50,7 +50,8 @@ export function setVirtualBackground(options: Object) {
50 50
         type: SET_VIRTUAL_BACKGROUND,
51 51
         virtualSource: options?.url,
52 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 파일 보기

@@ -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));

+ 3
- 2
react/features/virtual-background/reducer.js 파일 보기

@@ -23,7 +23,7 @@ PersistenceRegistry.register(STORE_NAME, true);
23 23
  * specified action.
24 24
  */
25 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 28
     switch (action.type) {
29 29
     case SET_VIRTUAL_BACKGROUND: {
@@ -31,7 +31,8 @@ ReducerRegistry.register(STORE_NAME, (state = {}, action) => {
31 31
             ...state,
32 32
             virtualSource,
33 33
             blurValue,
34
-            backgroundType
34
+            backgroundType,
35
+            selectedThumbnail
35 36
         };
36 37
     }
37 38
     case BACKGROUND_ENABLED: {

Loading…
취소
저장