From 77c8425c3ce0ab642826c3d0baa996c14ec6260f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 16 Jul 2021 20:50:29 +0200 Subject: [PATCH] Rewrite using TabbedView and improve TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../elements/DesktopCapturerSourcePicker.tsx | 78 +++++++------------ 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/src/components/views/elements/DesktopCapturerSourcePicker.tsx b/src/components/views/elements/DesktopCapturerSourcePicker.tsx index 8b7eaca7ea..49a2bda1f7 100644 --- a/src/components/views/elements/DesktopCapturerSourcePicker.tsx +++ b/src/components/views/elements/DesktopCapturerSourcePicker.tsx @@ -22,6 +22,7 @@ import classNames from 'classnames'; import AccessibleButton from './AccessibleButton'; import { getDesktopCapturerSources } from "matrix-js-sdk/src/webrtc/call"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import TabbedView, { Tab, TabLocation } from '../../structures/TabbedView'; export interface DesktopCapturerSource { id: string; @@ -41,11 +42,11 @@ export interface ExistingSourceIProps { } export class ExistingSource extends React.Component { - constructor(props) { + constructor(props: ExistingSourceIProps) { super(props); } - onClick = (ev) => { + private onClick = (): void => { this.props.onSelect(this.props.source); }; @@ -59,7 +60,8 @@ export class ExistingSource extends React.Component { + onClick={this.onClick} + > { - interval; +> { + interval: number; - constructor(props) { + constructor(props: PickerIProps) { super(props); this.state = { @@ -116,39 +118,24 @@ export default class DesktopCapturerSourcePicker extends React.Component< clearInterval(this.interval); } - onSelect = (source) => { + private onSelect = (source: DesktopCapturerSource): void => { this.setState({ selectedSource: source }); }; - onShare = () => { + private onShare = (): void => { this.props.onFinished(this.state.selectedSource); }; - onScreensClick = () => { - if (this.state.selectedTab === Tabs.Screens) return; - this.setState({ - selectedTab: Tabs.Screens, - selectedSource: null, - }); + private onTabChange = (): void => { + this.setState({ selectedSource: null }); }; - onWindowsClick = () => { - if (this.state.selectedTab === Tabs.Windows) return; - this.setState({ - selectedTab: Tabs.Windows, - selectedSource: null, - }); - }; - - onCloseClick = () => { + private onCloseClick = (): void => { this.props.onFinished(null); }; - render() { - const sources = this.state.sources.filter((source) => { - return source.id.startsWith(this.state.selectedTab); - }); - const sourceElements = sources.map((source) => { + private getTab(type: "screen" | "window", label: string): Tab { + const sources = this.state.sources.filter((source) => source.id.startsWith(type)).map((source) => { return ( + { sources } + + )); + } + + render() { + const tabs = [ + this.getTab("screen", _t("Share entire screen")), + this.getTab("window", _t("Application window")), + ]; return ( -
- - {_t("Screens")} - - - {_t("Windows")} - -
-
- { sourceElements } -
+