diff --git a/src/ClientContext.tsx b/src/ClientContext.tsx index 3c99c04d..619626f7 100644 --- a/src/ClientContext.tsx +++ b/src/ClientContext.tsx @@ -317,7 +317,7 @@ export const ClientProvider: FC = ({ children }) => { initClientState.client.on(ClientEvent.Sync, onSync); } - return () => { + return (): void => { if (initClientState.client) { initClientState.client.removeListener(ClientEvent.Sync, onSync); } diff --git a/src/Toast.tsx b/src/Toast.tsx index ca3e2fab..fffbec97 100644 --- a/src/Toast.tsx +++ b/src/Toast.tsx @@ -76,7 +76,7 @@ export const Toast: FC = ({ useEffect(() => { if (open && autoDismiss !== undefined) { const timeout = setTimeout(onDismiss, autoDismiss); - return () => clearTimeout(timeout); + return (): void => clearTimeout(timeout); } }, [open, autoDismiss, onDismiss]); diff --git a/src/auth/useInteractiveLogin.ts b/src/auth/useInteractiveLogin.ts index 83767f51..7ea01811 100644 --- a/src/auth/useInteractiveLogin.ts +++ b/src/auth/useInteractiveLogin.ts @@ -16,7 +16,11 @@ limitations under the License. import { useCallback } from "react"; import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth"; -import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { + createClient, + LoginResponse, + MatrixClient, +} from "matrix-js-sdk/src/matrix"; import { initClient } from "../matrix-utils"; import { Session } from "../ClientContext"; @@ -37,7 +41,7 @@ export function useInteractiveLogin(): ( const interactiveAuth = new InteractiveAuth({ matrixClient: authClient, - doRequest: () => + doRequest: (): Promise => authClient.login("m.login.password", { identifier: { type: "m.id.user", diff --git a/src/auth/useInteractiveRegistration.ts b/src/auth/useInteractiveRegistration.ts index 135d1fac..f7a7854e 100644 --- a/src/auth/useInteractiveRegistration.ts +++ b/src/auth/useInteractiveRegistration.ts @@ -16,7 +16,11 @@ limitations under the License. import { useState, useEffect, useCallback, useRef } from "react"; import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth"; -import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { + createClient, + MatrixClient, + RegisterResponse, +} from "matrix-js-sdk/src/matrix"; import { initClient } from "../matrix-utils"; import { Session } from "../ClientContext"; @@ -69,7 +73,7 @@ export const useInteractiveRegistration = (): { ): Promise<[MatrixClient, Session]> => { const interactiveAuth = new InteractiveAuth({ matrixClient: authClient.current!, - doRequest: (auth) => + doRequest: (auth): Promise => authClient.current!.registerRequest({ username, password, diff --git a/src/home/useGroupCallRooms.ts b/src/home/useGroupCallRooms.ts index 21426a2d..ea513587 100644 --- a/src/home/useGroupCallRooms.ts +++ b/src/home/useGroupCallRooms.ts @@ -166,7 +166,7 @@ export function useGroupCallRooms(client: MatrixClient): GroupCallRoom[] { updateRooms, ); client.on(RoomEvent.MyMembership, updateRooms); - return () => { + return (): void => { client.matrixRTC.off( MatrixRTCSessionManagerEvents.SessionStarted, updateRooms, diff --git a/src/livekit/MediaDevicesContext.tsx b/src/livekit/MediaDevicesContext.tsx index 027f12ae..b42a0afa 100644 --- a/src/livekit/MediaDevicesContext.tsx +++ b/src/livekit/MediaDevicesContext.tsx @@ -59,7 +59,7 @@ function useObservableState( // observable state doesn't run in SSR if (typeof window === "undefined" || !observable) return; const subscription = observable.subscribe(setState); - return () => subscription.unsubscribe(); + return (): void => subscription.unsubscribe(); }, [observable]); return state; } diff --git a/src/livekit/useECConnectionState.ts b/src/livekit/useECConnectionState.ts index ae9160b1..c2bd0aa7 100644 --- a/src/livekit/useECConnectionState.ts +++ b/src/livekit/useECConnectionState.ts @@ -192,7 +192,7 @@ export function useECConnectionState( livekitRoom.on(RoomEvent.ConnectionStateChanged, onConnStateChanged); } - return () => { + return (): void => { if (oldRoom) oldRoom.off(RoomEvent.ConnectionStateChanged, onConnStateChanged); }; diff --git a/src/profile/useProfile.ts b/src/profile/useProfile.ts index eba0420f..ab72a9bf 100644 --- a/src/profile/useProfile.ts +++ b/src/profile/useProfile.ts @@ -82,7 +82,7 @@ export function useProfile(client: MatrixClient | undefined): UseProfile { user?.on(UserEvent.AvatarUrl, onChangeUser); } - return () => { + return (): void => { if (user) { user.removeListener(UserEvent.DisplayName, onChangeUser); user.removeListener(UserEvent.AvatarUrl, onChangeUser); diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index a3fe1dbd..2052a649 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -94,7 +94,7 @@ export const GroupCallView: FC = ({ useEffect(() => { window.rtcSession = rtcSession; - return () => { + return (): void => { delete window.rtcSession; }; }, [rtcSession]); @@ -200,7 +200,7 @@ export const GroupCallView: FC = ({ await widget!.api.transport.reply(ev.detail, {}); }; widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); - return () => { + return (): void => { widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); }; } else if (widget && !preload && skipLobby) { @@ -255,7 +255,7 @@ export const GroupCallView: FC = ({ await leaveRTCSession(rtcSession); }; widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup); - return () => { + return (): void => { widget!.lazyActions.off(ElementWidgetActions.HangupCall, onHangup); }; } diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 56cdba49..94edace7 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -97,7 +97,7 @@ export const ActiveCall: FC = (props) => { ); useEffect(() => { - return () => { + return (): void => { livekitRoom?.disconnect(); }; // eslint-disable-next-line react-hooks/exhaustive-deps @@ -220,7 +220,7 @@ export const InCallView: FC = subscribe( onSpotlightLayout, ); - return () => { + return (): void => { widget!.lazyActions.off( ElementWidgetActions.TileLayout, onTileLayout, diff --git a/src/room/VideoPreview.tsx b/src/room/VideoPreview.tsx index 49342c42..2f6dbbbc 100644 --- a/src/room/VideoPreview.tsx +++ b/src/room/VideoPreview.tsx @@ -110,7 +110,7 @@ export const VideoPreview: FC = ({ if (videoEl.current) { videoTrack?.attach(videoEl.current); } - return () => { + return (): void => { videoTrack?.detach(); }; }, [videoTrack]); diff --git a/src/room/useActiveFocus.ts b/src/room/useActiveFocus.ts index 8e6435d2..5a7b1743 100644 --- a/src/room/useActiveFocus.ts +++ b/src/room/useActiveFocus.ts @@ -64,7 +64,7 @@ export function useActiveFocus( onMembershipsChanged, ); - return () => { + return (): void => { rtcSession.off( MatrixRTCSessionEvent.MembershipsChanged, onMembershipsChanged, diff --git a/src/room/usePageUnload.ts b/src/room/usePageUnload.ts index 6af3a8f9..679ae9e9 100644 --- a/src/room/usePageUnload.ts +++ b/src/room/usePageUnload.ts @@ -50,7 +50,7 @@ export function usePageUnload(callback: () => void): void { // @ts-ignore window.addEventListener("beforeunload", onBeforeUnload); - return () => { + return (): void => { window.removeEventListener("pagehide", onBeforeUnload); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/src/settings/ProfileSettingsTab.tsx b/src/settings/ProfileSettingsTab.tsx index 83ecae74..e0062f58 100644 --- a/src/settings/ProfileSettingsTab.tsx +++ b/src/settings/ProfileSettingsTab.tsx @@ -47,7 +47,7 @@ export const ProfileSettingsTab: FC = ({ client }) => { useEffect(() => { const form = formRef.current!; // Auto-save when the user dismisses this component - return () => { + return (): void => { if (formChanged.current) { const data = new FormData(form); const displayNameDataEntry = data.get("displayName"); diff --git a/src/settings/submit-rageshake.ts b/src/settings/submit-rageshake.ts index 675314bc..3a98b831 100644 --- a/src/settings/submit-rageshake.ts +++ b/src/settings/submit-rageshake.ts @@ -334,7 +334,7 @@ export function useRageshakeRequestModal( client.on(ClientEvent.Event, onEvent); - return () => { + return (): void => { client.removeListener(ClientEvent.Event, onEvent); }; }, [setOpen, roomId, client]); diff --git a/src/useEvents.ts b/src/useEvents.ts index a116a050..66c5084a 100644 --- a/src/useEvents.ts +++ b/src/useEvents.ts @@ -33,7 +33,7 @@ export function useEventTarget( useEffect(() => { if (target) { target.addEventListener(eventType, listener as EventListener, options); - return () => + return (): void => target.removeEventListener( eventType, listener as EventListener, @@ -55,7 +55,7 @@ export function useTypedEventEmitter< ): void { useEffect(() => { emitter.on(eventType, listener); - return () => { + return (): void => { emitter.off(eventType, listener); }; }, [emitter, eventType, listener]); @@ -72,7 +72,7 @@ export function useEventEmitterThree< ): void { useEffect(() => { emitter.on(eventType, listener); - return () => { + return (): void => { emitter.off(eventType, listener); }; }, [emitter, eventType, listener]); diff --git a/src/useLocalStorage.ts b/src/useLocalStorage.ts index 07d487ea..318c691f 100644 --- a/src/useLocalStorage.ts +++ b/src/useLocalStorage.ts @@ -32,7 +32,7 @@ export const useLocalStorage = ( useEffect(() => { localStorageBus.on(key, setValue); - return () => { + return (): void => { localStorageBus.off(key, setValue); }; }, [key, setValue]); diff --git a/src/useLocationNavigation.ts b/src/useLocationNavigation.ts index 08f28fc9..cc1c2f9f 100644 --- a/src/useLocationNavigation.ts +++ b/src/useLocationNavigation.ts @@ -34,7 +34,7 @@ export function useLocationNavigation(enabled = false): void { }); } - return () => { + return (): void => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore if (unblock) { diff --git a/src/useMatrixRTCSessionJoinState.ts b/src/useMatrixRTCSessionJoinState.ts index 7aac4e83..af7618df 100644 --- a/src/useMatrixRTCSessionJoinState.ts +++ b/src/useMatrixRTCSessionJoinState.ts @@ -38,7 +38,7 @@ export function useMatrixRTCSessionJoinState( useEffect(() => { rtcSession.on(MatrixRTCSessionEvent.JoinStateChanged, onJoinStateChanged); - return () => { + return (): void => { rtcSession.off( MatrixRTCSessionEvent.JoinStateChanged, onJoinStateChanged, diff --git a/src/useMatrixRTCSessionMemberships.ts b/src/useMatrixRTCSessionMemberships.ts index 3873b7a2..a7d62ba7 100644 --- a/src/useMatrixRTCSessionMemberships.ts +++ b/src/useMatrixRTCSessionMemberships.ts @@ -40,7 +40,7 @@ export function useMatrixRTCSessionMemberships( onMembershipsChanged, ); - return () => { + return (): void => { rtcSession.off( MatrixRTCSessionEvent.MembershipsChanged, onMembershipsChanged, diff --git a/src/useWakeLock.ts b/src/useWakeLock.ts index 5f931f75..b1174fa1 100644 --- a/src/useWakeLock.ts +++ b/src/useWakeLock.ts @@ -47,7 +47,7 @@ export function useWakeLock(): void { onVisiblityChange(); document.addEventListener("visiblitychange", onVisiblityChange); - return () => { + return (): void => { mounted = false; if (lock !== null) lock diff --git a/src/video-grid/NewVideoGrid.tsx b/src/video-grid/NewVideoGrid.tsx index 6de5f58d..61813125 100644 --- a/src/video-grid/NewVideoGrid.tsx +++ b/src/video-grid/NewVideoGrid.tsx @@ -33,6 +33,7 @@ import { VideoGridProps as Props, TileSpring, ChildrenProperties, + TileSpringUpdate, } from "./VideoGrid"; import { useReactiveState } from "../useReactiveState"; import { useMergedRefs } from "../useMergedRefs"; @@ -110,7 +111,7 @@ export function NewVideoGrid({ }); observer.observe(slotsRoot, { attributes: true }); - return () => observer.disconnect(); + return (): void => observer.disconnect(); } }, [slotsRoot, setRenderedGeneration]); @@ -174,8 +175,8 @@ export function NewVideoGrid({ const [tileTransitions, springRef] = useTransition( tiles, () => ({ - key: ({ item }: Tile) => item.id, - from: ({ x, y, width, height }: Tile) => ({ + key: ({ item }: Tile): string => item.id, + from: ({ x, y, width, height }: Tile): TileSpringUpdate => ({ opacity: 0, scale: 0, shadow: 0, @@ -188,7 +189,13 @@ export function NewVideoGrid({ immediate: disableAnimations, }), enter: { opacity: 1, scale: 1, immediate: disableAnimations }, - update: ({ item, x, y, width, height }: Tile) => + update: ({ + item, + x, + y, + width, + height, + }: Tile): TileSpringUpdate | null => item.id === dragState.current?.tileId ? null : { @@ -230,7 +237,7 @@ export function NewVideoGrid({ disableAnimations || ((key): boolean => key === "zIndex"), // Allow the tile's position to settle before pushing its // z-index back down - delay: (key) => (key === "zIndex" ? 500 : 0), + delay: (key): number => (key === "zIndex" ? 500 : 0), } : { scale: 1.1, diff --git a/src/video-grid/VideoGrid.tsx b/src/video-grid/VideoGrid.tsx index 202539ba..fa56bd88 100644 --- a/src/video-grid/VideoGrid.tsx +++ b/src/video-grid/VideoGrid.tsx @@ -77,6 +77,13 @@ export interface TileSpring { height: number; } +export interface TileSpringUpdate extends Partial { + from?: Partial; + reset?: boolean; + immediate?: boolean | ((key: string) => boolean); + delay?: (key: string) => number; +} + type LayoutDirection = "vertical" | "horizontal"; export function useVideoGridLayout(hasScreenshareFeeds: boolean): { @@ -120,7 +127,7 @@ function useIsMounted(): MutableRefObject { useEffect(() => { isMountedRef.current = true; - return () => { + return (): void => { isMountedRef.current = false; }; }, []); @@ -1026,7 +1033,7 @@ export function VideoGrid({ const oneOnOneLayout = tiles.length === 2 && !tiles.some((t) => t.focused); - return (tileIndex: number) => { + return (tileIndex: number): TileSpringUpdate => { const tile = tiles[tileIndex]; const tilePosition = tilePositions[tile.order]; const draggingTile = draggingTileRef.current; @@ -1045,7 +1052,7 @@ export function VideoGrid({ zIndex: 2, shadow: 15, shadowSpread: 0, - immediate: (key: string) => + immediate: (key: string): boolean => disableAnimations || key === "zIndex" || key === "x" || @@ -1112,14 +1119,14 @@ export function VideoGrid({ shadowSpread: oneOnOneLayout && tile.item.local ? 1 : 0, from, reset, - immediate: (key: string) => + immediate: (key: string): boolean => disableAnimations || key === "zIndex" || key === "shadow" || key === "shadowSpread", // If we just stopped dragging a tile, give it time for the // animation to settle before pushing its z-index back down - delay: (key: string) => (key === "zIndex" ? 500 : 0), + delay: (key: string): number => (key === "zIndex" ? 500 : 0), }; } };