diff --git a/react/features/virtual-background/actionTypes.js b/react/features/virtual-background/actionTypes.js index 671d31100..1b0ff1d1f 100644 --- a/react/features/virtual-background/actionTypes.js +++ b/react/features/virtual-background/actionTypes.js @@ -18,6 +18,8 @@ export const BACKGROUND_ENABLED = 'BACKGROUND_ENABLED'; * type: SET_VIRTUAL_BACKGROUND, * virtualSource: string, * blurValue: number, + * backgroundType: string, + * selectedThumbnail: string * }} */ export const SET_VIRTUAL_BACKGROUND = 'SET_VIRTUAL_BACKGROUND'; diff --git a/react/features/virtual-background/actions.js b/react/features/virtual-background/actions.js index 7f127bcd3..0b6ff866c 100644 --- a/react/features/virtual-background/actions.js +++ b/react/features/virtual-background/actions.js @@ -50,7 +50,8 @@ export function setVirtualBackground(options: Object) { type: SET_VIRTUAL_BACKGROUND, virtualSource: options?.url, blurValue: options?.blurValue, - backgroundType: options?.backgroundType + backgroundType: options?.backgroundType, + selectedThumbnail: options?.selectedThumbnail }; } diff --git a/react/features/virtual-background/components/VirtualBackgroundDialog.js b/react/features/virtual-background/components/VirtualBackgroundDialog.js index d8234c3cc..b27f07d4c 100644 --- a/react/features/virtual-background/components/VirtualBackgroundDialog.js +++ b/react/features/virtual-background/components/VirtualBackgroundDialog.js @@ -20,24 +20,29 @@ import logger from '../logger'; const backgroundsLimit = 25; const images = [ { - id: 1, + id: '1', src: 'images/virtual-background/background-1.jpg' }, { - id: 2, + id: '2', src: 'images/virtual-background/background-2.jpg' }, { - id: 3, + id: '3', src: 'images/virtual-background/background-3.jpg' }, { - id: 4, + id: '4', src: 'images/virtual-background/background-4.jpg' } ]; type Props = { + /** + * Returns the selected thumbnail identifier. + */ + _selectedThumbnail: string, + /** * The redux {@code dispatch} function. */ @@ -54,7 +59,7 @@ type Props = { * * @returns {ReactElement} */ -function VirtualBackground({ dispatch, t }: Props) { +function VirtualBackground({ _selectedThumbnail, dispatch, t }: Props) { const localImages = jitsiLocalStorage.getItem('virtualBackgrounds'); const [ storedImages, setStoredImages ] = useState((localImages && JSON.parse(localImages)) || []); const [ loading, isloading ] = useState(false); @@ -78,15 +83,14 @@ function VirtualBackground({ dispatch, t }: Props) { } }, [ storedImages ]); - const [ selected, setSelected ] = useState(''); const enableBlur = async (blurValue, selection) => { isloading(true); - setSelected(selection); await dispatch( toggleBackgroundEffect({ backgroundType: 'blur', enabled: true, - blurValue + blurValue, + selectedThumbnail: selection }) ); isloading(false); @@ -94,10 +98,10 @@ function VirtualBackground({ dispatch, t }: Props) { const removeBackground = async () => { isloading(true); - setSelected('none'); await dispatch( toggleBackgroundEffect({ - enabled: false + enabled: false, + selectedThumbnail: 'none' }) ); isloading(false); @@ -105,12 +109,12 @@ function VirtualBackground({ dispatch, t }: Props) { const setUploadedImageBackground = async image => { isloading(true); - setSelected(image.id); await dispatch( toggleBackgroundEffect({ backgroundType: 'image', enabled: true, - url: image.src + url: image.src, + selectedThumbnail: image.id }) ); isloading(false); @@ -118,14 +122,14 @@ function VirtualBackground({ dispatch, t }: Props) { const setImageBackground = async image => { isloading(true); - setSelected(image.id); const url = await toDataURL(image.src); await dispatch( toggleBackgroundEffect({ backgroundType: 'image', enabled: true, - url + url, + selectedThumbnail: image.id }) ); isloading(false); @@ -137,12 +141,13 @@ function VirtualBackground({ dispatch, t }: Props) { reader.readAsDataURL(imageFile[0]); reader.onload = async () => { const url = await resizeImage(reader.result); + const uuId = uuid.v4(); isloading(true); setStoredImages([ ...storedImages, { - id: uuid.v4(), + id: uuId, src: url } ]); @@ -150,7 +155,8 @@ function VirtualBackground({ dispatch, t }: Props) { toggleBackgroundEffect({ backgroundType: 'image', enabled: true, - url + url, + selectedThumbnail: uuId }) ); isloading(false); @@ -181,7 +187,8 @@ function VirtualBackground({ dispatch, t }: Props) { content = { t('virtualBackground.removeBackground') } position = { 'top' }>