Skip to content

Commit 44b9bd0

Browse files
authored
Merge pull request #485 from toger5/ts_Form+Home
2 parents 2e38558 + cb5b3e9 commit 44b9bd0

File tree

8 files changed

+103
-39
lines changed

8 files changed

+103
-39
lines changed

src/ClientContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ interface ClientState {
6262
changePassword: (password: string) => Promise<void>;
6363
logout: () => void;
6464
setClient: (client: MatrixClient, session: Session) => void;
65+
error?: Error;
6566
}
6667

6768
const ClientContext = createContext<ClientState>(null);

src/button/CopyButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import { Button, ButtonVariant } from "./Button";
2323

2424
interface Props {
2525
value: string;
26-
children: JSX.Element;
26+
children?: JSX.Element;
2727
className: string;
2828
variant: ButtonVariant;
29-
copiedMessage: string;
29+
copiedMessage?: string;
3030
}
3131
export function CopyButton({
3232
value,

src/form/Form.jsx renamed to src/form/Form.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@ limitations under the License.
1515
*/
1616

1717
import classNames from "classnames";
18-
import React, { forwardRef } from "react";
18+
import React, { FormEventHandler, forwardRef } from "react";
19+
1920
import styles from "./Form.module.css";
2021

21-
export const Form = forwardRef(({ children, className, ...rest }, ref) => {
22-
return (
23-
<form {...rest} className={classNames(styles.form, className)} ref={ref}>
24-
{children}
25-
</form>
26-
);
27-
});
22+
interface FormProps {
23+
className: string;
24+
onSubmit: FormEventHandler<HTMLFormElement>;
25+
children: JSX.Element[];
26+
}
27+
28+
export const Form = forwardRef<HTMLFormElement, FormProps>(
29+
({ children, className, onSubmit }, ref) => {
30+
return (
31+
<form
32+
onSubmit={onSubmit}
33+
className={classNames(styles.form, className)}
34+
ref={ref}
35+
>
36+
{children}
37+
</form>
38+
);
39+
}
40+
);

src/home/CallList.jsx renamed to src/home/CallList.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ limitations under the License.
1616

1717
import React from "react";
1818
import { Link } from "react-router-dom";
19+
import { MatrixClient, RoomMember } from "matrix-js-sdk";
20+
1921
import { CopyButton } from "../button";
2022
import { Facepile } from "../Facepile";
21-
import { Avatar } from "../Avatar";
23+
import { Avatar, Size } from "../Avatar";
2224
import styles from "./CallList.module.css";
2325
import { getRoomUrl } from "../matrix-utils";
2426
import { Body, Caption } from "../typography/Typography";
27+
import { GroupCallRoom } from "./useGroupCallRooms";
2528

26-
export function CallList({ rooms, client, disableFacepile }) {
29+
interface CallListProps {
30+
rooms: GroupCallRoom[];
31+
client: MatrixClient;
32+
disableFacepile?: boolean;
33+
}
34+
export function CallList({ rooms, client, disableFacepile }: CallListProps) {
2735
return (
2836
<>
2937
<div className={styles.callList}>
@@ -48,20 +56,27 @@ export function CallList({ rooms, client, disableFacepile }) {
4856
</>
4957
);
5058
}
51-
59+
interface CallTileProps {
60+
name: string;
61+
avatarUrl: string;
62+
roomId: string;
63+
participants: RoomMember[];
64+
client: MatrixClient;
65+
disableFacepile?: boolean;
66+
}
5267
function CallTile({
5368
name,
5469
avatarUrl,
5570
roomId,
5671
participants,
5772
client,
5873
disableFacepile,
59-
}) {
74+
}: CallTileProps) {
6075
return (
6176
<div className={styles.callTile}>
6277
<Link to={`/room/${roomId}`} className={styles.callTileLink}>
6378
<Avatar
64-
size="lg"
79+
size={Size.LG}
6580
bgKey={name}
6681
src={avatarUrl}
6782
fallback={name.slice(0, 1).toUpperCase()}

src/home/HomePage.jsx renamed to src/home/HomePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from "react";
18+
1819
import { useClient } from "../ClientContext";
1920
import { ErrorView, LoadingView } from "../FullScreenView";
2021
import { UnauthenticatedView } from "./UnauthenticatedView";

src/home/JoinExistingCallModal.jsx renamed to src/home/JoinExistingCallModal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ limitations under the License.
1515
*/
1616

1717
import React from "react";
18+
import { PressEvent } from "@react-types/shared";
19+
1820
import { Modal, ModalContent } from "../Modal";
1921
import { Button } from "../button";
2022
import { FieldRow } from "../input/Input";
2123
import styles from "./JoinExistingCallModal.module.css";
2224

23-
export function JoinExistingCallModal({ onJoin, ...rest }) {
25+
interface Props {
26+
onJoin: (e: PressEvent) => void;
27+
onClose: (e: PressEvent) => void;
28+
// TODO: add used parameters for <Modal>
29+
[index: string]: unknown;
30+
}
31+
export function JoinExistingCallModal({ onJoin, onClose, ...rest }: Props) {
2432
return (
2533
<Modal title="Join existing call?" isDismissable {...rest}>
2634
<ModalContent>
2735
<p>This call already exists, would you like to join?</p>
2836
<FieldRow rightAlign className={styles.buttons}>
29-
<Button onPress={rest.onClose}>No</Button>
37+
<Button onPress={onClose}>No</Button>
3038
<Button onPress={onJoin}>Yes, join call</Button>
3139
</FieldRow>
3240
</ModalContent>

src/home/RegisteredView.jsx renamed to src/home/RegisteredView.tsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { useState, useCallback } from "react";
17+
import React, {
18+
useState,
19+
useCallback,
20+
FormEvent,
21+
FormEventHandler,
22+
} from "react";
23+
import { useHistory } from "react-router-dom";
24+
import { MatrixClient } from "matrix-js-sdk";
25+
1826
import { createRoom, roomAliasLocalpartFromRoomName } from "../matrix-utils";
1927
import { useGroupCallRooms } from "./useGroupCallRooms";
2028
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
@@ -26,28 +34,35 @@ import { CallList } from "./CallList";
2634
import { UserMenuContainer } from "../UserMenuContainer";
2735
import { useModalTriggerState } from "../Modal";
2836
import { JoinExistingCallModal } from "./JoinExistingCallModal";
29-
import { useHistory } from "react-router-dom";
3037
import { Title } from "../typography/Typography";
3138
import { Form } from "../form/Form";
3239
import { CallType, CallTypeDropdown } from "./CallTypeDropdown";
3340

34-
export function RegisteredView({ client }) {
41+
interface Props {
42+
client: MatrixClient;
43+
isPasswordlessUser: boolean;
44+
}
45+
46+
export function RegisteredView({ client, isPasswordlessUser }: Props) {
3547
const [callType, setCallType] = useState(CallType.Video);
3648
const [loading, setLoading] = useState(false);
37-
const [error, setError] = useState();
49+
const [error, setError] = useState<Error>();
3850
const history = useHistory();
39-
const onSubmit = useCallback(
40-
(e) => {
51+
const { modalState, modalProps } = useModalTriggerState();
52+
53+
const onSubmit: FormEventHandler<HTMLFormElement> = useCallback(
54+
(e: FormEvent) => {
4155
e.preventDefault();
42-
const data = new FormData(e.target);
43-
const roomName = data.get("callName");
44-
const ptt = callType === CallType.Radio;
56+
const data = new FormData(e.target as HTMLFormElement);
57+
const roomNameData = data.get("callName");
58+
const roomName = typeof roomNameData === "string" ? roomNameData : "";
59+
// const ptt = callType === CallType.Radio;
4560

4661
async function submit() {
4762
setError(undefined);
4863
setLoading(true);
4964

50-
const [roomIdOrAlias] = await createRoom(client, roomName, ptt);
65+
const [roomIdOrAlias] = await createRoom(client, roomName);
5166

5267
if (roomIdOrAlias) {
5368
history.push(`/room/${roomIdOrAlias}`);
@@ -64,17 +79,15 @@ export function RegisteredView({ client }) {
6479
console.error(error);
6580
setLoading(false);
6681
setError(error);
67-
reset();
6882
}
6983
});
7084
},
71-
[client, callType]
85+
[client, history, modalState]
7286
);
7387

7488
const recentRooms = useGroupCallRooms(client);
7589

76-
const { modalState, modalProps } = useModalTriggerState();
77-
const [existingRoomId, setExistingRoomId] = useState();
90+
const [existingRoomId, setExistingRoomId] = useState<string>();
7891
const onJoinExistingRoom = useCallback(() => {
7992
history.push(`/${existingRoomId}`);
8093
}, [history, existingRoomId]);

src/home/useGroupCallRooms.js renamed to src/home/useGroupCallRooms.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import { GroupCall, MatrixClient, Room, RoomMember } from "matrix-js-sdk";
18+
import { GroupCallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/groupCallEventHandler";
1719
import { useState, useEffect } from "react";
1820

19-
const tsCache = {};
21+
export interface GroupCallRoom {
22+
roomId: string;
23+
roomName: string;
24+
avatarUrl: string;
25+
room: Room;
26+
groupCall: GroupCall;
27+
participants: RoomMember[];
28+
}
29+
const tsCache: { [index: string]: number } = {};
2030

21-
function getLastTs(client, r) {
31+
function getLastTs(client: MatrixClient, r: Room) {
2232
if (tsCache[r.roomId]) {
2333
return tsCache[r.roomId];
2434
}
@@ -59,13 +69,13 @@ function getLastTs(client, r) {
5969
return ts;
6070
}
6171

62-
function sortRooms(client, rooms) {
72+
function sortRooms(client: MatrixClient, rooms: Room[]): Room[] {
6373
return rooms.sort((a, b) => {
6474
return getLastTs(client, b) - getLastTs(client, a);
6575
});
6676
}
6777

68-
export function useGroupCallRooms(client) {
78+
export function useGroupCallRooms(client: MatrixClient): GroupCallRoom[] {
6979
const [rooms, setRooms] = useState([]);
7080

7181
useEffect(() => {
@@ -90,12 +100,15 @@ export function useGroupCallRooms(client) {
90100

91101
updateRooms();
92102

93-
client.on("GroupCall.incoming", updateRooms);
94-
client.on("GroupCall.participants", updateRooms);
103+
client.on(GroupCallEventHandlerEvent.Incoming, updateRooms);
104+
client.on(GroupCallEventHandlerEvent.Participants, updateRooms);
95105

96106
return () => {
97-
client.removeListener("GroupCall.incoming", updateRooms);
98-
client.removeListener("GroupCall.participants", updateRooms);
107+
client.removeListener(GroupCallEventHandlerEvent.Incoming, updateRooms);
108+
client.removeListener(
109+
GroupCallEventHandlerEvent.Participants,
110+
updateRooms
111+
);
99112
};
100113
}, [client]);
101114

0 commit comments

Comments
 (0)