From 3727bfb67fedaac27fea60dcbac28ae638480f8b Mon Sep 17 00:00:00 2001 From: Timo K Date: Thu, 28 Jul 2022 00:17:09 +0200 Subject: [PATCH] more types --- src/form/Form.tsx | 27 ++++++++++++++++++--------- src/home/CallList.tsx | 2 +- src/home/HomePage.tsx | 1 + src/home/JoinExistingCallModal.tsx | 1 + src/home/RegisteredView.tsx | 26 +++++++++++++++++--------- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/form/Form.tsx b/src/form/Form.tsx index fbe7fe0..944724b 100644 --- a/src/form/Form.tsx +++ b/src/form/Form.tsx @@ -15,16 +15,25 @@ limitations under the License. */ import classNames from "classnames"; -import React, { forwardRef } from "react"; +import React, { FormEventHandler, forwardRef } from "react"; import styles from "./Form.module.css"; -export const Form = forwardRef( - ({ children, className, ...rest }, ref) => { - return ( -
- {children} -
- ); +export const Form = forwardRef< + HTMLFormElement, + { + className: string; + onSubmit: FormEventHandler; + children: JSX.Element[]; } -); +>(({ children, className, onSubmit }, ref) => { + return ( +
+ {children} +
+ ); +}); diff --git a/src/home/CallList.tsx b/src/home/CallList.tsx index c9c29d8..b7611aa 100644 --- a/src/home/CallList.tsx +++ b/src/home/CallList.tsx @@ -16,7 +16,7 @@ limitations under the License. import React from "react"; import { Link } from "react-router-dom"; -import { MatrixClient, Room, RoomMember } from "matrix-js-sdk"; +import { MatrixClient, RoomMember } from "matrix-js-sdk"; import { CopyButton } from "../button"; import { Facepile } from "../Facepile"; diff --git a/src/home/HomePage.tsx b/src/home/HomePage.tsx index 89c9ece..00f770f 100644 --- a/src/home/HomePage.tsx +++ b/src/home/HomePage.tsx @@ -15,6 +15,7 @@ limitations under the License. */ import React from "react"; + import { useClient } from "../ClientContext"; import { ErrorView, LoadingView } from "../FullScreenView"; import { UnauthenticatedView } from "./UnauthenticatedView"; diff --git a/src/home/JoinExistingCallModal.tsx b/src/home/JoinExistingCallModal.tsx index 36b508f..0c17ede 100644 --- a/src/home/JoinExistingCallModal.tsx +++ b/src/home/JoinExistingCallModal.tsx @@ -24,6 +24,7 @@ import styles from "./JoinExistingCallModal.module.css"; interface Props { onJoin: (e: PressEvent) => void; onClose: (e: PressEvent) => void; + // TODO: add used parameters for [index: string]: unknown; } export function JoinExistingCallModal({ onJoin, onClose, ...rest }: Props) { diff --git a/src/home/RegisteredView.tsx b/src/home/RegisteredView.tsx index 8df30ab..7a87bdc 100644 --- a/src/home/RegisteredView.tsx +++ b/src/home/RegisteredView.tsx @@ -14,7 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { useState, useCallback } from "react"; +import React, { + useState, + useCallback, + FormEvent, + FormEventHandler, +} from "react"; import { useHistory } from "react-router-dom"; import { MatrixClient } from "matrix-js-sdk"; @@ -32,27 +37,31 @@ import { JoinExistingCallModal } from "./JoinExistingCallModal"; import { Title } from "../typography/Typography"; import { Form } from "../form/Form"; import { CallType, CallTypeDropdown } from "./CallTypeDropdown"; +interface Props { + client: MatrixClient; + isPasswordlessUser: boolean; +} -export function RegisteredView({ client }: { client: MatrixClient }) { +export function RegisteredView({ client, isPasswordlessUser }: Props) { const [callType, setCallType] = useState(CallType.Video); const [loading, setLoading] = useState(false); const [error, setError] = useState(); const history = useHistory(); const { modalState, modalProps } = useModalTriggerState(); - const onSubmit = useCallback( - (e) => { + const onSubmit: FormEventHandler = useCallback( + (e: FormEvent) => { e.preventDefault(); - const data = new FormData(e.target); + const data = new FormData(e.target as HTMLFormElement); const roomNameData = data.get("callName"); const roomName = typeof roomNameData === "string" ? roomNameData : ""; - const ptt = callType === CallType.Radio; + // const ptt = callType === CallType.Radio; async function submit() { setError(undefined); setLoading(true); - const [roomIdOrAlias] = await createRoom(client, roomName, ptt); + const [roomIdOrAlias] = await createRoom(client, roomName); if (roomIdOrAlias) { history.push(`/room/${roomIdOrAlias}`); @@ -69,11 +78,10 @@ export function RegisteredView({ client }: { client: MatrixClient }) { console.error(error); setLoading(false); setError(error); - reset(); } }); }, - [callType, client, history, modalState] + [client, history, modalState] ); const recentRooms = useGroupCallRooms(client);