Fix lints

This commit is contained in:
Robin
2024-06-04 11:20:25 -04:00
parent 07ce272e9f
commit 70fdc68b13
23 changed files with 60 additions and 38 deletions

View File

@@ -317,7 +317,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
initClientState.client.on(ClientEvent.Sync, onSync); initClientState.client.on(ClientEvent.Sync, onSync);
} }
return () => { return (): void => {
if (initClientState.client) { if (initClientState.client) {
initClientState.client.removeListener(ClientEvent.Sync, onSync); initClientState.client.removeListener(ClientEvent.Sync, onSync);
} }

View File

@@ -76,7 +76,7 @@ export const Toast: FC<Props> = ({
useEffect(() => { useEffect(() => {
if (open && autoDismiss !== undefined) { if (open && autoDismiss !== undefined) {
const timeout = setTimeout(onDismiss, autoDismiss); const timeout = setTimeout(onDismiss, autoDismiss);
return () => clearTimeout(timeout); return (): void => clearTimeout(timeout);
} }
}, [open, autoDismiss, onDismiss]); }, [open, autoDismiss, onDismiss]);

View File

@@ -16,7 +16,11 @@ limitations under the License.
import { useCallback } from "react"; import { useCallback } from "react";
import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth"; 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 { initClient } from "../matrix-utils";
import { Session } from "../ClientContext"; import { Session } from "../ClientContext";
@@ -37,7 +41,7 @@ export function useInteractiveLogin(): (
const interactiveAuth = new InteractiveAuth({ const interactiveAuth = new InteractiveAuth({
matrixClient: authClient, matrixClient: authClient,
doRequest: () => doRequest: (): Promise<LoginResponse> =>
authClient.login("m.login.password", { authClient.login("m.login.password", {
identifier: { identifier: {
type: "m.id.user", type: "m.id.user",

View File

@@ -16,7 +16,11 @@ limitations under the License.
import { useState, useEffect, useCallback, useRef } from "react"; import { useState, useEffect, useCallback, useRef } from "react";
import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth"; 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 { initClient } from "../matrix-utils";
import { Session } from "../ClientContext"; import { Session } from "../ClientContext";
@@ -69,7 +73,7 @@ export const useInteractiveRegistration = (): {
): Promise<[MatrixClient, Session]> => { ): Promise<[MatrixClient, Session]> => {
const interactiveAuth = new InteractiveAuth({ const interactiveAuth = new InteractiveAuth({
matrixClient: authClient.current!, matrixClient: authClient.current!,
doRequest: (auth) => doRequest: (auth): Promise<RegisterResponse> =>
authClient.current!.registerRequest({ authClient.current!.registerRequest({
username, username,
password, password,

View File

@@ -166,7 +166,7 @@ export function useGroupCallRooms(client: MatrixClient): GroupCallRoom[] {
updateRooms, updateRooms,
); );
client.on(RoomEvent.MyMembership, updateRooms); client.on(RoomEvent.MyMembership, updateRooms);
return () => { return (): void => {
client.matrixRTC.off( client.matrixRTC.off(
MatrixRTCSessionManagerEvents.SessionStarted, MatrixRTCSessionManagerEvents.SessionStarted,
updateRooms, updateRooms,

View File

@@ -59,7 +59,7 @@ function useObservableState<T>(
// observable state doesn't run in SSR // observable state doesn't run in SSR
if (typeof window === "undefined" || !observable) return; if (typeof window === "undefined" || !observable) return;
const subscription = observable.subscribe(setState); const subscription = observable.subscribe(setState);
return () => subscription.unsubscribe(); return (): void => subscription.unsubscribe();
}, [observable]); }, [observable]);
return state; return state;
} }

View File

@@ -192,7 +192,7 @@ export function useECConnectionState(
livekitRoom.on(RoomEvent.ConnectionStateChanged, onConnStateChanged); livekitRoom.on(RoomEvent.ConnectionStateChanged, onConnStateChanged);
} }
return () => { return (): void => {
if (oldRoom) if (oldRoom)
oldRoom.off(RoomEvent.ConnectionStateChanged, onConnStateChanged); oldRoom.off(RoomEvent.ConnectionStateChanged, onConnStateChanged);
}; };

View File

@@ -82,7 +82,7 @@ export function useProfile(client: MatrixClient | undefined): UseProfile {
user?.on(UserEvent.AvatarUrl, onChangeUser); user?.on(UserEvent.AvatarUrl, onChangeUser);
} }
return () => { return (): void => {
if (user) { if (user) {
user.removeListener(UserEvent.DisplayName, onChangeUser); user.removeListener(UserEvent.DisplayName, onChangeUser);
user.removeListener(UserEvent.AvatarUrl, onChangeUser); user.removeListener(UserEvent.AvatarUrl, onChangeUser);

View File

@@ -94,7 +94,7 @@ export const GroupCallView: FC<Props> = ({
useEffect(() => { useEffect(() => {
window.rtcSession = rtcSession; window.rtcSession = rtcSession;
return () => { return (): void => {
delete window.rtcSession; delete window.rtcSession;
}; };
}, [rtcSession]); }, [rtcSession]);
@@ -200,7 +200,7 @@ export const GroupCallView: FC<Props> = ({
await widget!.api.transport.reply(ev.detail, {}); await widget!.api.transport.reply(ev.detail, {});
}; };
widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin);
return () => { return (): void => {
widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin);
}; };
} else if (widget && !preload && skipLobby) { } else if (widget && !preload && skipLobby) {
@@ -255,7 +255,7 @@ export const GroupCallView: FC<Props> = ({
await leaveRTCSession(rtcSession); await leaveRTCSession(rtcSession);
}; };
widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup); widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup);
return () => { return (): void => {
widget!.lazyActions.off(ElementWidgetActions.HangupCall, onHangup); widget!.lazyActions.off(ElementWidgetActions.HangupCall, onHangup);
}; };
} }

View File

@@ -97,7 +97,7 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
); );
useEffect(() => { useEffect(() => {
return () => { return (): void => {
livekitRoom?.disconnect(); livekitRoom?.disconnect();
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -220,7 +220,7 @@ export const InCallView: FC<InCallViewProps> = subscribe(
onSpotlightLayout, onSpotlightLayout,
); );
return () => { return (): void => {
widget!.lazyActions.off( widget!.lazyActions.off(
ElementWidgetActions.TileLayout, ElementWidgetActions.TileLayout,
onTileLayout, onTileLayout,

View File

@@ -110,7 +110,7 @@ export const VideoPreview: FC<Props> = ({
if (videoEl.current) { if (videoEl.current) {
videoTrack?.attach(videoEl.current); videoTrack?.attach(videoEl.current);
} }
return () => { return (): void => {
videoTrack?.detach(); videoTrack?.detach();
}; };
}, [videoTrack]); }, [videoTrack]);

View File

@@ -64,7 +64,7 @@ export function useActiveFocus(
onMembershipsChanged, onMembershipsChanged,
); );
return () => { return (): void => {
rtcSession.off( rtcSession.off(
MatrixRTCSessionEvent.MembershipsChanged, MatrixRTCSessionEvent.MembershipsChanged,
onMembershipsChanged, onMembershipsChanged,

View File

@@ -50,7 +50,7 @@ export function usePageUnload(callback: () => void): void {
// @ts-ignore // @ts-ignore
window.addEventListener("beforeunload", onBeforeUnload); window.addEventListener("beforeunload", onBeforeUnload);
return () => { return (): void => {
window.removeEventListener("pagehide", onBeforeUnload); window.removeEventListener("pagehide", onBeforeUnload);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore

View File

@@ -47,7 +47,7 @@ export const ProfileSettingsTab: FC<Props> = ({ client }) => {
useEffect(() => { useEffect(() => {
const form = formRef.current!; const form = formRef.current!;
// Auto-save when the user dismisses this component // Auto-save when the user dismisses this component
return () => { return (): void => {
if (formChanged.current) { if (formChanged.current) {
const data = new FormData(form); const data = new FormData(form);
const displayNameDataEntry = data.get("displayName"); const displayNameDataEntry = data.get("displayName");

View File

@@ -334,7 +334,7 @@ export function useRageshakeRequestModal(
client.on(ClientEvent.Event, onEvent); client.on(ClientEvent.Event, onEvent);
return () => { return (): void => {
client.removeListener(ClientEvent.Event, onEvent); client.removeListener(ClientEvent.Event, onEvent);
}; };
}, [setOpen, roomId, client]); }, [setOpen, roomId, client]);

View File

@@ -33,7 +33,7 @@ export function useEventTarget<T extends Event>(
useEffect(() => { useEffect(() => {
if (target) { if (target) {
target.addEventListener(eventType, listener as EventListener, options); target.addEventListener(eventType, listener as EventListener, options);
return () => return (): void =>
target.removeEventListener( target.removeEventListener(
eventType, eventType,
listener as EventListener, listener as EventListener,
@@ -55,7 +55,7 @@ export function useTypedEventEmitter<
): void { ): void {
useEffect(() => { useEffect(() => {
emitter.on(eventType, listener); emitter.on(eventType, listener);
return () => { return (): void => {
emitter.off(eventType, listener); emitter.off(eventType, listener);
}; };
}, [emitter, eventType, listener]); }, [emitter, eventType, listener]);
@@ -72,7 +72,7 @@ export function useEventEmitterThree<
): void { ): void {
useEffect(() => { useEffect(() => {
emitter.on(eventType, listener); emitter.on(eventType, listener);
return () => { return (): void => {
emitter.off(eventType, listener); emitter.off(eventType, listener);
}; };
}, [emitter, eventType, listener]); }, [emitter, eventType, listener]);

View File

@@ -32,7 +32,7 @@ export const useLocalStorage = (
useEffect(() => { useEffect(() => {
localStorageBus.on(key, setValue); localStorageBus.on(key, setValue);
return () => { return (): void => {
localStorageBus.off(key, setValue); localStorageBus.off(key, setValue);
}; };
}, [key, setValue]); }, [key, setValue]);

View File

@@ -34,7 +34,7 @@ export function useLocationNavigation(enabled = false): void {
}); });
} }
return () => { return (): void => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
if (unblock) { if (unblock) {

View File

@@ -38,7 +38,7 @@ export function useMatrixRTCSessionJoinState(
useEffect(() => { useEffect(() => {
rtcSession.on(MatrixRTCSessionEvent.JoinStateChanged, onJoinStateChanged); rtcSession.on(MatrixRTCSessionEvent.JoinStateChanged, onJoinStateChanged);
return () => { return (): void => {
rtcSession.off( rtcSession.off(
MatrixRTCSessionEvent.JoinStateChanged, MatrixRTCSessionEvent.JoinStateChanged,
onJoinStateChanged, onJoinStateChanged,

View File

@@ -40,7 +40,7 @@ export function useMatrixRTCSessionMemberships(
onMembershipsChanged, onMembershipsChanged,
); );
return () => { return (): void => {
rtcSession.off( rtcSession.off(
MatrixRTCSessionEvent.MembershipsChanged, MatrixRTCSessionEvent.MembershipsChanged,
onMembershipsChanged, onMembershipsChanged,

View File

@@ -47,7 +47,7 @@ export function useWakeLock(): void {
onVisiblityChange(); onVisiblityChange();
document.addEventListener("visiblitychange", onVisiblityChange); document.addEventListener("visiblitychange", onVisiblityChange);
return () => { return (): void => {
mounted = false; mounted = false;
if (lock !== null) if (lock !== null)
lock lock

View File

@@ -33,6 +33,7 @@ import {
VideoGridProps as Props, VideoGridProps as Props,
TileSpring, TileSpring,
ChildrenProperties, ChildrenProperties,
TileSpringUpdate,
} from "./VideoGrid"; } from "./VideoGrid";
import { useReactiveState } from "../useReactiveState"; import { useReactiveState } from "../useReactiveState";
import { useMergedRefs } from "../useMergedRefs"; import { useMergedRefs } from "../useMergedRefs";
@@ -110,7 +111,7 @@ export function NewVideoGrid<T>({
}); });
observer.observe(slotsRoot, { attributes: true }); observer.observe(slotsRoot, { attributes: true });
return () => observer.disconnect(); return (): void => observer.disconnect();
} }
}, [slotsRoot, setRenderedGeneration]); }, [slotsRoot, setRenderedGeneration]);
@@ -174,8 +175,8 @@ export function NewVideoGrid<T>({
const [tileTransitions, springRef] = useTransition( const [tileTransitions, springRef] = useTransition(
tiles, tiles,
() => ({ () => ({
key: ({ item }: Tile<T>) => item.id, key: ({ item }: Tile<T>): string => item.id,
from: ({ x, y, width, height }: Tile<T>) => ({ from: ({ x, y, width, height }: Tile<T>): TileSpringUpdate => ({
opacity: 0, opacity: 0,
scale: 0, scale: 0,
shadow: 0, shadow: 0,
@@ -188,7 +189,13 @@ export function NewVideoGrid<T>({
immediate: disableAnimations, immediate: disableAnimations,
}), }),
enter: { opacity: 1, scale: 1, immediate: disableAnimations }, enter: { opacity: 1, scale: 1, immediate: disableAnimations },
update: ({ item, x, y, width, height }: Tile<T>) => update: ({
item,
x,
y,
width,
height,
}: Tile<T>): TileSpringUpdate | null =>
item.id === dragState.current?.tileId item.id === dragState.current?.tileId
? null ? null
: { : {
@@ -230,7 +237,7 @@ export function NewVideoGrid<T>({
disableAnimations || ((key): boolean => key === "zIndex"), disableAnimations || ((key): boolean => key === "zIndex"),
// Allow the tile's position to settle before pushing its // Allow the tile's position to settle before pushing its
// z-index back down // z-index back down
delay: (key) => (key === "zIndex" ? 500 : 0), delay: (key): number => (key === "zIndex" ? 500 : 0),
} }
: { : {
scale: 1.1, scale: 1.1,

View File

@@ -77,6 +77,13 @@ export interface TileSpring {
height: number; height: number;
} }
export interface TileSpringUpdate extends Partial<TileSpring> {
from?: Partial<TileSpring>;
reset?: boolean;
immediate?: boolean | ((key: string) => boolean);
delay?: (key: string) => number;
}
type LayoutDirection = "vertical" | "horizontal"; type LayoutDirection = "vertical" | "horizontal";
export function useVideoGridLayout(hasScreenshareFeeds: boolean): { export function useVideoGridLayout(hasScreenshareFeeds: boolean): {
@@ -120,7 +127,7 @@ function useIsMounted(): MutableRefObject<boolean> {
useEffect(() => { useEffect(() => {
isMountedRef.current = true; isMountedRef.current = true;
return () => { return (): void => {
isMountedRef.current = false; isMountedRef.current = false;
}; };
}, []); }, []);
@@ -1026,7 +1033,7 @@ export function VideoGrid<T>({
const oneOnOneLayout = const oneOnOneLayout =
tiles.length === 2 && !tiles.some((t) => t.focused); tiles.length === 2 && !tiles.some((t) => t.focused);
return (tileIndex: number) => { return (tileIndex: number): TileSpringUpdate => {
const tile = tiles[tileIndex]; const tile = tiles[tileIndex];
const tilePosition = tilePositions[tile.order]; const tilePosition = tilePositions[tile.order];
const draggingTile = draggingTileRef.current; const draggingTile = draggingTileRef.current;
@@ -1045,7 +1052,7 @@ export function VideoGrid<T>({
zIndex: 2, zIndex: 2,
shadow: 15, shadow: 15,
shadowSpread: 0, shadowSpread: 0,
immediate: (key: string) => immediate: (key: string): boolean =>
disableAnimations || disableAnimations ||
key === "zIndex" || key === "zIndex" ||
key === "x" || key === "x" ||
@@ -1112,14 +1119,14 @@ export function VideoGrid<T>({
shadowSpread: oneOnOneLayout && tile.item.local ? 1 : 0, shadowSpread: oneOnOneLayout && tile.item.local ? 1 : 0,
from, from,
reset, reset,
immediate: (key: string) => immediate: (key: string): boolean =>
disableAnimations || disableAnimations ||
key === "zIndex" || key === "zIndex" ||
key === "shadow" || key === "shadow" ||
key === "shadowSpread", key === "shadowSpread",
// If we just stopped dragging a tile, give it time for the // If we just stopped dragging a tile, give it time for the
// animation to settle before pushing its z-index back down // 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),
}; };
} }
}; };