From c5ee2a6b32d5cd25084636394fb6d6af09ee6a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 12 Jun 2021 13:43:42 +0200 Subject: [PATCH] Add share button and refoctor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../_DesktopCapturerSourcePicker.scss | 1 + .../elements/DesktopCapturerSourcePicker.tsx | 84 ++++++++++++------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/res/css/views/elements/_DesktopCapturerSourcePicker.scss b/res/css/views/elements/_DesktopCapturerSourcePicker.scss index 69dde5925e..489a9f3a79 100644 --- a/res/css/views/elements/_DesktopCapturerSourcePicker.scss +++ b/res/css/views/elements/_DesktopCapturerSourcePicker.scss @@ -53,6 +53,7 @@ limitations under the License. border-radius: 4px; } +.mx_desktopCapturerSourcePicker_stream_button_selected, .mx_desktopCapturerSourcePicker_stream_button:hover, .mx_desktopCapturerSourcePicker_stream_button:focus { background: $roomtile-selected-bg-color; diff --git a/src/components/views/elements/DesktopCapturerSourcePicker.tsx b/src/components/views/elements/DesktopCapturerSourcePicker.tsx index d7da5d7f1a..cbe7cd25b0 100644 --- a/src/components/views/elements/DesktopCapturerSourcePicker.tsx +++ b/src/components/views/elements/DesktopCapturerSourcePicker.tsx @@ -17,9 +17,11 @@ limitations under the License. import React from 'react'; import { _t } from '../../../languageHandler'; import BaseDialog from "..//dialogs/BaseDialog" +import DialogButtons from "./DialogButtons" import AccessibleButton from './AccessibleButton'; -import {getDesktopCapturerSources} from "matrix-js-sdk/src/webrtc/call"; -import {replaceableComponent} from "../../../utils/replaceableComponent"; +import { getDesktopCapturerSources } from "matrix-js-sdk/src/webrtc/call"; +import { replaceableComponent } from "../../../utils/replaceableComponent"; +import classNames from 'classnames'; export interface DesktopCapturerSource { id: string; @@ -28,13 +30,14 @@ export interface DesktopCapturerSource { } export enum Tabs { - Screens = "screens", - Windows = "windows", + Screens = "screen", + Windows = "window", } export interface ExistingSourceIProps { source: DesktopCapturerSource; onSelect(source: DesktopCapturerSource): void; + selected: boolean; } export class ExistingSource extends React.Component { @@ -47,9 +50,14 @@ export class ExistingSource extends React.Component { } render() { + const classes = classNames({ + mx_desktopCapturerSourcePicker_stream_button: true, + mx_desktopCapturerSourcePicker_stream_button_selected: this.props.selected, + }); + return ( { export interface PickerIState { selectedTab: Tabs; sources: Array; + selectedSource: DesktopCapturerSource | null; } export interface PickerIProps { onFinished(source: DesktopCapturerSource): void; @@ -83,6 +92,7 @@ export default class DesktopCapturerSourcePicker extends React.Component< this.state = { selectedTab: Tabs.Screens, sources: [], + selectedSource: null, }; } @@ -107,40 +117,47 @@ export default class DesktopCapturerSourcePicker extends React.Component< } onSelect = (source) => { - this.props.onFinished(source); + this.setState({ selectedSource: source }); } - onScreensClick = (ev) => { - this.setState({selectedTab: Tabs.Screens}); + onShare = () => { + this.props.onFinished(this.state.selectedSource); } - onWindowsClick = (ev) => { - this.setState({selectedTab: Tabs.Windows}); + onScreensClick = () => { + if (this.state.selectedTab === Tabs.Screens) return; + this.setState({ + selectedTab: Tabs.Screens, + selectedSource: null, + }); } - onCloseClick = (ev) => { + onWindowsClick = () => { + if (this.state.selectedTab === Tabs.Windows) return; + this.setState({ + selectedTab: Tabs.Windows, + selectedSource: null, + }); + } + + onCloseClick = () => { this.props.onFinished(null); } render() { - let sources; - if (this.state.selectedTab === Tabs.Screens) { - sources = this.state.sources - .filter((source) => { - return source.id.startsWith("screen"); - }) - .map((source) => { - return ; - }); - } else { - sources = this.state.sources - .filter((source) => { - return source.id.startsWith("window"); - }) - .map((source) => { - return ; - }); - } + const sources = this.state.sources.filter((source) => { + return source.id.startsWith(this.state.selectedTab) + }); + const sourceElements = sources.map((source) => { + return ( + + ); + }); const buttonStyle = "mx_desktopCapturerSourcePicker_tabLabel"; const screensButtonStyle = buttonStyle + ((this.state.selectedTab === Tabs.Screens) ? "_selected" : ""); @@ -167,8 +184,15 @@ export default class DesktopCapturerSourcePicker extends React.Component<
- { sources } + { sourceElements }
+ ); }