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);
}
return () => {
return (): void => {
if (initClientState.client) {
initClientState.client.removeListener(ClientEvent.Sync, onSync);
}

View File

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

View File

@@ -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<LoginResponse> =>
authClient.login("m.login.password", {
identifier: {
type: "m.id.user",

View File

@@ -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<RegisterResponse> =>
authClient.current!.registerRequest({
username,
password,

View File

@@ -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,

View File

@@ -59,7 +59,7 @@ function useObservableState<T>(
// 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;
}

View File

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

View File

@@ -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);

View File

@@ -94,7 +94,7 @@ export const GroupCallView: FC<Props> = ({
useEffect(() => {
window.rtcSession = rtcSession;
return () => {
return (): void => {
delete window.rtcSession;
};
}, [rtcSession]);
@@ -200,7 +200,7 @@ export const GroupCallView: FC<Props> = ({
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<Props> = ({
await leaveRTCSession(rtcSession);
};
widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup);
return () => {
return (): void => {
widget!.lazyActions.off(ElementWidgetActions.HangupCall, onHangup);
};
}

View File

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

View File

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

View File

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

View File

@@ -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

View File

@@ -47,7 +47,7 @@ export const ProfileSettingsTab: FC<Props> = ({ 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");

View File

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

View File

@@ -33,7 +33,7 @@ export function useEventTarget<T extends Event>(
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]);

View File

@@ -32,7 +32,7 @@ export const useLocalStorage = (
useEffect(() => {
localStorageBus.on(key, setValue);
return () => {
return (): void => {
localStorageBus.off(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
// @ts-ignore
if (unblock) {

View File

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

View File

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

View File

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

View File

@@ -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<T>({
});
observer.observe(slotsRoot, { attributes: true });
return () => observer.disconnect();
return (): void => observer.disconnect();
}
}, [slotsRoot, setRenderedGeneration]);
@@ -174,8 +175,8 @@ export function NewVideoGrid<T>({
const [tileTransitions, springRef] = useTransition(
tiles,
() => ({
key: ({ item }: Tile<T>) => item.id,
from: ({ x, y, width, height }: Tile<T>) => ({
key: ({ item }: Tile<T>): string => item.id,
from: ({ x, y, width, height }: Tile<T>): TileSpringUpdate => ({
opacity: 0,
scale: 0,
shadow: 0,
@@ -188,7 +189,13 @@ export function NewVideoGrid<T>({
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
? null
: {
@@ -230,7 +237,7 @@ export function NewVideoGrid<T>({
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,

View File

@@ -77,6 +77,13 @@ export interface TileSpring {
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";
export function useVideoGridLayout(hasScreenshareFeeds: boolean): {
@@ -120,7 +127,7 @@ function useIsMounted(): MutableRefObject<boolean> {
useEffect(() => {
isMountedRef.current = true;
return () => {
return (): void => {
isMountedRef.current = false;
};
}, []);
@@ -1026,7 +1033,7 @@ export function VideoGrid<T>({
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<T>({
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<T>({
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),
};
}
};