You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VirtualBackgroundDialog.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @flow
  2. /* eslint-disable react/jsx-no-bind, no-return-assign */
  3. import React, { useState } from 'react';
  4. import { Dialog } from '../../base/dialog';
  5. import { translate } from '../../base/i18n';
  6. import { Icon, IconBlurBackground } from '../../base/icons';
  7. import { connect } from '../../base/redux';
  8. import { Tooltip } from '../../base/tooltip';
  9. import { toggleBackgroundEffect, setVirtualBackground } from '../actions';
  10. const images = [
  11. {
  12. tooltip: 'Image 1',
  13. name: 'background-1.jpg',
  14. id: 1,
  15. src: 'images/virtual-background/background-1.jpg'
  16. },
  17. {
  18. tooltip: 'Image 2',
  19. name: 'background-2.jpg',
  20. id: 2,
  21. src: 'images/virtual-background/background-2.jpg'
  22. },
  23. {
  24. tooltip: 'Image 3',
  25. name: 'background-3.jpg',
  26. id: 3,
  27. src: 'images/virtual-background/background-3.jpg'
  28. },
  29. {
  30. tooltip: 'Image 4',
  31. name: 'background-4.jpg',
  32. id: 4,
  33. src: 'images/virtual-background/background-4.jpg'
  34. }
  35. ];
  36. type Props = {
  37. /**
  38. * The redux {@code dispatch} function.
  39. */
  40. dispatch: Function,
  41. /**
  42. * Invoked to obtain translated strings.
  43. */
  44. t: Function
  45. };
  46. /**
  47. * Renders virtual background dialog.
  48. *
  49. * @returns {ReactElement}
  50. */
  51. function VirtualBackground({ dispatch, t }: Props) {
  52. const [ selected, setSelected ] = useState('');
  53. const enableBlur = () => {
  54. setSelected('blur');
  55. dispatch(setVirtualBackground('', false));
  56. dispatch(toggleBackgroundEffect(true));
  57. };
  58. const removeBackground = () => {
  59. setSelected('none');
  60. dispatch(setVirtualBackground('', false));
  61. dispatch(toggleBackgroundEffect(false));
  62. };
  63. const addImageBackground = image => {
  64. setSelected(image.id);
  65. dispatch(setVirtualBackground(image.src, true));
  66. dispatch(toggleBackgroundEffect(true));
  67. };
  68. return (
  69. <Dialog
  70. hideCancelButton = { true }
  71. submitDisabled = { false }
  72. titleKey = { 'virtualBackground.title' }
  73. width = 'small'>
  74. <div className = 'virtual-background-dialog'>
  75. <Tooltip
  76. content = { t('virtualBackground.removeBackground') }
  77. position = { 'top' }>
  78. <div
  79. className = { selected === 'none' ? 'none-selected' : 'virtual-background-none' }
  80. onClick = { () => removeBackground() }>
  81. None
  82. </div>
  83. </Tooltip>
  84. <Tooltip
  85. content = { t('virtualBackground.enableBlur') }
  86. position = { 'top' }>
  87. <Icon
  88. className = { selected === 'blur' ? 'blur-selected' : '' }
  89. onClick = { () => enableBlur() }
  90. size = { 50 }
  91. src = { IconBlurBackground } />
  92. </Tooltip>
  93. {images.map((image, index) => (
  94. <Tooltip
  95. content = { image.tooltip }
  96. key = { index }
  97. position = { 'top' }>
  98. <img
  99. className = { selected === image.id ? 'thumbnail-selected' : 'thumbnail' }
  100. onClick = { () => addImageBackground(image) }
  101. onError = { event => event.target.style.display = 'none' }
  102. src = { image.src } />
  103. </Tooltip>
  104. ))}
  105. </div>
  106. </Dialog>
  107. );
  108. }
  109. export default translate(connect()(VirtualBackground));