Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -6,7 +6,7 @@ export type MediaLoadingData = {
|
||||
};
|
||||
|
||||
export const useMediaLoading = (
|
||||
getTargetElement: () => HTMLMediaElement | null
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
): MediaLoadingData => {
|
||||
const [loadingData, setLoadingData] = useState<MediaLoadingData>({
|
||||
loading: false,
|
||||
|
||||
@@ -9,7 +9,7 @@ export type MediaPlayControl = {
|
||||
};
|
||||
|
||||
export const useMediaPlay = (
|
||||
getTargetElement: () => HTMLMediaElement | null
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
): MediaPlayData & MediaPlayControl => {
|
||||
const [playing, setPlay] = useState(false);
|
||||
|
||||
@@ -20,7 +20,7 @@ export const useMediaPlay = (
|
||||
if (play) targetEl.play();
|
||||
else targetEl.pause();
|
||||
},
|
||||
[getTargetElement]
|
||||
[getTargetElement],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -4,7 +4,7 @@ export type PlayTimeCallback = (duration: number, currentTime: number) => void;
|
||||
|
||||
export const useMediaPlayTimeCallback = (
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
onPlayTimeCallback: PlayTimeCallback
|
||||
onPlayTimeCallback: PlayTimeCallback,
|
||||
): void => {
|
||||
useEffect(() => {
|
||||
const targetEl = getTargetElement();
|
||||
|
||||
@@ -8,7 +8,7 @@ export type MediaPlaybackRateControl = {
|
||||
};
|
||||
|
||||
export const useMediaPlaybackRate = (
|
||||
getTargetElement: () => HTMLMediaElement | null
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
): MediaPlaybackRateData & MediaPlaybackRateControl => {
|
||||
const [rate, setRate] = useState(1.0);
|
||||
|
||||
@@ -18,7 +18,7 @@ export const useMediaPlaybackRate = (
|
||||
if (!targetEl) return;
|
||||
targetEl.playbackRate = playbackRate;
|
||||
},
|
||||
[getTargetElement]
|
||||
[getTargetElement],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -9,7 +9,7 @@ export type MediaSeekControl = {
|
||||
};
|
||||
|
||||
export const useMediaSeek = (
|
||||
getTargetElement: () => HTMLMediaElement | null
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
): MediaSeekData & MediaSeekControl => {
|
||||
const [seekData, setSeekData] = useState<MediaSeekData>({
|
||||
seeking: false,
|
||||
@@ -22,7 +22,7 @@ export const useMediaSeek = (
|
||||
if (!targetEl) return;
|
||||
targetEl.currentTime = time;
|
||||
},
|
||||
[getTargetElement]
|
||||
[getTargetElement],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -11,7 +11,7 @@ export type MediaVolumeControl = {
|
||||
};
|
||||
|
||||
export const useMediaVolume = (
|
||||
getTargetElement: () => HTMLMediaElement | null
|
||||
getTargetElement: () => HTMLMediaElement | null,
|
||||
): MediaVolumeData & MediaVolumeControl => {
|
||||
const [volumeData, setVolumeData] = useState<MediaVolumeData>({
|
||||
volume: 1,
|
||||
@@ -24,7 +24,7 @@ export const useMediaVolume = (
|
||||
if (!targetEl) return;
|
||||
targetEl.muted = mute;
|
||||
},
|
||||
[getTargetElement]
|
||||
[getTargetElement],
|
||||
);
|
||||
|
||||
const setVolume = useCallback(
|
||||
@@ -33,7 +33,7 @@ export const useMediaVolume = (
|
||||
if (!targetEl) return;
|
||||
targetEl.volume = volume;
|
||||
},
|
||||
[getTargetElement]
|
||||
[getTargetElement],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -8,5 +8,5 @@ export type RequestEmailTokenResponse = {
|
||||
export type RequestEmailTokenCallback = (
|
||||
email: string,
|
||||
clientSecret: string,
|
||||
nextLink?: string
|
||||
nextLink?: string,
|
||||
) => Promise<RequestEmailTokenResponse>;
|
||||
|
||||
@@ -14,8 +14,8 @@ export function useAccountData(eventType: string) {
|
||||
setEvent(evt);
|
||||
}
|
||||
},
|
||||
[eventType, setEvent]
|
||||
)
|
||||
[eventType, setEvent],
|
||||
),
|
||||
);
|
||||
|
||||
return event;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
||||
|
||||
export const useAccountDataCallback = (
|
||||
mx: MatrixClient,
|
||||
onAccountData: ClientEventHandlerMap[ClientEvent.AccountData]
|
||||
onAccountData: ClientEventHandlerMap[ClientEvent.AccountData],
|
||||
) => {
|
||||
useEffect(() => {
|
||||
mx.on(ClientEvent.AccountData, onAccountData);
|
||||
|
||||
@@ -10,7 +10,7 @@ export const useAccountManagementActions = () => {
|
||||
accountDeactivate: 'org.matrix.account_deactivate',
|
||||
crossSigningReset: 'org.matrix.cross_signing_reset',
|
||||
}),
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
return actions;
|
||||
|
||||
@@ -33,7 +33,7 @@ export type AsyncCallback<TArgs extends unknown[], TData> = (...args: TArgs) =>
|
||||
|
||||
export const useAsync = <TData, TError, TArgs extends unknown[]>(
|
||||
asyncCallback: AsyncCallback<TArgs, TData>,
|
||||
onStateChange: (state: AsyncState<TData, TError>) => void
|
||||
onStateChange: (state: AsyncState<TData, TError>) => void,
|
||||
): AsyncCallback<TArgs, TData> => {
|
||||
const alive = useAlive();
|
||||
|
||||
@@ -90,14 +90,14 @@ export const useAsync = <TData, TError, TArgs extends unknown[]>(
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
[asyncCallback, alive, onStateChange]
|
||||
[asyncCallback, alive, onStateChange],
|
||||
);
|
||||
|
||||
return callback;
|
||||
};
|
||||
|
||||
export const useAsyncCallback = <TData, TError, TArgs extends unknown[]>(
|
||||
asyncCallback: AsyncCallback<TArgs, TData>
|
||||
asyncCallback: AsyncCallback<TArgs, TData>,
|
||||
): [AsyncState<TData, TError>, AsyncCallback<TArgs, TData>] => {
|
||||
const [state, setState] = useState<AsyncState<TData, TError>>({
|
||||
status: AsyncStatus.Idle,
|
||||
@@ -109,7 +109,7 @@ export const useAsyncCallback = <TData, TError, TArgs extends unknown[]>(
|
||||
};
|
||||
|
||||
export const useAsyncCallbackValue = <TData, TError>(
|
||||
asyncCallback: AsyncCallback<[], TData>
|
||||
asyncCallback: AsyncCallback<[], TData>,
|
||||
): [AsyncState<TData, TError>, AsyncCallback<[], TData>] => {
|
||||
const [state, load] = useAsyncCallback<TData, TError, []>(asyncCallback);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export type UseAsyncSearchOptions = AsyncSearchOption & {
|
||||
|
||||
export type SearchItemStrGetter<TSearchItem extends object | string | number> = (
|
||||
searchItem: TSearchItem,
|
||||
query: string
|
||||
query: string,
|
||||
) => string | string[];
|
||||
|
||||
export type UseAsyncSearchResult<TSearchItem extends object | string | number> = {
|
||||
@@ -32,11 +32,11 @@ export type SearchResetHandler = () => void;
|
||||
const performMatch = (
|
||||
target: string | string[],
|
||||
query: string,
|
||||
options?: UseAsyncSearchOptions
|
||||
options?: UseAsyncSearchOptions,
|
||||
): string | undefined => {
|
||||
if (Array.isArray(target)) {
|
||||
const matchTarget = target.find((i) =>
|
||||
matchQuery(normalize(i, options?.normalizeOptions), query, options?.matchOptions)
|
||||
matchQuery(normalize(i, options?.normalizeOptions), query, options?.matchOptions),
|
||||
);
|
||||
return matchTarget ? normalize(matchTarget, options?.normalizeOptions) : undefined;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export const orderSearchItems = <TSearchItem extends object | string | number>(
|
||||
query: string,
|
||||
items: TSearchItem[],
|
||||
getItemStr: SearchItemStrGetter<TSearchItem>,
|
||||
options?: UseAsyncSearchOptions
|
||||
options?: UseAsyncSearchOptions,
|
||||
): TSearchItem[] => {
|
||||
const orderedItems: TSearchItem[] = Array.from(items);
|
||||
|
||||
@@ -107,7 +107,7 @@ export const orderSearchItems = <TSearchItem extends object | string | number>(
|
||||
export const useAsyncSearch = <TSearchItem extends object | string | number>(
|
||||
list: TSearchItem[],
|
||||
getItemStr: SearchItemStrGetter<TSearchItem>,
|
||||
options?: UseAsyncSearchOptions
|
||||
options?: UseAsyncSearchOptions,
|
||||
): [UseAsyncSearchResult<TSearchItem> | undefined, AsyncSearchHandler, SearchResetHandler] => {
|
||||
const [result, setResult] = useState<UseAsyncSearchResult<TSearchItem>>();
|
||||
|
||||
@@ -135,7 +135,7 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
|
||||
const normalizedQuery = normalize(query, options?.normalizeOptions);
|
||||
searchCallback(normalizedQuery);
|
||||
},
|
||||
[searchCallback, options?.normalizeOptions]
|
||||
[searchCallback, options?.normalizeOptions],
|
||||
);
|
||||
|
||||
const resetHandler: SearchResetHandler = useCallback(() => {
|
||||
@@ -148,7 +148,7 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
|
||||
// terminate any ongoing search request on unmount.
|
||||
terminateSearch();
|
||||
},
|
||||
[terminateSearch]
|
||||
[terminateSearch],
|
||||
);
|
||||
|
||||
return [result, searchHandler, resetHandler];
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
*/
|
||||
export const useAuthenticatedMediaUrl = (
|
||||
src: string | undefined,
|
||||
useAuthentication: boolean
|
||||
useAuthentication: boolean,
|
||||
): string | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
const [blobUrl, setBlobUrl] = useState<string | undefined>(() => {
|
||||
@@ -74,6 +74,6 @@ export const useAuthenticatedMediaFetch = () => {
|
||||
return src;
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
};
|
||||
|
||||
@@ -63,10 +63,7 @@ function isHierarchySpace(hierarchyRoom: IHierarchyRoom): boolean {
|
||||
* @param spaceId - The space room ID
|
||||
* @returns Array of hierarchy rooms
|
||||
*/
|
||||
async function fetchSpaceHierarchy(
|
||||
mx: MatrixClient,
|
||||
spaceId: string
|
||||
): Promise<IHierarchyRoom[]> {
|
||||
async function fetchSpaceHierarchy(mx: MatrixClient, spaceId: string): Promise<IHierarchyRoom[]> {
|
||||
const allRooms: IHierarchyRoom[] = [];
|
||||
let nextBatch: string | undefined;
|
||||
let pageCount = 0;
|
||||
@@ -74,7 +71,13 @@ async function fetchSpaceHierarchy(
|
||||
while (pageCount < MAX_PAGES) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const result = await mx.getRoomHierarchy(spaceId, PER_PAGE_COUNT, undefined, false, nextBatch);
|
||||
const result = await mx.getRoomHierarchy(
|
||||
spaceId,
|
||||
PER_PAGE_COUNT,
|
||||
undefined,
|
||||
false,
|
||||
nextBatch,
|
||||
);
|
||||
allRooms.push(...result.rooms);
|
||||
nextBatch = result.next_batch;
|
||||
pageCount += 1;
|
||||
@@ -114,7 +117,7 @@ async function joinRoomsSequentially(
|
||||
mx: MatrixClient,
|
||||
rooms: IHierarchyRoom[],
|
||||
spaceId: string,
|
||||
onProgress?: ProgressCallback
|
||||
onProgress?: ProgressCallback,
|
||||
): Promise<void> {
|
||||
const spaceServer = getServerFromRoomId(spaceId);
|
||||
|
||||
@@ -155,7 +158,7 @@ async function joinRoomsSequentially(
|
||||
mx,
|
||||
item.room_id,
|
||||
RoomNotificationMode.SpecialMessages,
|
||||
RoomNotificationMode.Unset
|
||||
RoomNotificationMode.Unset,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -171,12 +174,12 @@ async function joinRoomsSequentially(
|
||||
// Join spaces first, then rooms
|
||||
await spacesToJoin.reduce(
|
||||
(promise, space) => promise.then(() => joinItem(space, true)),
|
||||
Promise.resolve()
|
||||
Promise.resolve(),
|
||||
);
|
||||
|
||||
await roomsToJoin.reduce(
|
||||
(promise, room) => promise.then(() => joinItem(room, false)),
|
||||
Promise.resolve()
|
||||
Promise.resolve(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,7 +189,7 @@ async function joinRoomsSequentially(
|
||||
export async function autoJoinSpaceChildren(
|
||||
mx: MatrixClient,
|
||||
spaceId: string,
|
||||
onProgress?: ProgressCallback
|
||||
onProgress?: ProgressCallback,
|
||||
): Promise<void> {
|
||||
if (processingSpaces.has(spaceId)) {
|
||||
return;
|
||||
@@ -237,7 +240,7 @@ export function useAutoJoinSpaceRooms(mx: MatrixClient): void {
|
||||
setJoiningProgress({ spaceId, progress: null });
|
||||
}
|
||||
},
|
||||
[mx, settings.autoJoinSpaceRooms, setJoiningProgress]
|
||||
[mx, settings.autoJoinSpaceRooms, setJoiningProgress],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -295,4 +298,4 @@ export function useAutoJoinOnSpaceVisit(space: Room | undefined): void {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [space, settings.autoJoinSpaceRooms, mx, setJoiningProgress]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,9 @@ import {
|
||||
SPACE_ROOM_PATH,
|
||||
SPACE_SEARCH_PATH,
|
||||
} from '../pages/paths';
|
||||
import { ScreenSize } from './useScreenSize';
|
||||
import { ScreenSize, useScreenSizeContext } from './useScreenSize';
|
||||
import { useNavigateWithTransition } from './useViewTransitions';
|
||||
import { useMatrixClientOptionally } from './useMatrixClient';
|
||||
import { useScreenSizeContext } from './useScreenSize';
|
||||
import { getCanonicalAliasOrRoomId, getCanonicalAliasRoomId, isRoomAlias } from '../utils/matrix';
|
||||
|
||||
type BackRouteContext = {
|
||||
@@ -73,7 +72,10 @@ export const getBackRouteTarget = ({
|
||||
return listPath;
|
||||
}
|
||||
|
||||
const atLobby = matchPath({ path: SPACE_LOBBY_PATH, caseSensitive: true, end: false }, pathname);
|
||||
const atLobby = matchPath(
|
||||
{ path: SPACE_LOBBY_PATH, caseSensitive: true, end: false },
|
||||
pathname,
|
||||
);
|
||||
if (atLobby) {
|
||||
return listPath;
|
||||
}
|
||||
@@ -83,7 +85,10 @@ export const getBackRouteTarget = ({
|
||||
return listPath;
|
||||
}
|
||||
|
||||
const atSearch = matchPath({ path: SPACE_SEARCH_PATH, caseSensitive: true, end: false }, pathname);
|
||||
const atSearch = matchPath(
|
||||
{ path: SPACE_SEARCH_PATH, caseSensitive: true, end: false },
|
||||
pathname,
|
||||
);
|
||||
if (atSearch) {
|
||||
return listPath;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type CategoryAction =
|
||||
};
|
||||
export const useCategoryHandler = (
|
||||
setAtom: (action: CategoryAction) => void,
|
||||
closed: (categoryId: string) => boolean
|
||||
closed: (categoryId: string) => boolean,
|
||||
) => {
|
||||
const handleCategoryClick: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
const categoryId = evt.currentTarget.getAttribute('data-category-id');
|
||||
|
||||
@@ -231,7 +231,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
exe: async (payload) => {
|
||||
const rawIds = splitWithSpace(payload);
|
||||
const roomIdOrAliases = rawIds.filter(
|
||||
(idOrAlias) => isRoomId(idOrAlias) || isRoomAlias(idOrAlias)
|
||||
(idOrAlias) => isRoomId(idOrAlias) || isRoomAlias(idOrAlias),
|
||||
);
|
||||
roomIdOrAliases.forEach(async (idOrAlias) => {
|
||||
await mx.joinRoom(idOrAlias);
|
||||
@@ -372,7 +372,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
...content,
|
||||
displayname: nick,
|
||||
},
|
||||
mx.getSafeUserId()
|
||||
mx.getSafeUserId(),
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -394,7 +394,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
...content,
|
||||
avatar_url: payload,
|
||||
},
|
||||
mx.getSafeUserId()
|
||||
mx.getSafeUserId(),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -445,7 +445,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
const startEventId = result.event_id;
|
||||
|
||||
const path = `/rooms/${encodeURIComponent(room.roomId)}/context/${encodeURIComponent(
|
||||
startEventId
|
||||
startEventId,
|
||||
)}`;
|
||||
const eventContext = await mx.http.authedRequest<IContextResponse>(Method.Get, path, {
|
||||
limit: 0,
|
||||
@@ -459,7 +459,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
token,
|
||||
20,
|
||||
Direction.Forward,
|
||||
undefined
|
||||
undefined,
|
||||
);
|
||||
const { end, chunk } = response;
|
||||
// remove until the latest event;
|
||||
@@ -469,14 +469,14 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
(roomEvent) =>
|
||||
(messageTypes.length > 0 ? messageTypes.includes(roomEvent.type) : true) &&
|
||||
users.includes(roomEvent.sender) &&
|
||||
roomEvent.unsigned?.redacted_because === undefined
|
||||
roomEvent.unsigned?.redacted_because === undefined,
|
||||
);
|
||||
|
||||
const eventIds = eventsToDelete.map((roomEvent) => roomEvent.event_id);
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await rateLimitedActions(eventIds, (eventId) =>
|
||||
mx.redactEvent(room.roomId, eventId, undefined, { reason })
|
||||
mx.redactEvent(room.roomId, eventId, undefined, { reason }),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -501,7 +501,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
|
||||
const serverAcl = getStateEvent(
|
||||
room,
|
||||
StateEvent.RoomServerAcl
|
||||
StateEvent.RoomServerAcl,
|
||||
)?.getContent<RoomServerAclEventContent>();
|
||||
|
||||
const aclContent: RoomServerAclEventContent = {
|
||||
@@ -520,10 +520,10 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
});
|
||||
|
||||
aclContent.allow = aclContent.allow?.filter(
|
||||
(servername) => !removeAllowList.includes(servername)
|
||||
(servername) => !removeAllowList.includes(servername),
|
||||
);
|
||||
aclContent.deny = aclContent.deny?.filter(
|
||||
(servername) => !removeDenyList.includes(servername)
|
||||
(servername) => !removeDenyList.includes(servername),
|
||||
);
|
||||
|
||||
aclContent.allow?.sort();
|
||||
@@ -533,7 +533,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
[mx, room, navigateRoom]
|
||||
[mx, room, navigateRoom],
|
||||
);
|
||||
|
||||
return commands;
|
||||
|
||||
@@ -13,7 +13,7 @@ export function useCompositionEndTracking(): void {
|
||||
(evt: TimeStamped) => {
|
||||
setLastCompositionEnd(evt.timeStamp);
|
||||
},
|
||||
[setLastCompositionEnd]
|
||||
[setLastCompositionEnd],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -42,6 +42,6 @@ export function useComposingCheck({
|
||||
(evt.keyCode === 229 &&
|
||||
typeof compositionEnd !== 'undefined' &&
|
||||
evt.timeStamp - compositionEnd < compositionEndThreshold),
|
||||
[compositionEndThreshold, compositionEnd]
|
||||
[compositionEndThreshold, compositionEnd],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ export const useDateFormatItems = (): DateFormatItem[] =>
|
||||
name: 'Custom',
|
||||
},
|
||||
],
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ export type DebounceCallback<T extends unknown[]> = (...args: T) => void;
|
||||
|
||||
export function useDebounce<T extends unknown[]>(
|
||||
callback: DebounceCallback<T>,
|
||||
options?: DebounceOptions
|
||||
options?: DebounceOptions,
|
||||
): DebounceCallback<T> {
|
||||
const timeoutIdRef = useRef<number>();
|
||||
const { wait, immediate } = options ?? {};
|
||||
@@ -27,7 +27,7 @@ export function useDebounce<T extends unknown[]>(
|
||||
timeoutIdRef.current = undefined;
|
||||
}, wait);
|
||||
},
|
||||
[callback, wait, immediate]
|
||||
[callback, wait, immediate],
|
||||
);
|
||||
|
||||
return debounceCallback;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CryptoEvent, CryptoEventHandlerMap } from 'matrix-js-sdk/lib/crypto-api
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useDeviceListChange = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.DevicesUpdated]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.DevicesUpdated],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
useEffect(() => {
|
||||
@@ -46,8 +46,8 @@ export function useDeviceList(): [undefined | IMyDevice[], () => Promise<void>]
|
||||
refreshDeviceList();
|
||||
}
|
||||
},
|
||||
[mx, refreshDeviceList]
|
||||
)
|
||||
[mx, refreshDeviceList],
|
||||
),
|
||||
);
|
||||
|
||||
return [deviceList ?? undefined, refreshDeviceList];
|
||||
@@ -60,17 +60,17 @@ export const useDeviceIds = (devices: IMyDevice[] | undefined): string[] => {
|
||||
};
|
||||
|
||||
export const useSplitCurrentDevice = (
|
||||
devices: IMyDevice[] | undefined
|
||||
devices: IMyDevice[] | undefined,
|
||||
): [IMyDevice | undefined, IMyDevice[] | undefined] => {
|
||||
const mx = useMatrixClient();
|
||||
const currentDeviceId = mx.getDeviceId();
|
||||
const currentDevice = useMemo(
|
||||
() => devices?.find((d) => d.device_id === currentDeviceId),
|
||||
[devices, currentDeviceId]
|
||||
[devices, currentDeviceId],
|
||||
);
|
||||
const otherDevices = useMemo(
|
||||
() => devices?.filter((device) => device.device_id !== currentDeviceId),
|
||||
[devices, currentDeviceId]
|
||||
[devices, currentDeviceId],
|
||||
);
|
||||
|
||||
return [currentDevice, otherDevices];
|
||||
|
||||
@@ -17,7 +17,7 @@ export const useDeviceVerificationDetect = (
|
||||
crypto: CryptoApi | undefined,
|
||||
userId: string,
|
||||
deviceId: string | undefined,
|
||||
callback: (status: VerificationStatus) => void
|
||||
callback: (status: VerificationStatus) => void,
|
||||
): void => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -45,15 +45,15 @@ export const useDeviceVerificationDetect = (
|
||||
updateStatus();
|
||||
}
|
||||
},
|
||||
[userId, updateStatus]
|
||||
)
|
||||
[userId, updateStatus],
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
export const useDeviceVerificationStatus = (
|
||||
crypto: CryptoApi | undefined,
|
||||
userId: string,
|
||||
deviceId: string | undefined
|
||||
deviceId: string | undefined,
|
||||
): VerificationStatus => {
|
||||
const [verificationStatus, setVerificationStatus] = useState(VerificationStatus.Unknown);
|
||||
|
||||
@@ -65,7 +65,7 @@ export const useDeviceVerificationStatus = (
|
||||
export const useUnverifiedDeviceCount = (
|
||||
crypto: CryptoApi | undefined,
|
||||
userId: string,
|
||||
devices: string[]
|
||||
devices: string[],
|
||||
): number | undefined => {
|
||||
const [unverifiedCount, setUnverifiedCount] = useState<number>();
|
||||
const alive = useAlive();
|
||||
@@ -94,8 +94,8 @@ export const useUnverifiedDeviceCount = (
|
||||
updateCount();
|
||||
}
|
||||
},
|
||||
[userId, updateCount]
|
||||
)
|
||||
[userId, updateCount],
|
||||
),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { getResizeObserverEntry, useResizeObserver } from './useResizeObserver';
|
||||
|
||||
export const useElementSizeObserver = <T extends Element>(
|
||||
element: () => T | null,
|
||||
onResize: (width: number, height: number, element: T) => void
|
||||
onResize: (width: number, height: number, element: T) => void,
|
||||
) => {
|
||||
useResizeObserver(
|
||||
useCallback(
|
||||
@@ -16,8 +16,8 @@ export const useElementSizeObserver = <T extends Element>(
|
||||
onResize(clientWidth, clientHeight, target);
|
||||
}
|
||||
},
|
||||
[element, onResize]
|
||||
[element, onResize],
|
||||
),
|
||||
element
|
||||
element,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ type EmailNotificationResult = {
|
||||
|
||||
export const useEmailNotifications = (): [
|
||||
EmailNotificationResult | undefined | null,
|
||||
RefreshHandler
|
||||
RefreshHandler,
|
||||
] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -26,7 +26,7 @@ export const useEmailNotifications = (): [
|
||||
|
||||
const pushers = (await mx.getPushers())?.pushers;
|
||||
const emailPusher = pushers.find(
|
||||
(pusher) => pusher.app_id === 'm.email' && emailAddresses.includes(pusher.pushkey)
|
||||
(pusher) => pusher.app_id === 'm.email' && emailAddresses.includes(pusher.pushkey),
|
||||
);
|
||||
|
||||
if (emailPusher?.pushkey) {
|
||||
@@ -40,7 +40,7 @@ export const useEmailNotifications = (): [
|
||||
enabled: false,
|
||||
email: emailAddresses[0],
|
||||
};
|
||||
}, [mx])
|
||||
}, [mx]),
|
||||
);
|
||||
|
||||
if (emailState.status === AsyncStatus.Success) {
|
||||
|
||||
@@ -54,7 +54,7 @@ export function useEmojiUsage() {
|
||||
await mx.setAccountData(PAARROT_EMOJI_USAGE_EVENT, currentUsage);
|
||||
}
|
||||
},
|
||||
[mx, emojiUsage]
|
||||
[mx, emojiUsage],
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ export function useEmojiUsage() {
|
||||
});
|
||||
return entries.slice(0, count).map(([shortcode]) => shortcode);
|
||||
},
|
||||
[emojiUsage]
|
||||
[emojiUsage],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -7,12 +7,12 @@ export const useFileDropHandler = (onDrop: (file: File[]) => void): DragEventHan
|
||||
const files = getDataTransferFiles(evt.dataTransfer);
|
||||
if (files) onDrop(files);
|
||||
},
|
||||
[onDrop]
|
||||
[onDrop],
|
||||
);
|
||||
|
||||
export const useFileDropZone = (
|
||||
zoneRef: RefObject<HTMLElement> | undefined,
|
||||
onDrop: (file: File[]) => void
|
||||
onDrop: (file: File[]) => void,
|
||||
): boolean => {
|
||||
const dragStateRef = useRef<'start' | 'leave' | 'over'>();
|
||||
const [active, setActive] = useState(false);
|
||||
|
||||
@@ -29,5 +29,5 @@ export const useFilePasteHandler = (onPaste: (file: File[]) => void): ClipboardE
|
||||
if (clipboardImage) onPaste([clipboardImage]);
|
||||
});
|
||||
},
|
||||
[onPaste]
|
||||
[onPaste],
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { selectFile } from '../utils/dom';
|
||||
|
||||
export const useFilePicker = <M extends boolean | undefined = undefined>(
|
||||
onSelect: (file: M extends true ? File[] : File) => void,
|
||||
multiple?: M
|
||||
multiple?: M,
|
||||
) =>
|
||||
useCallback(
|
||||
async (accept: string) => {
|
||||
@@ -11,5 +11,5 @@ export const useFilePicker = <M extends boolean | undefined = undefined>(
|
||||
if (!file) return;
|
||||
onSelect(file);
|
||||
},
|
||||
[multiple, onSelect]
|
||||
[multiple, onSelect],
|
||||
);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { useState } from 'react';
|
||||
|
||||
export function useForceUpdate() {
|
||||
const [data, setData] = useState(null);
|
||||
|
||||
return [data, function forceUpdateHook() {
|
||||
setData({});
|
||||
}];
|
||||
return [
|
||||
data,
|
||||
function forceUpdateHook() {
|
||||
setData({});
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export const useGetRoom = (rooms: Set<string>): GetRoomCallback => {
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
[mx, rooms]
|
||||
[mx, rooms],
|
||||
);
|
||||
|
||||
return getRoom;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useImagePackRooms = (
|
||||
roomId: string,
|
||||
roomToParents: Map<string, Set<string>>
|
||||
roomToParents: Map<string, Set<string>>,
|
||||
): Room[] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ export const useUserImagePack = (): ImagePack | undefined => {
|
||||
setUserPack(getUserImagePack(mx));
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
[mx],
|
||||
),
|
||||
);
|
||||
|
||||
return userPack;
|
||||
@@ -45,8 +45,8 @@ export const useGlobalImagePacks = (): ImagePack[] => {
|
||||
setGlobalPacks(getGlobalImagePacks(mx));
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
[mx],
|
||||
),
|
||||
);
|
||||
|
||||
useStateEventCallback(
|
||||
@@ -59,15 +59,15 @@ export const useGlobalImagePacks = (): ImagePack[] => {
|
||||
if (eventType === StateEvent.PoniesRoomEmotes && roomId && typeof stateKey === 'string') {
|
||||
const global = !!globalPacks.find(
|
||||
(pack) =>
|
||||
pack.address && pack.address.roomId === roomId && pack.address.stateKey === stateKey
|
||||
pack.address && pack.address.roomId === roomId && pack.address.stateKey === stateKey,
|
||||
);
|
||||
if (global) {
|
||||
setGlobalPacks(getGlobalImagePacks(mx));
|
||||
}
|
||||
}
|
||||
},
|
||||
[mx, globalPacks]
|
||||
)
|
||||
[mx, globalPacks],
|
||||
),
|
||||
);
|
||||
|
||||
return globalPacks;
|
||||
@@ -89,8 +89,8 @@ export const useRoomImagePack = (room: Room, stateKey: string): ImagePack | unde
|
||||
setRoomPack(getRoomImagePack(room, stateKey));
|
||||
}
|
||||
},
|
||||
[room, stateKey]
|
||||
)
|
||||
[room, stateKey],
|
||||
),
|
||||
);
|
||||
|
||||
return roomPack;
|
||||
@@ -111,8 +111,8 @@ export const useRoomImagePacks = (room: Room): ImagePack[] => {
|
||||
setRoomPacks(getRoomImagePacks(room));
|
||||
}
|
||||
},
|
||||
[room]
|
||||
)
|
||||
[room],
|
||||
),
|
||||
);
|
||||
|
||||
return roomPacks;
|
||||
@@ -133,8 +133,8 @@ export const useRoomsImagePacks = (rooms: Room[]) => {
|
||||
setRoomPacks(rooms.flatMap(getRoomImagePacks));
|
||||
}
|
||||
},
|
||||
[rooms]
|
||||
)
|
||||
[rooms],
|
||||
),
|
||||
);
|
||||
|
||||
return roomPacks;
|
||||
@@ -151,7 +151,7 @@ export const useRelevantImagePacks = (usage: ImageUsage, rooms: Room[]): ImagePa
|
||||
|
||||
const relPacks = packs.concat(
|
||||
globalPacks,
|
||||
roomsPacks.filter((pack) => !globalPackIds.has(pack.id))
|
||||
roomsPacks.filter((pack) => !globalPackIds.has(pack.id)),
|
||||
);
|
||||
|
||||
return relPacks.filter((pack) => pack.getImages(usage).length > 0);
|
||||
|
||||
@@ -67,12 +67,9 @@ const DEFAULT_OPTIONS: Required<UseInertialHorizontalScrollOptions> = {
|
||||
* Shared hook for drag-scrolling horizontal overflow areas with inertial momentum.
|
||||
*/
|
||||
export function useInertialHorizontalScroll(
|
||||
options: UseInertialHorizontalScrollOptions = {}
|
||||
options: UseInertialHorizontalScrollOptions = {},
|
||||
): UseInertialHorizontalScrollResult {
|
||||
const resolvedOptions = useMemo(
|
||||
() => ({ ...DEFAULT_OPTIONS, ...options }),
|
||||
[options]
|
||||
);
|
||||
const resolvedOptions = useMemo(() => ({ ...DEFAULT_OPTIONS, ...options }), [options]);
|
||||
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const stateRef = useRef<ScrollState>({
|
||||
@@ -134,23 +131,26 @@ export function useInertialHorizontalScroll(
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
}
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
const scrollByStep = useCallback((direction: 1 | -1) => {
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
const scrollByStep = useCallback(
|
||||
(direction: 1 | -1) => {
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
const currentPrimary = isHorizontal ? scroll.scrollLeft : scroll.scrollTop;
|
||||
const offsetSize = isHorizontal ? scroll.offsetWidth : scroll.offsetHeight;
|
||||
scroll.scrollTo({
|
||||
...(isHorizontal
|
||||
? { left: currentPrimary + offsetSize / resolvedOptions.scrollStepRatio * direction }
|
||||
: { top: currentPrimary + offsetSize / resolvedOptions.scrollStepRatio * direction }),
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}, [resolvedOptions.axis, resolvedOptions.scrollStepRatio]);
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
const currentPrimary = isHorizontal ? scroll.scrollLeft : scroll.scrollTop;
|
||||
const offsetSize = isHorizontal ? scroll.offsetWidth : scroll.offsetHeight;
|
||||
scroll.scrollTo({
|
||||
...(isHorizontal
|
||||
? { left: currentPrimary + (offsetSize / resolvedOptions.scrollStepRatio) * direction }
|
||||
: { top: currentPrimary + (offsetSize / resolvedOptions.scrollStepRatio) * direction }),
|
||||
behavior: 'smooth',
|
||||
});
|
||||
},
|
||||
[resolvedOptions.axis, resolvedOptions.scrollStepRatio],
|
||||
);
|
||||
|
||||
const stopInertia = useCallback(() => {
|
||||
const state = stateRef.current;
|
||||
@@ -193,133 +193,162 @@ export function useInertialHorizontalScroll(
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.velocity *= Math.pow(resolvedOptions.friction, deltaMs / 16.6667);
|
||||
currentState.animationFrameId = requestAnimationFrame((nextTimestamp) => step(nextTimestamp, timestamp));
|
||||
currentState.velocity *= resolvedOptions.friction ** (deltaMs / 16.6667);
|
||||
currentState.animationFrameId = requestAnimationFrame((nextTimestamp) =>
|
||||
step(nextTimestamp, timestamp),
|
||||
);
|
||||
};
|
||||
|
||||
stopInertia();
|
||||
state.animationFrameId = requestAnimationFrame((timestamp) => step(timestamp, timestamp));
|
||||
}, [resolvedOptions.axis, resolvedOptions.friction, resolvedOptions.minVelocity, stopInertia, updateScrollState]);
|
||||
}, [
|
||||
resolvedOptions.axis,
|
||||
resolvedOptions.friction,
|
||||
resolvedOptions.minVelocity,
|
||||
stopInertia,
|
||||
updateScrollState,
|
||||
]);
|
||||
|
||||
const endDrag = useCallback((pointerId: number | null) => {
|
||||
const state = stateRef.current;
|
||||
if (!state.dragging) return;
|
||||
const endDrag = useCallback(
|
||||
(pointerId: number | null) => {
|
||||
const state = stateRef.current;
|
||||
if (!state.dragging) return;
|
||||
|
||||
const scroll = scrollRef.current;
|
||||
if (scroll && pointerId !== null && scroll.hasPointerCapture(pointerId)) {
|
||||
scroll.releasePointerCapture(pointerId);
|
||||
}
|
||||
const scroll = scrollRef.current;
|
||||
if (scroll && pointerId !== null && scroll.hasPointerCapture(pointerId)) {
|
||||
scroll.releasePointerCapture(pointerId);
|
||||
}
|
||||
|
||||
if (state.moved) {
|
||||
state.suppressClick = true;
|
||||
startInertia();
|
||||
}
|
||||
if (state.moved) {
|
||||
state.suppressClick = true;
|
||||
startInertia();
|
||||
}
|
||||
|
||||
state.dragging = false;
|
||||
state.activePointerId = null;
|
||||
state.moved = false;
|
||||
state.velocity = 0;
|
||||
setIsDragging(false);
|
||||
}, [startInertia]);
|
||||
state.dragging = false;
|
||||
state.activePointerId = null;
|
||||
state.moved = false;
|
||||
state.velocity = 0;
|
||||
setIsDragging(false);
|
||||
},
|
||||
[startInertia],
|
||||
);
|
||||
|
||||
const processPointerMove = useCallback((evt: PointerLikeEvent) => {
|
||||
const state = stateRef.current;
|
||||
if (!state.dragging || state.activePointerId !== evt.pointerId) {
|
||||
return;
|
||||
}
|
||||
const processPointerMove = useCallback(
|
||||
(evt: PointerLikeEvent) => {
|
||||
const state = stateRef.current;
|
||||
if (!state.dragging || state.activePointerId !== evt.pointerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
|
||||
const currentPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
const deltaPrimary = currentPrimary - state.startPrimary;
|
||||
const now = evt.timeStamp;
|
||||
const deltaTime = Math.max(now - state.lastTime, 1);
|
||||
const hasExceededThreshold = Math.abs(deltaPrimary) >= resolvedOptions.dragThreshold;
|
||||
const currentPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
const deltaPrimary = currentPrimary - state.startPrimary;
|
||||
const now = evt.timeStamp;
|
||||
const deltaTime = Math.max(now - state.lastTime, 1);
|
||||
const hasExceededThreshold = Math.abs(deltaPrimary) >= resolvedOptions.dragThreshold;
|
||||
|
||||
if (hasExceededThreshold) {
|
||||
state.moved = true;
|
||||
}
|
||||
if (hasExceededThreshold) {
|
||||
state.moved = true;
|
||||
}
|
||||
|
||||
if (!state.moved) {
|
||||
if (!state.moved) {
|
||||
state.lastPrimary = currentPrimary;
|
||||
state.lastTime = now;
|
||||
return;
|
||||
}
|
||||
|
||||
evt.preventDefault?.();
|
||||
|
||||
if (isHorizontal) {
|
||||
scroll.scrollLeft = state.startScrollPrimary - deltaPrimary;
|
||||
} else {
|
||||
scroll.scrollTop = state.startScrollPrimary - deltaPrimary;
|
||||
}
|
||||
|
||||
const rawVelocity = (currentPrimary - state.lastPrimary) / deltaTime;
|
||||
state.velocity = Math.max(Math.min(rawVelocity, 2), -2);
|
||||
state.lastPrimary = currentPrimary;
|
||||
state.lastTime = now;
|
||||
return;
|
||||
}
|
||||
},
|
||||
[resolvedOptions.axis, resolvedOptions.dragThreshold],
|
||||
);
|
||||
|
||||
evt.preventDefault?.();
|
||||
const handlePointerDown = useCallback(
|
||||
(evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (evt.button !== 0) return;
|
||||
if (!evt.isPrimary) return;
|
||||
|
||||
if (isHorizontal) {
|
||||
scroll.scrollLeft = state.startScrollPrimary - deltaPrimary;
|
||||
} else {
|
||||
scroll.scrollTop = state.startScrollPrimary - deltaPrimary;
|
||||
}
|
||||
const state = stateRef.current;
|
||||
if (state.dragging && state.activePointerId === evt.pointerId) return;
|
||||
|
||||
const rawVelocity = (currentPrimary - state.lastPrimary) / deltaTime;
|
||||
state.velocity = Math.max(Math.min(rawVelocity, 2), -2);
|
||||
state.lastPrimary = currentPrimary;
|
||||
state.lastTime = now;
|
||||
}, [resolvedOptions.axis, resolvedOptions.dragThreshold]);
|
||||
const { target } = evt;
|
||||
if (target instanceof Element && target.closest(TEXT_SELECTION_TARGET_SELECTOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handlePointerDown = useCallback((evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (evt.button !== 0) return;
|
||||
if (!evt.isPrimary) return;
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
|
||||
const state = stateRef.current;
|
||||
if (state.dragging && state.activePointerId === evt.pointerId) return;
|
||||
stopInertia();
|
||||
|
||||
const target = evt.target;
|
||||
if (target instanceof Element && target.closest(TEXT_SELECTION_TARGET_SELECTOR)) {
|
||||
return;
|
||||
}
|
||||
state.activePointerId = evt.pointerId;
|
||||
state.startPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
state.startScrollPrimary = isHorizontal ? scroll.scrollLeft : scroll.scrollTop;
|
||||
state.lastPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
state.lastTime = evt.timeStamp;
|
||||
state.velocity = 0;
|
||||
state.dragging = true;
|
||||
state.moved = false;
|
||||
state.suppressClick = false;
|
||||
|
||||
const scroll = scrollRef.current;
|
||||
if (!scroll) return;
|
||||
const isHorizontal = resolvedOptions.axis === 'x';
|
||||
try {
|
||||
scroll.setPointerCapture(evt.pointerId);
|
||||
} catch {
|
||||
// Ignore capture failures when browser has already ended pointer interaction.
|
||||
}
|
||||
|
||||
stopInertia();
|
||||
setIsDragging(true);
|
||||
},
|
||||
[resolvedOptions.axis, stopInertia],
|
||||
);
|
||||
|
||||
state.activePointerId = evt.pointerId;
|
||||
state.startPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
state.startScrollPrimary = isHorizontal ? scroll.scrollLeft : scroll.scrollTop;
|
||||
state.lastPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||
state.lastTime = evt.timeStamp;
|
||||
state.velocity = 0;
|
||||
state.dragging = true;
|
||||
state.moved = false;
|
||||
state.suppressClick = false;
|
||||
const handlePointerMove = useCallback(
|
||||
(evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
processPointerMove(evt);
|
||||
},
|
||||
[processPointerMove],
|
||||
);
|
||||
|
||||
try {
|
||||
scroll.setPointerCapture(evt.pointerId);
|
||||
} catch {
|
||||
// Ignore capture failures when browser has already ended pointer interaction.
|
||||
}
|
||||
const handlePointerUp = useCallback(
|
||||
(evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
},
|
||||
[endDrag],
|
||||
);
|
||||
|
||||
setIsDragging(true);
|
||||
}, [resolvedOptions.axis, stopInertia]);
|
||||
const handlePointerCancel = useCallback(
|
||||
(evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
},
|
||||
[endDrag],
|
||||
);
|
||||
|
||||
const handlePointerMove = useCallback((evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
processPointerMove(evt);
|
||||
}, [processPointerMove]);
|
||||
|
||||
const handlePointerUp = useCallback((evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
}, [endDrag]);
|
||||
|
||||
const handlePointerCancel = useCallback((evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
}, [endDrag]);
|
||||
|
||||
const handleLostPointerCapture = useCallback((evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
}, [endDrag]);
|
||||
const handleLostPointerCapture = useCallback(
|
||||
(evt: React.PointerEvent<HTMLDivElement>) => {
|
||||
const state = stateRef.current;
|
||||
if (state.activePointerId !== evt.pointerId) return;
|
||||
endDrag(evt.pointerId);
|
||||
},
|
||||
[endDrag],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleWindowPointerMove = (evt: PointerEvent) => {
|
||||
@@ -399,4 +428,4 @@ export function useInertialHorizontalScroll(
|
||||
onClickCapture: handleClickCapture,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ export type IntersectionObserverOpts = {
|
||||
|
||||
export const getIntersectionObserverEntry = (
|
||||
target: Element | Document,
|
||||
entries: IntersectionObserverEntry[]
|
||||
entries: IntersectionObserverEntry[],
|
||||
): IntersectionObserverEntry | undefined => entries.find((entry) => entry.target === target);
|
||||
|
||||
export const useIntersectionObserver = (
|
||||
onIntersectionCallback: OnIntersectionCallback,
|
||||
opts?: IntersectionObserverOpts | (() => IntersectionObserverOpts),
|
||||
observeElement?: Element | null | (() => Element | null)
|
||||
observeElement?: Element | null | (() => Element | null),
|
||||
): IntersectionObserver | undefined => {
|
||||
const [intersectionObserver, setIntersectionObserver] = useState<IntersectionObserver>();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export const useInterval = (callback: IntervalCallback, ms: number): number | un
|
||||
() => () => {
|
||||
window.clearInterval(id);
|
||||
},
|
||||
[id]
|
||||
[id],
|
||||
);
|
||||
|
||||
return id;
|
||||
|
||||
@@ -9,9 +9,7 @@ export const useJoinedRoomId = (allRooms: string[], roomIdOrAlias: string): stri
|
||||
|
||||
const joinedRoomId = useMemo(() => {
|
||||
const decoded = decodeRouteParam(roomIdOrAlias) ?? roomIdOrAlias;
|
||||
const roomId = isRoomAlias(decoded)
|
||||
? getCanonicalAliasRoomId(mx, decoded)
|
||||
: decoded;
|
||||
const roomId = isRoomAlias(decoded) ? getCanonicalAliasRoomId(mx, decoded) : decoded;
|
||||
|
||||
if (roomId && allRooms.includes(roomId)) return roomId;
|
||||
return undefined;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useMatrixClient } from './useMatrixClient';
|
||||
import { useAlive } from './useAlive';
|
||||
|
||||
export const useKeyBackupStatusChange = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupStatus]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupStatus],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -40,7 +40,7 @@ export const useKeyBackupStatus = (crypto: CryptoApi): boolean => {
|
||||
};
|
||||
|
||||
export const useKeyBackupSessionsRemainingChange = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupSessionsRemaining]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupSessionsRemaining],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -53,7 +53,7 @@ export const useKeyBackupSessionsRemainingChange = (
|
||||
};
|
||||
|
||||
export const useKeyBackupFailedChange = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupFailed]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupFailed],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -66,7 +66,7 @@ export const useKeyBackupFailedChange = (
|
||||
};
|
||||
|
||||
export const useKeyBackupDecryptionKeyCached = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupDecryptionKeyCached]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.KeyBackupDecryptionKeyCached],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -86,7 +86,7 @@ export const useKeyBackupSync = (): [number, string | undefined] => {
|
||||
useCallback((count) => {
|
||||
setRemaining(count);
|
||||
setFailure(undefined);
|
||||
}, [])
|
||||
}, []),
|
||||
);
|
||||
|
||||
useKeyBackupFailedChange(
|
||||
@@ -95,7 +95,7 @@ export const useKeyBackupSync = (): [number, string | undefined] => {
|
||||
setFailure(f);
|
||||
setRemaining(0);
|
||||
}
|
||||
}, [])
|
||||
}, []),
|
||||
);
|
||||
|
||||
return [remaining, failure];
|
||||
@@ -126,8 +126,8 @@ export const useKeyBackupInfo = (crypto: CryptoApi): KeyBackupInfo | undefined |
|
||||
fetchInfo();
|
||||
}
|
||||
},
|
||||
[fetchInfo]
|
||||
)
|
||||
[fetchInfo],
|
||||
),
|
||||
);
|
||||
|
||||
return info;
|
||||
@@ -135,7 +135,7 @@ export const useKeyBackupInfo = (crypto: CryptoApi): KeyBackupInfo | undefined |
|
||||
|
||||
export const useKeyBackupTrust = (
|
||||
crypto: CryptoApi,
|
||||
backupInfo: KeyBackupInfo
|
||||
backupInfo: KeyBackupInfo,
|
||||
): BackupTrustInfo | undefined => {
|
||||
const alive = useAlive();
|
||||
const [trust, setTrust] = useState<BackupTrustInfo>();
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useMarkAsRead(mx: MatrixClient) {
|
||||
// Then send the read receipt to the server
|
||||
await markAsRead(mx, roomId, privateReceipt);
|
||||
},
|
||||
[mx, setUnreadAtom]
|
||||
[mx, setUnreadAtom],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,6 @@ export function useMarkRoomsAsRead(mx: MatrixClient) {
|
||||
// Send read receipts to the server
|
||||
await Promise.all(roomIds.map((roomId) => markAsRead(mx, roomId, privateReceipt)));
|
||||
},
|
||||
[mx, setUnreadAtom]
|
||||
[mx, setUnreadAtom],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export const useMatrixEventRenderer =
|
||||
<T extends unknown[]>(
|
||||
typeToRenderer: EventRendererOpts<T>,
|
||||
renderStateEvent?: EventRenderer<T>,
|
||||
renderEvent?: EventRenderer<T>
|
||||
renderEvent?: EventRenderer<T>,
|
||||
): RenderMatrixEvent<T> =>
|
||||
(eventType, isStateEvent, ...args) => {
|
||||
const renderer = typeToRenderer[eventType];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IconSrc, Icons } from '../components/icons';
|
||||
import React, { ReactNode } from 'react';
|
||||
|
||||
import { MatrixEvent } from 'matrix-js-sdk';
|
||||
import { IconSrc, Icons } from '../components/icons';
|
||||
import { IMemberContent, Membership } from '../../types/matrix/room';
|
||||
import { getMxIdLocalPart } from '../utils/matrix';
|
||||
import { isMembershipChanged } from '../utils/room';
|
||||
|
||||
@@ -45,12 +45,12 @@ export const useMembershipFilterMenu = (): MembershipFilterItem[] =>
|
||||
filterFn: MembershipFilter.filterBanned,
|
||||
},
|
||||
],
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
export const useMembershipFilter = (
|
||||
index: number,
|
||||
membershipFilter: MembershipFilterItem[]
|
||||
membershipFilter: MembershipFilterItem[],
|
||||
): MembershipFilterItem => {
|
||||
const filter = membershipFilter[index] ?? membershipFilter[0];
|
||||
return filter;
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useMemberPowerCompare = (creators: Set<string>, powerLevels: IPower
|
||||
|
||||
return aPower > bPower;
|
||||
},
|
||||
[creators, powerLevels]
|
||||
[creators, powerLevels],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ export type GetMemberPowerTag = (userId: string) => MemberPowerTag;
|
||||
export const useGetMemberPowerTag = (
|
||||
room: Room,
|
||||
creators: Set<string>,
|
||||
powerLevels: IPowerLevels
|
||||
powerLevels: IPowerLevels,
|
||||
) => {
|
||||
const creatorsTag = useRoomCreatorsTag();
|
||||
const powerLevelTags = usePowerLevelTags(room, powerLevels);
|
||||
@@ -26,7 +26,7 @@ export const useGetMemberPowerTag = (
|
||||
const power = readPowerLevel.user(powerLevels, userId);
|
||||
return getPowerLevelTag(powerLevelTags, power);
|
||||
},
|
||||
[creators, creatorsTag, powerLevels, powerLevelTags]
|
||||
[creators, creatorsTag, powerLevels, powerLevelTags],
|
||||
);
|
||||
|
||||
return getMemberPowerTag;
|
||||
@@ -35,16 +35,16 @@ export const useGetMemberPowerTag = (
|
||||
export const getPowerTagIconSrc = (
|
||||
mx: MatrixClient,
|
||||
useAuthentication: boolean,
|
||||
icon: MemberPowerTagIcon
|
||||
icon: MemberPowerTagIcon,
|
||||
): string | undefined =>
|
||||
icon?.key?.startsWith('mxc://')
|
||||
? mx.mxcUrlToHttp(icon.key, 96, 96, 'scale', undefined, undefined, useAuthentication) ?? '🌻'
|
||||
? (mx.mxcUrlToHttp(icon.key, 96, 96, 'scale', undefined, undefined, useAuthentication) ?? '🌻')
|
||||
: icon?.key;
|
||||
|
||||
export const useAccessiblePowerTagColors = (
|
||||
themeKind: ThemeKind,
|
||||
creatorsTag: MemberPowerTag,
|
||||
powerLevelTags: PowerLevelTags
|
||||
powerLevelTags: PowerLevelTags,
|
||||
): Map<string, string> => {
|
||||
const accessibleColors: Map<string, string> = useMemo(() => {
|
||||
const colors: Map<string, string> = new Map();
|
||||
@@ -67,7 +67,7 @@ export const useAccessiblePowerTagColors = (
|
||||
|
||||
export const useFlattenPowerTagMembers = (
|
||||
members: RoomMember[],
|
||||
getTag: GetMemberPowerTag
|
||||
getTag: GetMemberPowerTag,
|
||||
): Array<MemberPowerTag | RoomMember> => {
|
||||
const PLTagOrRoomMember = useMemo(() => {
|
||||
let prevTag: MemberPowerTag | undefined;
|
||||
|
||||
@@ -39,7 +39,7 @@ export const useMemberSortMenu = (): MemberSortItem[] =>
|
||||
sortFn: MemberSort.Oldest,
|
||||
},
|
||||
],
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
export const useMemberSort = (index: number, memberSort: MemberSortItem[]): MemberSortItem => {
|
||||
@@ -49,7 +49,7 @@ export const useMemberSort = (index: number, memberSort: MemberSortItem[]): Memb
|
||||
|
||||
export const useMemberPowerSort = (
|
||||
creators: Set<string>,
|
||||
getPowerLevel: (userId: string) => number
|
||||
getPowerLevel: (userId: string) => number,
|
||||
): MemberSortFn => {
|
||||
const sort: MemberSortFn = useCallback(
|
||||
(a, b) => {
|
||||
@@ -61,7 +61,7 @@ export const useMemberPowerSort = (
|
||||
|
||||
return getPowerLevel(b.userId) - getPowerLevel(a.userId);
|
||||
},
|
||||
[creators]
|
||||
[creators],
|
||||
);
|
||||
|
||||
return sort;
|
||||
|
||||
@@ -6,13 +6,13 @@ export const useMembership = (room: Room, userId: string): Membership => {
|
||||
const member = room.getMember(userId);
|
||||
|
||||
const [membership, setMembership] = useState<Membership>(
|
||||
() => (member?.membership as Membership | undefined) ?? Membership.Leave
|
||||
() => (member?.membership as Membership | undefined) ?? Membership.Leave,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleMembershipChange: RoomMemberEventHandlerMap[RoomMemberEvent.Membership] = (
|
||||
event,
|
||||
m
|
||||
m,
|
||||
) => {
|
||||
if (event.getRoomId() === room.roomId && m.userId === userId) {
|
||||
setMembership((m.membership as Membership | undefined) ?? Membership.Leave);
|
||||
|
||||
@@ -40,7 +40,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
|
||||
|
||||
navigate(viaServers ? withSearchParam<_RoomSearchParams>(path, { viaServers }) : path);
|
||||
},
|
||||
[mx, navigate, navigateRoom, navigateSpace, roomId, space, openProfile]
|
||||
[mx, navigate, navigateRoom, navigateSpace, roomId, space, openProfile],
|
||||
);
|
||||
|
||||
return handleClick;
|
||||
|
||||
@@ -22,5 +22,5 @@ export const useMessageLayoutItems = (): MessageLayoutItem[] =>
|
||||
name: 'Bubble',
|
||||
},
|
||||
],
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -34,5 +34,5 @@ export const useMessageSpacingItems = (): MessageSpacingItem[] =>
|
||||
name: 'Large',
|
||||
},
|
||||
],
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -22,8 +22,8 @@ export const useMutualRooms = (userId: string): AsyncState<string[], unknown> =>
|
||||
const [mutualRoomsState] = useAsyncCallbackValue(
|
||||
useCallback(
|
||||
() => (supported ? mx._unstable_getSharedRooms(userId) : Promise.resolve([])),
|
||||
[mx, userId, supported]
|
||||
)
|
||||
[mx, userId, supported],
|
||||
),
|
||||
);
|
||||
|
||||
return mutualRoomsState;
|
||||
|
||||
@@ -9,10 +9,10 @@ export enum NotificationMode {
|
||||
|
||||
export const getNotificationMode = (actions: PushRuleAction[]): NotificationMode => {
|
||||
const soundTweak = actions.find(
|
||||
(action) => typeof action === 'object' && action.set_tweak === TweakName.Sound
|
||||
(action) => typeof action === 'object' && action.set_tweak === TweakName.Sound,
|
||||
);
|
||||
const notify = actions.find(
|
||||
(action) => typeof action === 'string' && action === PushRuleActionName.Notify
|
||||
(action) => typeof action === 'string' && action === PushRuleActionName.Notify,
|
||||
);
|
||||
|
||||
if (notify && soundTweak) return NotificationMode.NotifyLoud;
|
||||
@@ -26,7 +26,7 @@ export type NotificationModeOptions = {
|
||||
};
|
||||
export const getNotificationModeActions = (
|
||||
mode: NotificationMode,
|
||||
options?: NotificationModeOptions
|
||||
options?: NotificationModeOptions,
|
||||
): PushRuleAction[] => {
|
||||
if (mode === NotificationMode.OFF) return [];
|
||||
|
||||
@@ -51,11 +51,11 @@ export const getNotificationModeActions = (
|
||||
|
||||
export type GetNotificationModeCallback = (mode: NotificationMode) => PushRuleAction[];
|
||||
export const useNotificationModeActions = (
|
||||
options?: NotificationModeOptions
|
||||
options?: NotificationModeOptions,
|
||||
): GetNotificationModeCallback => {
|
||||
const getAction: GetNotificationModeCallback = useCallback(
|
||||
(mode) => getNotificationModeActions(mode, options),
|
||||
[options]
|
||||
[options],
|
||||
);
|
||||
|
||||
return getAction;
|
||||
|
||||
@@ -10,7 +10,7 @@ export const useObjectURL = (object?: Blob): string | undefined => {
|
||||
() => () => {
|
||||
if (url) URL.revokeObjectURL(url);
|
||||
},
|
||||
[url]
|
||||
[url],
|
||||
);
|
||||
|
||||
return url;
|
||||
|
||||
@@ -13,7 +13,7 @@ const INITIAL_PAN = {
|
||||
export const usePan = (active: boolean) => {
|
||||
const [pan, setPan] = useState<Pan>(INITIAL_PAN);
|
||||
const [cursor, setCursor] = useState<'grab' | 'grabbing' | 'initial'>(
|
||||
active ? 'grab' : 'initial'
|
||||
active ? 'grab' : 'initial',
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -3,8 +3,7 @@ import { ILoginFlow, IPasswordFlow, ISSOFlow, LoginFlow } from 'matrix-js-sdk/li
|
||||
|
||||
export const getSSOFlow = (loginFlows: LoginFlow[]): ISSOFlow | undefined =>
|
||||
loginFlows.find((flow) => flow.type === 'm.login.sso' || flow.type === 'm.login.cas') as
|
||||
| ISSOFlow
|
||||
| undefined;
|
||||
ISSOFlow | undefined;
|
||||
|
||||
export const getPasswordFlow = (loginFlows: LoginFlow[]): IPasswordFlow | undefined =>
|
||||
loginFlows.find((flow) => flow.type === 'm.login.password') as IPasswordFlow;
|
||||
@@ -25,7 +24,7 @@ export const useParsedLoginFlows = (loginFlows: LoginFlow[]) => {
|
||||
token: getTokenFlow(loginFlows),
|
||||
sso: getSSOFlow(loginFlows),
|
||||
}),
|
||||
[loginFlows]
|
||||
[loginFlows],
|
||||
);
|
||||
|
||||
return parsedFlow;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AsyncState, useAsyncCallback } from './useAsyncCallback';
|
||||
import { RequestEmailTokenCallback, RequestEmailTokenResponse } from './types';
|
||||
|
||||
export const usePasswordEmail = (
|
||||
mx: MatrixClient
|
||||
mx: MatrixClient,
|
||||
): [AsyncState<RequestEmailTokenResponse, MatrixError>, RequestEmailTokenCallback] => {
|
||||
const sendAttemptRef = useRef(1);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const usePasswordEmail = (
|
||||
result,
|
||||
};
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
const [passwordEmailState, passwordEmail] = useAsyncCallback<
|
||||
|
||||
@@ -109,7 +109,7 @@ export const usePowerLevelTags = (room: Room, powerLevels: IPowerLevels): PowerL
|
||||
|
||||
export const getPowerLevelTag = (
|
||||
powerLevelTags: PowerLevelTags,
|
||||
powerLevel: number
|
||||
powerLevel: number,
|
||||
): MemberPowerTag => {
|
||||
const tag: MemberPowerTag | undefined = powerLevelTags[powerLevel];
|
||||
return tag ?? generateFallbackTag(powerLevelTags, powerLevel);
|
||||
|
||||
@@ -69,7 +69,7 @@ export function usePowerLevels(room: Room): IPowerLevels {
|
||||
const powerLevelsEvent = useStateEvent(room, StateEvent.RoomPowerLevels);
|
||||
const powerLevels: IPowerLevels = useMemo(
|
||||
() => getPowersLevelFromMatrixEvent(powerLevelsEvent),
|
||||
[powerLevelsEvent]
|
||||
[powerLevelsEvent],
|
||||
);
|
||||
|
||||
return powerLevels;
|
||||
@@ -114,8 +114,8 @@ export const useRoomsPowerLevels = (rooms: Room[]): Map<string, IPowerLevels> =>
|
||||
setRoomToPowerLevels(getRoomsPowerLevels());
|
||||
}
|
||||
},
|
||||
[rooms, getRoomsPowerLevels]
|
||||
)
|
||||
[rooms, getRoomsPowerLevels],
|
||||
),
|
||||
);
|
||||
|
||||
return roomToPowerLevels;
|
||||
@@ -171,7 +171,7 @@ export const readPowerLevel: ReadPowerLevelAPI = {
|
||||
export const useGetMemberPowerLevel = (powerLevels: IPowerLevels) => {
|
||||
const callback = useCallback(
|
||||
(userId?: string): number => readPowerLevel.user(powerLevels, userId),
|
||||
[powerLevels]
|
||||
[powerLevels],
|
||||
);
|
||||
|
||||
return callback;
|
||||
@@ -209,7 +209,7 @@ export type PermissionLocation =
|
||||
|
||||
export const getPermissionPower = (
|
||||
powerLevels: IPowerLevels,
|
||||
location: PermissionLocation
|
||||
location: PermissionLocation,
|
||||
): number => {
|
||||
if ('user' in location) {
|
||||
return readPowerLevel.user(powerLevels, location.key);
|
||||
@@ -230,7 +230,7 @@ export const getPermissionPower = (
|
||||
export const applyPermissionPower = (
|
||||
powerLevels: IPowerLevels,
|
||||
location: PermissionLocation,
|
||||
power: number
|
||||
power: number,
|
||||
): IPowerLevels => {
|
||||
if ('user' in location) {
|
||||
if (typeof location.key === 'string') {
|
||||
|
||||
@@ -20,7 +20,7 @@ export const makePushRuleData = (
|
||||
conditions?: PushRuleCondition[],
|
||||
pattern?: string,
|
||||
enabled?: boolean,
|
||||
_default?: boolean
|
||||
_default?: boolean,
|
||||
): PushRuleData => ({
|
||||
kind,
|
||||
pushRule: {
|
||||
@@ -43,7 +43,7 @@ export const orderedPushRuleKinds: PushRuleKind[] = [
|
||||
|
||||
export const getPushRule = (
|
||||
pushRules: IPushRules,
|
||||
ruleId: RuleId | string
|
||||
ruleId: RuleId | string,
|
||||
): PushRuleData | undefined => {
|
||||
const { global } = pushRules;
|
||||
|
||||
@@ -67,5 +67,5 @@ export const getPushRule = (
|
||||
|
||||
export const usePushRule = (
|
||||
pushRules: IPushRules,
|
||||
ruleId: RuleId | string
|
||||
ruleId: RuleId | string,
|
||||
): PushRuleData | undefined => useMemo(() => getPushRule(pushRules, ruleId), [pushRules, ruleId]);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AsyncState, useAsyncCallback } from './useAsyncCallback';
|
||||
import { RequestEmailTokenCallback, RequestEmailTokenResponse } from './types';
|
||||
|
||||
export const useRegisterEmail = (
|
||||
mx: MatrixClient
|
||||
mx: MatrixClient,
|
||||
): [AsyncState<RequestEmailTokenResponse, MatrixError>, RequestEmailTokenCallback] => {
|
||||
const sendAttemptRef = useRef(1);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useRegisterEmail = (
|
||||
result,
|
||||
};
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
const [registerEmailState, registerEmail] = useAsyncCallback<
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RelationsEvent, type Relations } from 'matrix-js-sdk/lib/models/relatio
|
||||
|
||||
export const useRelations = <T>(
|
||||
relations: Relations,
|
||||
getRelations: (relations: Relations) => T
|
||||
getRelations: (relations: Relations) => T,
|
||||
) => {
|
||||
const [data, setData] = useState(() => getRelations(relations));
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ export type OnResizeCallback = (entries: ResizeObserverEntry[]) => void;
|
||||
|
||||
export const getResizeObserverEntry = (
|
||||
target: Element,
|
||||
entries: ResizeObserverEntry[]
|
||||
entries: ResizeObserverEntry[],
|
||||
): ResizeObserverEntry | undefined => entries.find((entry) => entry.target === target);
|
||||
|
||||
export const useResizeObserver = (
|
||||
onResizeCallback: OnResizeCallback,
|
||||
observeElement?: Element | null | (() => Element | null)
|
||||
observeElement?: Element | null | (() => Element | null),
|
||||
): ResizeObserver => {
|
||||
const resizeObserver = useMemo(() => new ResizeObserver(onResizeCallback), [onResizeCallback]);
|
||||
|
||||
|
||||
@@ -19,6 +19,6 @@ export const useRestoreBackupOnVerification = () => {
|
||||
setRestoreProgress(progress);
|
||||
},
|
||||
});
|
||||
}, [mx, setRestoreProgress])
|
||||
}, [mx, setRestoreProgress]),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getStateEvent } from '../utils/room';
|
||||
export const usePublishedAliases = (room: Room): [string | undefined, string[]] => {
|
||||
const aliasContent = useStateEvent(
|
||||
room,
|
||||
StateEvent.RoomCanonicalAlias
|
||||
StateEvent.RoomCanonicalAlias,
|
||||
)?.getContent<RoomCanonicalAliasEventContent>();
|
||||
|
||||
const canonicalAlias = aliasContent?.alias;
|
||||
@@ -38,7 +38,7 @@ export const useSetMainAlias = (room: Room): ((alias: string | undefined) => Pro
|
||||
async (alias: string | undefined) => {
|
||||
const content = getStateEvent(
|
||||
room,
|
||||
StateEvent.RoomCanonicalAlias
|
||||
StateEvent.RoomCanonicalAlias,
|
||||
)?.getContent<RoomCanonicalAliasEventContent>();
|
||||
|
||||
const altAliases: string[] = [];
|
||||
@@ -58,14 +58,14 @@ export const useSetMainAlias = (room: Room): ((alias: string | undefined) => Pro
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
},
|
||||
[mx, room]
|
||||
[mx, room],
|
||||
);
|
||||
|
||||
return mainAlias;
|
||||
};
|
||||
|
||||
export const usePublishUnpublishAliases = (
|
||||
room: Room
|
||||
room: Room,
|
||||
): {
|
||||
publishAliases: (aliases: string[]) => Promise<void>;
|
||||
unpublishAliases: (aliases: string[]) => Promise<void>;
|
||||
@@ -75,7 +75,7 @@ export const usePublishUnpublishAliases = (
|
||||
async (aliases: string[]) => {
|
||||
const content = getStateEvent(
|
||||
room,
|
||||
StateEvent.RoomCanonicalAlias
|
||||
StateEvent.RoomCanonicalAlias,
|
||||
)?.getContent<RoomCanonicalAliasEventContent>();
|
||||
const altAliases = content?.alt_aliases ?? [];
|
||||
|
||||
@@ -92,14 +92,14 @@ export const usePublishUnpublishAliases = (
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
},
|
||||
[mx, room]
|
||||
[mx, room],
|
||||
);
|
||||
|
||||
const unpublishAliases = useCallback(
|
||||
async (aliases: string[]) => {
|
||||
const content = getStateEvent(
|
||||
room,
|
||||
StateEvent.RoomCanonicalAlias
|
||||
StateEvent.RoomCanonicalAlias,
|
||||
)?.getContent<RoomCanonicalAliasEventContent>();
|
||||
const altAliases: string[] = [];
|
||||
|
||||
@@ -116,7 +116,7 @@ export const usePublishUnpublishAliases = (
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
},
|
||||
[mx, room]
|
||||
[mx, room],
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -126,7 +126,7 @@ export const usePublishUnpublishAliases = (
|
||||
};
|
||||
|
||||
export const useLocalAliases = (
|
||||
roomId: string
|
||||
roomId: string,
|
||||
): {
|
||||
localAliasesState: AsyncState<string[], MatrixError>;
|
||||
addLocalAlias: (alias: string) => Promise<void>;
|
||||
@@ -139,7 +139,7 @@ export const useLocalAliases = (
|
||||
useCallback(async () => {
|
||||
const content = await mx.getLocalAliases(roomId);
|
||||
return content.aliases;
|
||||
}, [mx, roomId])
|
||||
}, [mx, roomId]),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -151,7 +151,7 @@ export const useLocalAliases = (
|
||||
await mx.createAlias(alias, roomId);
|
||||
if (alive()) await loadAliases();
|
||||
},
|
||||
[mx, roomId, loadAliases, alive]
|
||||
[mx, roomId, loadAliases, alive],
|
||||
);
|
||||
|
||||
const removeLocalAlias = useCallback(
|
||||
@@ -159,7 +159,7 @@ export const useLocalAliases = (
|
||||
await mx.deleteAlias(alias);
|
||||
if (alive()) await loadAliases();
|
||||
},
|
||||
[mx, loadAliases, alive]
|
||||
[mx, loadAliases, alive],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -32,7 +32,7 @@ export const useRoomCreators = (room: Room): Set<string> => {
|
||||
|
||||
const creators = useMemo(
|
||||
() => (createEvent ? getRoomCreators(createEvent) : new Set<string>()),
|
||||
[createEvent]
|
||||
[createEvent],
|
||||
);
|
||||
|
||||
return creators;
|
||||
|
||||
@@ -10,7 +10,7 @@ export const useRoomDirectoryVisibility = (roomId: string) => {
|
||||
useCallback(async () => {
|
||||
const v = await mx.getRoomDirectoryVisibility(roomId);
|
||||
return v.visibility === Visibility.Public;
|
||||
}, [mx, roomId])
|
||||
}, [mx, roomId]),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -21,11 +21,11 @@ export const useRoomDirectoryVisibility = (roomId: string) => {
|
||||
async (visibility: boolean) => {
|
||||
await mx.setRoomDirectoryVisibility(
|
||||
roomId,
|
||||
visibility ? Visibility.Public : Visibility.Private
|
||||
visibility ? Visibility.Public : Visibility.Private,
|
||||
);
|
||||
await loadVisibility();
|
||||
},
|
||||
[mx, roomId, loadVisibility]
|
||||
[mx, roomId, loadVisibility],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -51,11 +51,11 @@ const getPersonalEmbedFiltersFromRoom = (room: Room): EmbedFiltersContent => {
|
||||
* @returns A tuple of [filters, setFilters]
|
||||
*/
|
||||
export const useRoomEmbedFilters = (
|
||||
room: Room
|
||||
room: Room,
|
||||
): [EmbedFiltersContent, (filters: EmbedFiltersContent) => Promise<void>] => {
|
||||
const mx = useMatrixClient();
|
||||
const [filters, setFiltersState] = useState<EmbedFiltersContent>(() =>
|
||||
getPersonalEmbedFiltersFromRoom(room)
|
||||
getPersonalEmbedFiltersFromRoom(room),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -75,7 +75,7 @@ export const useRoomEmbedFilters = (
|
||||
async (newFilters: EmbedFiltersContent): Promise<void> => {
|
||||
await mx.setRoomAccountData(room.roomId, EMBED_FILTERS_ACCOUNT_DATA_TYPE, newFilters);
|
||||
},
|
||||
[mx, room.roomId]
|
||||
[mx, room.roomId],
|
||||
);
|
||||
|
||||
return [filters, setFilters];
|
||||
@@ -106,7 +106,7 @@ export const useRoomWideEmbedFilters = (room: Room): EmbedFiltersContent => {
|
||||
* @returns Function to save room-wide filters
|
||||
*/
|
||||
export const useSetRoomWideEmbedFilters = (
|
||||
room: Room
|
||||
room: Room,
|
||||
): ((filters: EmbedFiltersContent) => Promise<void>) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -115,7 +115,7 @@ export const useSetRoomWideEmbedFilters = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomEmbedFilters as any, newFilters);
|
||||
},
|
||||
[mx, room.roomId]
|
||||
[mx, room.roomId],
|
||||
);
|
||||
|
||||
return setFilters;
|
||||
@@ -129,7 +129,7 @@ export const useSetRoomWideEmbedFilters = (
|
||||
*/
|
||||
export const combineEmbedFilters = (
|
||||
personalFilters: EmbedFiltersContent,
|
||||
roomWideFilters: EmbedFiltersContent
|
||||
roomWideFilters: EmbedFiltersContent,
|
||||
): string[] => {
|
||||
const combined = new Set<string>([
|
||||
...personalFilters.disabledPatterns,
|
||||
|
||||
@@ -37,7 +37,7 @@ const useFetchEvent = (room: Room, eventId: string) => {
|
||||
export const useRoomEvent = (
|
||||
room: Room,
|
||||
eventId: string,
|
||||
getLocally?: () => MatrixEvent | undefined
|
||||
getLocally?: () => MatrixEvent | undefined,
|
||||
) => {
|
||||
const event = useMemo(() => {
|
||||
if (getLocally) return getLocally();
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useRoomEventReaders = (room: Room, eventId?: string): string[] => {
|
||||
const handleLocalEcho: RoomEventHandlerMap[RoomEvent.LocalEchoUpdated] = (
|
||||
event,
|
||||
r,
|
||||
oldEventId
|
||||
oldEventId,
|
||||
) => {
|
||||
// update members on local event id replaced
|
||||
// with server generated id
|
||||
|
||||
@@ -5,7 +5,7 @@ import { MatrixClient, MatrixEvent, Room, RoomEvent, IRoomTimelineData } from 'm
|
||||
* Hook that tracks timeline events across all rooms to trigger re-sorting of room lists.
|
||||
* Returns a counter that increments whenever a message is sent or received in any room.
|
||||
* This can be used as a dependency in useMemo to trigger re-sorting of room lists.
|
||||
*
|
||||
*
|
||||
* @param mx - The Matrix client instance
|
||||
* @param roomIds - Optional array of room IDs to track. If not provided, tracks all rooms.
|
||||
* @returns A number that increments on each timeline event
|
||||
@@ -19,18 +19,18 @@ export const useRoomListReorder = (mx: MatrixClient, roomIds?: string[]): number
|
||||
room: Room | undefined,
|
||||
toStartOfTimeline: boolean | undefined,
|
||||
removed: boolean,
|
||||
data: IRoomTimelineData
|
||||
data: IRoomTimelineData,
|
||||
) => {
|
||||
if (!room || !data.liveEvent) return;
|
||||
if (toStartOfTimeline) return;
|
||||
|
||||
|
||||
if (roomIds && !roomIds.includes(room.roomId)) return;
|
||||
|
||||
|
||||
setUpdateCounter((prev) => prev + 1);
|
||||
};
|
||||
|
||||
mx.on(RoomEvent.Timeline, handleTimelineEvent);
|
||||
|
||||
|
||||
return () => {
|
||||
mx.removeListener(RoomEvent.Timeline, handleTimelineEvent);
|
||||
};
|
||||
@@ -42,12 +42,12 @@ export const useRoomListReorder = (mx: MatrixClient, roomIds?: string[]): number
|
||||
/**
|
||||
* Hook that implements FLIP (First, Last, Invert, Play) animation for list reordering.
|
||||
* Tracks element positions before and after reorder, then animates the difference.
|
||||
*
|
||||
*
|
||||
* @param items - Array of item IDs in their current order
|
||||
* @returns Ref callback to attach to the list container
|
||||
*/
|
||||
export const useListReorderAnimation = <T extends string>(
|
||||
items: T[]
|
||||
items: T[],
|
||||
): React.RefCallback<HTMLElement> => {
|
||||
const positionsRef = useRef<Map<T, number>>(new Map());
|
||||
const containerRef = useRef<HTMLElement | null>(null);
|
||||
@@ -59,7 +59,9 @@ export const useListReorderAnimation = <T extends string>(
|
||||
const elements = new Map<T, HTMLElement>();
|
||||
|
||||
items.forEach((itemId) => {
|
||||
const element = containerRef.current!.querySelector(`[data-room-id="${itemId}"]`) as HTMLElement;
|
||||
const element = containerRef.current!.querySelector(
|
||||
`[data-room-id="${itemId}"]`,
|
||||
) as HTMLElement;
|
||||
if (element) {
|
||||
currentPositions.set(itemId, element.offsetTop);
|
||||
elements.set(itemId, element);
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import to from 'await-to-js';
|
||||
import {
|
||||
Direction,
|
||||
IRoomEvent,
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
RelationType,
|
||||
Room,
|
||||
} from 'matrix-js-sdk';
|
||||
import { Direction, IRoomEvent, MatrixEvent, MsgType, RelationType, Room } from 'matrix-js-sdk';
|
||||
import { CryptoBackend } from 'matrix-js-sdk/lib/common-crypto/CryptoBackend';
|
||||
import { EncryptedAttachmentInfo } from 'browser-encrypt-attachment';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
@@ -63,7 +56,7 @@ const toMediaItem = (mEvent: MatrixEvent): RoomMediaItem | undefined => {
|
||||
if (relation?.rel_type === RelationType.Replace) return undefined;
|
||||
|
||||
const content = mEvent.getContent();
|
||||
const msgtype = content.msgtype;
|
||||
const { msgtype } = content;
|
||||
if (msgtype !== MsgType.Image && msgtype !== MsgType.Video) return undefined;
|
||||
|
||||
const file = content.file as IEncryptedFile | undefined;
|
||||
@@ -118,7 +111,7 @@ const toMediaItem = (mEvent: MatrixEvent): RoomMediaItem | undefined => {
|
||||
*/
|
||||
export const useRoomMediaEvents = (room: Room) => {
|
||||
const mx = useMatrixClient();
|
||||
const roomId = room.roomId;
|
||||
const { roomId } = room;
|
||||
const cacheRef = useRef(getOrCreateCache(roomId));
|
||||
if (cacheRef.current !== mediaCache.get(roomId)) {
|
||||
cacheRef.current = getOrCreateCache(roomId);
|
||||
@@ -137,7 +130,7 @@ export const useRoomMediaEvents = (room: Room) => {
|
||||
}
|
||||
return mEvent;
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
const fetchPages = useCallback(async () => {
|
||||
@@ -149,7 +142,7 @@ export const useRoomMediaEvents = (room: Room) => {
|
||||
roomId,
|
||||
cache.nextToken,
|
||||
PAGE_SIZE,
|
||||
Direction.Backward
|
||||
Direction.Backward,
|
||||
);
|
||||
|
||||
cache.nextToken = response.end ?? null;
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useRoomNavigate = () => {
|
||||
const roomIdOrAlias = getCanonicalAliasOrRoomId(mx, roomId);
|
||||
navigate(getSpacePath(roomIdOrAlias));
|
||||
},
|
||||
[mx, navigate]
|
||||
[mx, navigate],
|
||||
);
|
||||
|
||||
const navigateRoom = useCallback(
|
||||
@@ -81,7 +81,7 @@ export const useRoomNavigate = () => {
|
||||
|
||||
navigate(
|
||||
getSpaceRoomPath(pSpaceIdOrAlias, openSpaceTimeline ? roomId : roomIdOrAlias, eventId),
|
||||
opts
|
||||
opts,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ export const useRoomNavigate = () => {
|
||||
roomToParents,
|
||||
mDirects,
|
||||
developerTools,
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -15,7 +15,7 @@ export type RoomPermissionsAPI = {
|
||||
|
||||
export const getRoomPermissionsAPI = (
|
||||
creators: Set<string>,
|
||||
powerLevels: IPowerLevels
|
||||
powerLevels: IPowerLevels,
|
||||
): RoomPermissionsAPI => {
|
||||
const api: RoomPermissionsAPI = {
|
||||
event: (type, userId) => {
|
||||
@@ -49,11 +49,11 @@ export const getRoomPermissionsAPI = (
|
||||
|
||||
export const useRoomPermissions = (
|
||||
creators: Set<string>,
|
||||
powerLevels: IPowerLevels
|
||||
powerLevels: IPowerLevels,
|
||||
): RoomPermissionsAPI => {
|
||||
const api: RoomPermissionsAPI = useMemo(
|
||||
() => getRoomPermissionsAPI(creators, powerLevels),
|
||||
[creators, powerLevels]
|
||||
[creators, powerLevels],
|
||||
);
|
||||
|
||||
return api;
|
||||
|
||||
@@ -13,17 +13,17 @@ export interface PaarrotSubRoomsContent {
|
||||
/**
|
||||
* Hook to get the sub-rooms (child rooms) for a given room.
|
||||
* Sub-rooms are stored in the room's state as im.paarrot.sub_rooms
|
||||
*
|
||||
*
|
||||
* @param room - The parent room
|
||||
* @returns Array of child room IDs
|
||||
*/
|
||||
export const useRoomSubRooms = (room: Room): string[] => {
|
||||
const subRoomsEvent = useStateEvent(room, StateEvent.PaarrotSubRooms);
|
||||
|
||||
|
||||
const subRooms = useMemo(() => {
|
||||
const content = subRoomsEvent?.getContent<PaarrotSubRoomsContent>();
|
||||
return content?.children ?? [];
|
||||
}, [subRoomsEvent]);
|
||||
|
||||
|
||||
return subRooms;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ const equalTypingMembers = (x: TypingReceipt[], y: TypingReceipt[]): boolean =>
|
||||
export const useRoomTypingMember = (roomId: string) => {
|
||||
const selector = useCallback(
|
||||
(roomToTyping: IRoomIdToTypingMembers) => roomToTyping.get(roomId) ?? [],
|
||||
[roomId]
|
||||
[roomId],
|
||||
);
|
||||
|
||||
const typing = useAtomValue(selectAtom(roomIdToTypingMembersAtom, selector, equalTypingMembers));
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import {
|
||||
roomIdToUploadItemsAtomFamily,
|
||||
TUploadItem,
|
||||
} from '../state/room/roomInputDrafts';
|
||||
import { roomIdToUploadItemsAtomFamily, TUploadItem } from '../state/room/roomInputDrafts';
|
||||
import { encryptFile } from '../utils/matrix';
|
||||
import { safeFile } from '../utils/mimeTypes';
|
||||
import { fulfilledPromiseSettledResult } from '../utils/common';
|
||||
@@ -23,7 +20,7 @@ export const useRoomUploadFiles = (room: Room) => {
|
||||
|
||||
if (room.hasEncryptionStateEvent()) {
|
||||
const encryptFiles = fulfilledPromiseSettledResult(
|
||||
await Promise.allSettled(safeFiles.map((f) => encryptFile(f)))
|
||||
await Promise.allSettled(safeFiles.map((f) => encryptFile(f))),
|
||||
);
|
||||
encryptFiles.forEach((ef) =>
|
||||
fileItems.push({
|
||||
@@ -31,7 +28,7 @@ export const useRoomUploadFiles = (room: Room) => {
|
||||
metadata: {
|
||||
markedAsSpoiler: false,
|
||||
},
|
||||
})
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
safeFiles.forEach((f) =>
|
||||
@@ -42,7 +39,7 @@ export const useRoomUploadFiles = (room: Room) => {
|
||||
metadata: {
|
||||
markedAsSpoiler: false,
|
||||
},
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +48,7 @@ export const useRoomUploadFiles = (room: Room) => {
|
||||
item: fileItems,
|
||||
});
|
||||
},
|
||||
[setSelectedFiles, room]
|
||||
[setSelectedFiles, room],
|
||||
);
|
||||
|
||||
const pickFiles = useFilePicker(handleFiles, true);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Icons, IconSrc } from '../components/icons';
|
||||
import { createContext, useCallback, useContext, useMemo } from 'react';
|
||||
import { ConditionKind, IPushRules, MatrixClient, PushRuleKind } from 'matrix-js-sdk';
|
||||
import { Icons, IconSrc } from '../components/icons';
|
||||
|
||||
import { AccountDataEvent } from '../../types/matrix/accountData';
|
||||
import { useAccountData } from './useAccountData';
|
||||
@@ -20,7 +20,7 @@ export type RoomsNotificationPreferences = {
|
||||
};
|
||||
|
||||
const RoomsNotificationPreferencesContext = createContext<RoomsNotificationPreferences | null>(
|
||||
null
|
||||
null,
|
||||
);
|
||||
export const RoomsNotificationPreferencesProvider = RoomsNotificationPreferencesContext.Provider;
|
||||
|
||||
@@ -79,7 +79,7 @@ export enum RoomNotificationMode {
|
||||
|
||||
export const getRoomNotificationMode = (
|
||||
preferences: RoomsNotificationPreferences,
|
||||
roomId: string
|
||||
roomId: string,
|
||||
): RoomNotificationMode => {
|
||||
if (preferences.mute.has(roomId)) {
|
||||
return RoomNotificationMode.Mute;
|
||||
@@ -96,7 +96,7 @@ export const getRoomNotificationMode = (
|
||||
|
||||
export const useRoomNotificationPreference = (
|
||||
preferences: RoomsNotificationPreferences,
|
||||
roomId: string
|
||||
roomId: string,
|
||||
): RoomNotificationMode =>
|
||||
useMemo(() => getRoomNotificationMode(preferences, roomId), [preferences, roomId]);
|
||||
|
||||
@@ -111,7 +111,7 @@ export const setRoomNotificationPreference = async (
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
mode: RoomNotificationMode,
|
||||
previousMode: RoomNotificationMode
|
||||
previousMode: RoomNotificationMode,
|
||||
): Promise<void> => {
|
||||
// remove the old preference
|
||||
if (
|
||||
@@ -158,8 +158,8 @@ export const useSetRoomNotificationPreference = (roomId: string) => {
|
||||
useCallback(
|
||||
(mode: RoomNotificationMode, previousMode: RoomNotificationMode) =>
|
||||
setRoomNotificationPreference(mx, roomId, mode, previousMode),
|
||||
[mx, roomId]
|
||||
)
|
||||
[mx, roomId],
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -21,7 +21,7 @@ export const useScreenSize = (): ScreenSize => {
|
||||
|
||||
useElementSizeObserver(
|
||||
useCallback(() => document.body, []),
|
||||
useCallback((width) => setSize(getScreenSize(width)), [])
|
||||
useCallback((width) => setSize(getScreenSize(width)), []),
|
||||
);
|
||||
|
||||
return size;
|
||||
|
||||
@@ -24,7 +24,7 @@ export type InCinnySpacesContent = {
|
||||
export const parseSidebar = (
|
||||
mx: MatrixClient,
|
||||
orphanSpaces: string[],
|
||||
content?: InCinnySpacesContent
|
||||
content?: InCinnySpacesContent,
|
||||
) => {
|
||||
const sidebar = content?.sidebar ?? content?.shortcut ?? [];
|
||||
const hiddenSet = new Set(content?.hidden ?? []);
|
||||
@@ -76,10 +76,7 @@ export const parseSidebar = (
|
||||
/**
|
||||
* Parse hidden spaces from account data
|
||||
*/
|
||||
export const parseHiddenSpaces = (
|
||||
mx: MatrixClient,
|
||||
content?: InCinnySpacesContent
|
||||
): string[] => {
|
||||
export const parseHiddenSpaces = (mx: MatrixClient, content?: InCinnySpacesContent): string[] => {
|
||||
const hidden = content?.hidden ?? [];
|
||||
return hidden.filter((spaceId) => {
|
||||
if (typeof spaceId !== 'string') return false;
|
||||
@@ -90,14 +87,14 @@ export const parseHiddenSpaces = (
|
||||
};
|
||||
|
||||
export const useSidebarItems = (
|
||||
orphanSpaces: string[]
|
||||
orphanSpaces: string[],
|
||||
): [SidebarItems, Dispatch<SetStateAction<SidebarItems>>] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const [sidebarItems, setSidebarItems] = useState(() => {
|
||||
const inCinnySpacesContent = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
return parseSidebar(mx, orphanSpaces, inCinnySpacesContent);
|
||||
});
|
||||
@@ -105,7 +102,7 @@ export const useSidebarItems = (
|
||||
useEffect(() => {
|
||||
const inCinnySpacesContent = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
setSidebarItems(parseSidebar(mx, orphanSpaces, inCinnySpacesContent));
|
||||
}, [mx, orphanSpaces]);
|
||||
@@ -119,8 +116,8 @@ export const useSidebarItems = (
|
||||
setSidebarItems(parseSidebar(mx, orphanSpaces, newContent));
|
||||
}
|
||||
},
|
||||
[mx, orphanSpaces]
|
||||
)
|
||||
[mx, orphanSpaces],
|
||||
),
|
||||
);
|
||||
|
||||
return [sidebarItems, setSidebarItems];
|
||||
@@ -150,7 +147,7 @@ export const sidebarItemWithout = (items: SidebarItems, roomId: string) => {
|
||||
|
||||
export const makeCinnySpacesContent = (
|
||||
mx: MatrixClient,
|
||||
items: SidebarItems
|
||||
items: SidebarItems,
|
||||
): InCinnySpacesContent => {
|
||||
const currentInSpaces =
|
||||
getAccountData(mx, AccountDataEvent.CinnySpaces)?.getContent<InCinnySpacesContent>() ?? {};
|
||||
@@ -172,7 +169,7 @@ export const useHiddenSpaces = (): [string[], Dispatch<SetStateAction<string[]>>
|
||||
const [hiddenSpaces, setHiddenSpaces] = useState(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
return parseHiddenSpaces(mx, content);
|
||||
});
|
||||
@@ -180,7 +177,7 @@ export const useHiddenSpaces = (): [string[], Dispatch<SetStateAction<string[]>>
|
||||
useEffect(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
setHiddenSpaces(parseHiddenSpaces(mx, content));
|
||||
}, [mx]);
|
||||
@@ -194,8 +191,8 @@ export const useHiddenSpaces = (): [string[], Dispatch<SetStateAction<string[]>>
|
||||
setHiddenSpaces(parseHiddenSpaces(mx, newContent));
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
[mx],
|
||||
),
|
||||
);
|
||||
|
||||
return [hiddenSpaces, setHiddenSpaces];
|
||||
@@ -204,10 +201,7 @@ export const useHiddenSpaces = (): [string[], Dispatch<SetStateAction<string[]>>
|
||||
/**
|
||||
* Create content for hiding a space
|
||||
*/
|
||||
export const makeHideSpaceContent = (
|
||||
mx: MatrixClient,
|
||||
spaceId: string
|
||||
): InCinnySpacesContent => {
|
||||
export const makeHideSpaceContent = (mx: MatrixClient, spaceId: string): InCinnySpacesContent => {
|
||||
const currentContent =
|
||||
getAccountData(mx, AccountDataEvent.CinnySpaces)?.getContent<InCinnySpacesContent>() ?? {};
|
||||
|
||||
@@ -225,10 +219,7 @@ export const makeHideSpaceContent = (
|
||||
/**
|
||||
* Create content for unhiding a space
|
||||
*/
|
||||
export const makeUnhideSpaceContent = (
|
||||
mx: MatrixClient,
|
||||
spaceId: string
|
||||
): InCinnySpacesContent => {
|
||||
export const makeUnhideSpaceContent = (mx: MatrixClient, spaceId: string): InCinnySpacesContent => {
|
||||
const currentContent =
|
||||
getAccountData(mx, AccountDataEvent.CinnySpaces)?.getContent<InCinnySpacesContent>() ?? {};
|
||||
|
||||
@@ -275,7 +266,7 @@ export const useHomeHidden = (): [boolean, Dispatch<SetStateAction<boolean>>] =>
|
||||
const [homeHidden, setHomeHidden] = useState(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
return content?.hideHome ?? false;
|
||||
});
|
||||
@@ -283,7 +274,7 @@ export const useHomeHidden = (): [boolean, Dispatch<SetStateAction<boolean>>] =>
|
||||
useEffect(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
AccountDataEvent.CinnySpaces,
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
setHomeHidden(content?.hideHome ?? false);
|
||||
}, [mx]);
|
||||
@@ -297,8 +288,8 @@ export const useHomeHidden = (): [boolean, Dispatch<SetStateAction<boolean>>] =>
|
||||
setHomeHidden(newContent?.hideHome ?? false);
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
[mx],
|
||||
),
|
||||
);
|
||||
|
||||
return [homeHidden, setHomeHidden];
|
||||
|
||||
@@ -65,7 +65,7 @@ export function isHierarchySpaceRoom(room: IHierarchyRoom | undefined): boolean
|
||||
export async function fetchAllHierarchyRooms(
|
||||
mx: MatrixClient,
|
||||
spaceId: string,
|
||||
maxDepth = 3
|
||||
maxDepth = 3,
|
||||
): Promise<IHierarchyRoom[]> {
|
||||
const allRooms: IHierarchyRoom[] = [];
|
||||
let nextBatch: string | undefined;
|
||||
@@ -84,7 +84,7 @@ const isChildSpace = (
|
||||
childId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
spaceRooms: Set<string>,
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>,
|
||||
): boolean =>
|
||||
isSpace(getRoom(childId) ?? null) ||
|
||||
spaceRooms.has(childId) ||
|
||||
@@ -95,7 +95,7 @@ const getChildRoomsFromSummaries = (
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>,
|
||||
parentByRoomId: Map<string, string>,
|
||||
spaceRooms: Set<string>,
|
||||
getRoom: GetRoomCallback
|
||||
getRoom: GetRoomCallback,
|
||||
): HierarchyItemRoom[] => {
|
||||
const childItems: HierarchyItemRoom[] = [];
|
||||
hierarchySummaries.forEach((summary, roomId) => {
|
||||
@@ -116,7 +116,7 @@ const getHierarchySpaces = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
spaceRooms: Set<string>,
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>,
|
||||
): HierarchyItemSpace[] => {
|
||||
const rootSpaceItem: HierarchyItemSpace = {
|
||||
roomId: rootSpaceId,
|
||||
@@ -190,13 +190,13 @@ const getSpaceHierarchy = (
|
||||
spaceRooms: Set<string>,
|
||||
getRoom: (roomId: string) => Room | undefined,
|
||||
closedCategory: (spaceId: string) => boolean,
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>,
|
||||
): SpaceHierarchy[] => {
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(
|
||||
rootSpaceId,
|
||||
getRoom,
|
||||
spaceRooms,
|
||||
hierarchySummaries
|
||||
hierarchySummaries,
|
||||
);
|
||||
const parentByRoomId = buildParentByRoomId(hierarchySummaries.values());
|
||||
|
||||
@@ -209,7 +209,7 @@ const getSpaceHierarchy = (
|
||||
hierarchySummaries,
|
||||
parentByRoomId,
|
||||
spaceRooms,
|
||||
getRoom
|
||||
getRoom,
|
||||
);
|
||||
if (summaryRooms.length > 0) {
|
||||
return {
|
||||
@@ -244,7 +244,7 @@ const getSpaceHierarchy = (
|
||||
hierarchySummaries,
|
||||
parentByRoomId,
|
||||
spaceRooms,
|
||||
getRoom
|
||||
getRoom,
|
||||
);
|
||||
const roomIds = new Set(childItems.map((i) => i.roomId));
|
||||
summaryRooms.forEach((item) => {
|
||||
@@ -267,19 +267,19 @@ export const useSpaceHierarchy = (
|
||||
spaceRooms: Set<string>,
|
||||
getRoom: (roomId: string) => Room | undefined,
|
||||
closedCategory: (spaceId: string) => boolean,
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>
|
||||
hierarchySummaries: Map<string, IHierarchyRoom>,
|
||||
): SpaceHierarchy[] => {
|
||||
const mx = useMatrixClient();
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
|
||||
const [hierarchyAtom] = useState(() =>
|
||||
atom(getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries))
|
||||
atom(getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries)),
|
||||
);
|
||||
const [hierarchy, setHierarchy] = useAtom(hierarchyAtom);
|
||||
|
||||
useEffect(() => {
|
||||
setHierarchy(
|
||||
getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries)
|
||||
getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries),
|
||||
);
|
||||
}, [mx, spaceId, spaceRooms, setHierarchy, getRoom, closedCategory, hierarchySummaries]);
|
||||
|
||||
@@ -293,12 +293,20 @@ export const useSpaceHierarchy = (
|
||||
|
||||
if (spaceId === eventRoomId || getAllParents(roomToParents, eventRoomId).has(spaceId)) {
|
||||
setHierarchy(
|
||||
getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries)
|
||||
getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory, hierarchySummaries),
|
||||
);
|
||||
}
|
||||
},
|
||||
[spaceId, roomToParents, setHierarchy, spaceRooms, getRoom, closedCategory, hierarchySummaries]
|
||||
)
|
||||
[
|
||||
spaceId,
|
||||
roomToParents,
|
||||
setHierarchy,
|
||||
spaceRooms,
|
||||
getRoom,
|
||||
closedCategory,
|
||||
hierarchySummaries,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return hierarchy;
|
||||
@@ -308,13 +316,13 @@ const getSpaceJoinedHierarchy = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
sortRoomItems: (parentId: string, items: HierarchyItem[]) => HierarchyItem[]
|
||||
sortRoomItems: (parentId: string, items: HierarchyItem[]) => HierarchyItem[],
|
||||
): HierarchyItem[] => {
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(
|
||||
rootSpaceId,
|
||||
getRoom,
|
||||
new Set(),
|
||||
new Map()
|
||||
new Map(),
|
||||
);
|
||||
|
||||
const hierarchy: HierarchyItem[] = spaceItems.flatMap((spaceItem) => {
|
||||
@@ -359,7 +367,7 @@ export const useSpaceJoinedHierarchy = (
|
||||
spaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
sortByActivity: (spaceId: string) => boolean
|
||||
sortByActivity: (spaceId: string) => boolean,
|
||||
): HierarchyItem[] => {
|
||||
const mx = useMatrixClient();
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
@@ -373,11 +381,11 @@ export const useSpaceJoinedHierarchy = (
|
||||
items.sort(hierarchyItemTs).sort(hierarchyItemByOrder);
|
||||
return items;
|
||||
},
|
||||
[mx, sortByActivity]
|
||||
[mx, sortByActivity],
|
||||
);
|
||||
|
||||
const [hierarchyAtom] = useState(() =>
|
||||
atom(getSpaceJoinedHierarchy(spaceId, getRoom, excludeRoom, sortRoomItems))
|
||||
atom(getSpaceJoinedHierarchy(spaceId, getRoom, excludeRoom, sortRoomItems)),
|
||||
);
|
||||
const [hierarchy, setHierarchy] = useAtom(hierarchyAtom);
|
||||
|
||||
@@ -397,8 +405,8 @@ export const useSpaceJoinedHierarchy = (
|
||||
setHierarchy(getSpaceJoinedHierarchy(spaceId, getRoom, excludeRoom, sortRoomItems));
|
||||
}
|
||||
},
|
||||
[spaceId, roomToParents, setHierarchy, getRoom, excludeRoom, sortRoomItems]
|
||||
)
|
||||
[spaceId, roomToParents, setHierarchy, getRoom, excludeRoom, sortRoomItems],
|
||||
),
|
||||
);
|
||||
|
||||
return hierarchy;
|
||||
@@ -411,7 +419,7 @@ export type FetchSpaceHierarchyLevelData = {
|
||||
};
|
||||
export const useFetchSpaceHierarchyLevel = (
|
||||
roomId: string,
|
||||
enable: boolean
|
||||
enable: boolean,
|
||||
): FetchSpaceHierarchyLevelData => {
|
||||
const mx = useMatrixClient();
|
||||
const pageNoRef = useRef(0);
|
||||
@@ -422,7 +430,7 @@ export const useFetchSpaceHierarchyLevel = (
|
||||
string | undefined
|
||||
> = useCallback(
|
||||
({ pageParam }) => mx.getRoomHierarchy(roomId, PER_PAGE_COUNT, 1, false, pageParam),
|
||||
[roomId, mx]
|
||||
[roomId, mx],
|
||||
);
|
||||
|
||||
const queryResponse = useInfiniteQuery({
|
||||
|
||||
@@ -20,13 +20,13 @@ export const useStateEvent = (room: Room, eventType: StateEvent, stateKey = '')
|
||||
forceUpdate();
|
||||
}
|
||||
},
|
||||
[room, eventType, stateKey, forceUpdate]
|
||||
)
|
||||
[room, eventType, stateKey, forceUpdate],
|
||||
),
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
() => getStateEvent(room, eventType, stateKey),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[room, eventType, stateKey, updateCount]
|
||||
[room, eventType, stateKey, updateCount],
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
|
||||
export type StateEventCallback = (
|
||||
event: MatrixEvent,
|
||||
state: RoomState,
|
||||
lastStateEvent: MatrixEvent | null
|
||||
lastStateEvent: MatrixEvent | null,
|
||||
) => void;
|
||||
|
||||
export const useStateEventCallback = (mx: MatrixClient, onStateEvent: StateEventCallback) => {
|
||||
|
||||
@@ -16,13 +16,13 @@ export const useStateEvents = (room: Room, eventType: StateEvent) => {
|
||||
forceUpdate();
|
||||
}
|
||||
},
|
||||
[room, eventType, forceUpdate]
|
||||
)
|
||||
[room, eventType, forceUpdate],
|
||||
),
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
() => getStateEvents(room, eventType),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[room, eventType, updateCount]
|
||||
[room, eventType, updateCount],
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
||||
|
||||
export const useSyncState = (
|
||||
mx: MatrixClient | undefined,
|
||||
onChange: ClientEventHandlerMap[ClientEvent.Sync]
|
||||
onChange: ClientEventHandlerMap[ClientEvent.Sync],
|
||||
): void => {
|
||||
useEffect(() => {
|
||||
mx?.on(ClientEvent.Sync, onChange);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { GetTarget } from '../plugins/text-area/type';
|
||||
|
||||
export const useTextAreaCodeEditor = (
|
||||
textAreaRef: MutableRefObject<HTMLTextAreaElement | null>,
|
||||
intentSpaceCount: number
|
||||
intentSpaceCount: number,
|
||||
) => {
|
||||
const getTarget: GetTarget = useCallback(() => {
|
||||
const target = textAreaRef.current;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Cursor, Intent, Operations, TextArea } from '../plugins/text-area';
|
||||
export const useTextAreaIntentHandler = (
|
||||
textArea: TextArea,
|
||||
operations: Operations,
|
||||
intent: Intent
|
||||
intent: Intent,
|
||||
) => {
|
||||
const handler: KeyboardEventHandler<HTMLTextAreaElement> = useCallback(
|
||||
(evt) => {
|
||||
@@ -51,7 +51,7 @@ export const useTextAreaIntentHandler = (
|
||||
operations.select(intent.addPreviousLine(cursor));
|
||||
}
|
||||
},
|
||||
[textArea, operations, intent]
|
||||
[textArea, operations, intent],
|
||||
);
|
||||
|
||||
return handler;
|
||||
|
||||
+57
-26
@@ -2,7 +2,18 @@ import { lightTheme } from 'folds';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { onDarkFontWeight, onLightFontWeight } from '../../config.css';
|
||||
import { butterTheme, catppuccinMochaTheme, darkTheme, discordTheme, discordDarkerTheme, mochaTheme, silverTheme, stationeryDarkTheme, stationeryTheme, twilightTheme } from '../../colors.css';
|
||||
import {
|
||||
butterTheme,
|
||||
catppuccinMochaTheme,
|
||||
darkTheme,
|
||||
discordTheme,
|
||||
discordDarkerTheme,
|
||||
mochaTheme,
|
||||
silverTheme,
|
||||
stationeryDarkTheme,
|
||||
stationeryTheme,
|
||||
twilightTheme,
|
||||
} from '../../colors.css';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { pluginRegistry } from '../features/settings/plugins/PluginAPI';
|
||||
@@ -80,37 +91,54 @@ export const StationeryTheme: Theme = {
|
||||
export const StationeryDarkTheme: Theme = {
|
||||
id: 'stationery-dark-theme',
|
||||
kind: ThemeKind.Dark,
|
||||
classNames: ['stationery-dark-theme', 'stationery', stationeryDarkTheme, onDarkFontWeight, 'prism-dark'],
|
||||
classNames: [
|
||||
'stationery-dark-theme',
|
||||
'stationery',
|
||||
stationeryDarkTheme,
|
||||
onDarkFontWeight,
|
||||
'prism-dark',
|
||||
],
|
||||
};
|
||||
|
||||
export const useThemes = (): Theme[] => {
|
||||
const [pluginThemesUpdate, setPluginThemesUpdate] = useState(0);
|
||||
|
||||
|
||||
// Force update when plugins change (this is a simple approach)
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setPluginThemesUpdate(prev => prev + 1);
|
||||
setPluginThemesUpdate((prev) => prev + 1);
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
const builtInThemes: Theme[] = useMemo(() => [
|
||||
LightTheme, SilverTheme, StationeryTheme, StationeryDarkTheme, DarkTheme, ButterTheme,
|
||||
DiscordTheme, DiscordDarkerTheme, TwilightTheme,
|
||||
MochaTheme, CatppuccinMochaTheme
|
||||
], []);
|
||||
|
||||
|
||||
const builtInThemes: Theme[] = useMemo(
|
||||
() => [
|
||||
LightTheme,
|
||||
SilverTheme,
|
||||
StationeryTheme,
|
||||
StationeryDarkTheme,
|
||||
DarkTheme,
|
||||
ButterTheme,
|
||||
DiscordTheme,
|
||||
DiscordDarkerTheme,
|
||||
TwilightTheme,
|
||||
MochaTheme,
|
||||
CatppuccinMochaTheme,
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
// Convert plugin themes to Theme format
|
||||
const pluginThemes: Theme[] = useMemo(() => {
|
||||
const themes = pluginRegistry.getPluginThemes();
|
||||
return themes.map(pluginTheme => ({
|
||||
return themes.map((pluginTheme) => ({
|
||||
id: pluginTheme.id,
|
||||
kind: pluginTheme.kind === 'dark' ? ThemeKind.Dark : ThemeKind.Light,
|
||||
classNames: [
|
||||
pluginTheme.className,
|
||||
pluginTheme.kind === 'dark' ? onDarkFontWeight : onLightFontWeight,
|
||||
pluginTheme.kind === 'dark' ? 'prism-dark' : 'prism-light'
|
||||
]
|
||||
pluginTheme.kind === 'dark' ? 'prism-dark' : 'prism-light',
|
||||
],
|
||||
}));
|
||||
}, [pluginThemesUpdate]);
|
||||
|
||||
@@ -119,14 +147,14 @@ export const useThemes = (): Theme[] => {
|
||||
|
||||
export const useThemeNames = (): Record<string, string> => {
|
||||
const [pluginThemesUpdate, setPluginThemesUpdate] = useState(0);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setPluginThemesUpdate(prev => prev + 1);
|
||||
setPluginThemesUpdate((prev) => prev + 1);
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
|
||||
return useMemo(() => {
|
||||
const builtInNames = {
|
||||
[LightTheme.id]: 'Light',
|
||||
@@ -141,13 +169,16 @@ export const useThemeNames = (): Record<string, string> => {
|
||||
[MochaTheme.id]: 'Mocha',
|
||||
[CatppuccinMochaTheme.id]: 'Catppuccin Mocha',
|
||||
};
|
||||
|
||||
|
||||
const pluginThemes = pluginRegistry.getPluginThemes();
|
||||
const pluginNames = pluginThemes.reduce((acc, theme) => {
|
||||
acc[theme.id] = theme.name;
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
const pluginNames = pluginThemes.reduce(
|
||||
(acc, theme) => {
|
||||
acc[theme.id] = theme.name;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
|
||||
return { ...builtInNames, ...pluginNames };
|
||||
}, [pluginThemesUpdate]);
|
||||
};
|
||||
@@ -155,7 +186,7 @@ export const useThemeNames = (): Record<string, string> => {
|
||||
export const useSystemThemeKind = (): ThemeKind => {
|
||||
const darkModeQueryList = useMemo(() => window.matchMedia('(prefers-color-scheme: dark)'), []);
|
||||
const [themeKind, setThemeKind] = useState<ThemeKind>(
|
||||
darkModeQueryList.matches ? ThemeKind.Dark : ThemeKind.Light
|
||||
darkModeQueryList.matches ? ThemeKind.Dark : ThemeKind.Light,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -188,8 +219,8 @@ export const useActiveTheme = (): Theme => {
|
||||
|
||||
const selectedTheme =
|
||||
systemThemeKind === ThemeKind.Dark
|
||||
? themes.find((theme) => theme.id === darkThemeId) ?? DarkTheme
|
||||
: themes.find((theme) => theme.id === lightThemeId) ?? LightTheme;
|
||||
? (themes.find((theme) => theme.id === darkThemeId) ?? DarkTheme)
|
||||
: (themes.find((theme) => theme.id === lightThemeId) ?? LightTheme);
|
||||
|
||||
return selectedTheme;
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ export type ThrottleCallback<T extends unknown[]> = (...args: T) => void;
|
||||
|
||||
export function useThrottle<T extends unknown[]>(
|
||||
callback: ThrottleCallback<T>,
|
||||
options?: ThrottleOptions
|
||||
options?: ThrottleOptions,
|
||||
): ThrottleCallback<T> {
|
||||
const timeoutIdRef = useRef<number>();
|
||||
const argsRef = useRef<T>();
|
||||
@@ -34,7 +34,7 @@ export function useThrottle<T extends unknown[]>(
|
||||
timeoutIdRef.current = undefined;
|
||||
}, wait);
|
||||
},
|
||||
[callback, wait, immediate]
|
||||
[callback, wait, immediate],
|
||||
);
|
||||
|
||||
return debounceCallback;
|
||||
|
||||
@@ -30,7 +30,7 @@ export function useTimeoutToggle(duration = 1500, initial = false): [boolean, ()
|
||||
() => () => {
|
||||
clear();
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
return [active, trigger];
|
||||
|
||||
@@ -76,7 +76,7 @@ export const useUIAFlow = (authData: IAuthData, uiaFlow: UIAFlow): UIAFlowInterf
|
||||
|
||||
const hasStage = useCallback(
|
||||
(stageType: string): boolean => uiaFlow.stages.includes(stageType),
|
||||
[uiaFlow]
|
||||
[uiaFlow],
|
||||
);
|
||||
|
||||
const getStageInfo = useCallback(
|
||||
@@ -85,7 +85,7 @@ export const useUIAFlow = (authData: IAuthData, uiaFlow: UIAFlow): UIAFlowInterf
|
||||
|
||||
return params[stageType];
|
||||
},
|
||||
[hasStage, params]
|
||||
[hasStage, params],
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -96,7 +96,7 @@ export const useUIAFlow = (authData: IAuthData, uiaFlow: UIAFlow): UIAFlowInterf
|
||||
};
|
||||
|
||||
export const useUIAMatrixError = (
|
||||
error?: MatrixError
|
||||
error?: MatrixError,
|
||||
): [undefined, undefined] | [IAuthData, undefined] | [undefined, MatrixError] => {
|
||||
if (!error) return [undefined, undefined];
|
||||
if (error.httpStatus === 401) return [error.data as IAuthData, undefined];
|
||||
|
||||
@@ -15,7 +15,7 @@ import { getProfileAssetUrl } from '../utils/profileAssetCache';
|
||||
export function useUserBanner(): [
|
||||
string | undefined,
|
||||
(banner: string | undefined) => Promise<void>,
|
||||
boolean
|
||||
boolean,
|
||||
] {
|
||||
const mx = useMatrixClient();
|
||||
const [banner, setBanner] = useState<string | undefined>();
|
||||
@@ -58,7 +58,7 @@ export function useUserBanner(): [
|
||||
await saveBannerUrl(mx, newBanner);
|
||||
setBanner(newBanner);
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
return [banner, updateBanner, loading];
|
||||
|
||||
@@ -9,14 +9,19 @@ import {
|
||||
saveNameplate,
|
||||
saveProfileEffect,
|
||||
} from '../utils/profileFields';
|
||||
import { clearProfileCache, getCachedProfileFields, getProfileFields, registerProfileCacheListener } from '../utils/profileCache';
|
||||
import {
|
||||
clearProfileCache,
|
||||
getCachedProfileFields,
|
||||
getProfileFields,
|
||||
registerProfileCacheListener,
|
||||
} from '../utils/profileCache';
|
||||
import { getProfileAssetUrl } from '../utils/profileAssetCache';
|
||||
import { CollectibleKind } from '../utils/discordCollectibles';
|
||||
|
||||
export function useUserCollectibles(): [
|
||||
CollectibleProfileFields,
|
||||
(kind: CollectibleKind, collectible: StoredCollectible | undefined) => Promise<void>,
|
||||
boolean
|
||||
boolean,
|
||||
] {
|
||||
const mx = useMatrixClient();
|
||||
const [collectibles, setCollectibles] = useState<CollectibleProfileFields>({});
|
||||
@@ -61,7 +66,7 @@ export function useUserCollectibles(): [
|
||||
clearProfileCache(mx.getUserId());
|
||||
setCollectibles((prev) => ({ ...prev, [kind]: collectible }));
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
return [collectibles, updateCollectible, loading];
|
||||
|
||||
@@ -11,7 +11,11 @@ import {
|
||||
resolveColorForTheme,
|
||||
saveColorPreference,
|
||||
} from '../utils/profileFields';
|
||||
import { getCachedProfileFields, getProfileFields, registerProfileCacheListener } from '../utils/profileCache';
|
||||
import {
|
||||
getCachedProfileFields,
|
||||
getProfileFields,
|
||||
registerProfileCacheListener,
|
||||
} from '../utils/profileCache';
|
||||
|
||||
/**
|
||||
* Hook to manage the user's MSC4522 color preference on their global profile.
|
||||
@@ -19,7 +23,7 @@ import { getCachedProfileFields, getProfileFields, registerProfileCacheListener
|
||||
export function useUserColorPreference(): [
|
||||
ColorPreference | undefined,
|
||||
(preference: ColorPreference | undefined) => Promise<void>,
|
||||
boolean
|
||||
boolean,
|
||||
] {
|
||||
const mx = useMatrixClient();
|
||||
const [preference, setPreference] = useState<ColorPreference | undefined>();
|
||||
@@ -63,7 +67,7 @@ export function useUserColorPreference(): [
|
||||
await saveColorPreference(mx, newPreference!);
|
||||
setPreference(newPreference);
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
return [preference, updatePreference, loading];
|
||||
@@ -122,7 +126,7 @@ export function useOtherUserColorPreference(userId: string): ColorPreference | u
|
||||
*/
|
||||
export function useMemberColorPreference(userId: string, room?: Room): ColorPreference | undefined {
|
||||
const [preference, setPreference] = useState<ColorPreference | undefined>(() =>
|
||||
extractMemberColorPreference(room, userId)
|
||||
extractMemberColorPreference(room, userId),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -147,7 +151,11 @@ export function useOtherUserColor(userId: string, room?: Room): string | undefin
|
||||
/**
|
||||
* Resolve the current user's username color for the active theme.
|
||||
*/
|
||||
export function useUsernameColor(userId: string, room?: Room, themeKind?: ThemeKind): string | undefined {
|
||||
export function useUsernameColor(
|
||||
userId: string,
|
||||
room?: Room,
|
||||
themeKind?: ThemeKind,
|
||||
): string | undefined {
|
||||
const theme = useTheme();
|
||||
const kind = themeKind ?? theme.kind;
|
||||
const profilePreference = useOtherUserColorPreference(userId);
|
||||
|
||||
@@ -61,5 +61,5 @@ export const usePresenceLabel = (): Record<Presence, string> =>
|
||||
[Presence.Unavailable]: 'Busy',
|
||||
[Presence.Offline]: 'Away',
|
||||
}),
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { UserEvent, UserEventHandlerMap } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { getCachedProfileFields, getProfileFields, registerProfileCacheListener } from '../utils/profileCache';
|
||||
import {
|
||||
getCachedProfileFields,
|
||||
getProfileFields,
|
||||
registerProfileCacheListener,
|
||||
} from '../utils/profileCache';
|
||||
|
||||
export type UserProfile = {
|
||||
avatarUrl?: string;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useUserTrustStatusChange = (
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.UserTrustStatusChanged]
|
||||
onChange: CryptoEventHandlerMap[CryptoEvent.UserTrustStatusChanged],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
export function useUserTypingVerb(): [
|
||||
string | undefined,
|
||||
(verb: string | undefined) => Promise<void>,
|
||||
boolean
|
||||
boolean,
|
||||
] {
|
||||
const mx = useMatrixClient();
|
||||
const [verb, setVerb] = useState<string | undefined>();
|
||||
@@ -64,7 +64,7 @@ export function useUserTypingVerb(): [
|
||||
await saveTypingVerb(mx, parsed);
|
||||
setVerb(parsed);
|
||||
},
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
|
||||
return [verb, updateVerb, loading];
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useVerificationRequestReceived = (
|
||||
onRequest: CryptoEventHandlerMap[CryptoEvent.VerificationRequestReceived]
|
||||
onRequest: CryptoEventHandlerMap[CryptoEvent.VerificationRequestReceived],
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useVerificationRequestReceived = (
|
||||
|
||||
export const useVerificationRequestChange = (
|
||||
request: VerificationRequest,
|
||||
onChange: VerificationRequestEventHandlerMap[VerificationRequestEvent.Change]
|
||||
onChange: VerificationRequestEventHandlerMap[VerificationRequestEvent.Change],
|
||||
) => {
|
||||
useEffect(() => {
|
||||
request.on(VerificationRequestEvent.Change, onChange);
|
||||
@@ -44,7 +44,7 @@ export const useVerificationRequestPhase = (request: VerificationRequest): Verif
|
||||
request,
|
||||
useCallback(() => {
|
||||
setPhase(request.phase);
|
||||
}, [request])
|
||||
}, [request]),
|
||||
);
|
||||
|
||||
return phase;
|
||||
@@ -52,7 +52,7 @@ export const useVerificationRequestPhase = (request: VerificationRequest): Verif
|
||||
|
||||
export const useVerifierCancel = (
|
||||
verifier: Verifier,
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.Cancel]
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.Cancel],
|
||||
) => {
|
||||
useEffect(() => {
|
||||
verifier.on(VerifierEvent.Cancel, onCallback);
|
||||
@@ -64,7 +64,7 @@ export const useVerifierCancel = (
|
||||
|
||||
export const useVerifierShowSas = (
|
||||
verifier: Verifier,
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.ShowSas]
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.ShowSas],
|
||||
) => {
|
||||
useEffect(() => {
|
||||
verifier.on(VerifierEvent.ShowSas, onCallback);
|
||||
@@ -76,7 +76,7 @@ export const useVerifierShowSas = (
|
||||
|
||||
export const useVerifierShowReciprocateQr = (
|
||||
verifier: Verifier,
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.ShowReciprocateQr]
|
||||
onCallback: VerifierEventHandlerMap[VerifierEvent.ShowReciprocateQr],
|
||||
) => {
|
||||
useEffect(() => {
|
||||
verifier.on(VerifierEvent.ShowReciprocateQr, onCallback);
|
||||
|
||||
@@ -33,29 +33,29 @@ export const useViewTransitions = () => {
|
||||
|
||||
/**
|
||||
* Custom navigate hook that wraps navigation in view transitions
|
||||
*
|
||||
*
|
||||
* **USAGE:**
|
||||
* Replace `useNavigate()` with `useNavigateWithTransition()` for smooth transitions
|
||||
*
|
||||
*
|
||||
* ```tsx
|
||||
* // Before:
|
||||
* import { useNavigate } from 'react-router-dom';
|
||||
* const navigate = useNavigate();
|
||||
*
|
||||
*
|
||||
* // After:
|
||||
* import { useNavigateWithTransition } from '../hooks/useViewTransitions';
|
||||
* const navigate = useNavigateWithTransition();
|
||||
*
|
||||
*
|
||||
* // Usage remains the same:
|
||||
* navigate('/some/path');
|
||||
* navigate(-1); // Go back
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* This enables smooth animated transitions when navigating between:
|
||||
* - Different spaces
|
||||
* - Different rooms
|
||||
* - Different sections (Home, Inbox, Settings, etc.)
|
||||
*
|
||||
*
|
||||
* Falls back to instant navigation on browsers that don't support View Transitions API.
|
||||
*/
|
||||
export const useNavigateWithTransition = () => {
|
||||
@@ -80,6 +80,6 @@ export const useNavigateWithTransition = () => {
|
||||
}
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[navigate],
|
||||
);
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ const getDropIndex = (
|
||||
range: ItemRange,
|
||||
dropDirection: Direction,
|
||||
getItemElement: (index: number) => HTMLElement | undefined,
|
||||
pageThreshold = 1
|
||||
pageThreshold = 1,
|
||||
): number | undefined => {
|
||||
const fromBackward = dropDirection === Direction.Backward;
|
||||
const items = fromBackward ? generateItems(range) : generateItems(range).reverse();
|
||||
@@ -116,7 +116,7 @@ type RestoreAnchorData = [number | undefined, HTMLElement | undefined];
|
||||
const getRestoreAnchor = (
|
||||
range: ItemRange,
|
||||
getItemElement: (index: number) => HTMLElement | undefined,
|
||||
direction: Direction
|
||||
direction: Direction,
|
||||
): RestoreAnchorData => {
|
||||
let scrollAnchorEl: HTMLElement | undefined;
|
||||
const scrollAnchorItem = (
|
||||
@@ -146,7 +146,7 @@ const getRestoreScrollData = (scrollTop: number, restoreAnchorData: RestoreAncho
|
||||
|
||||
const useObserveAnchorHandle = (
|
||||
intersectionObserver: ReturnType<typeof useIntersectionObserver>,
|
||||
anchorType: Direction
|
||||
anchorType: Direction,
|
||||
): HandleObserveAnchor =>
|
||||
useMemo<HandleObserveAnchor>(() => {
|
||||
let anchor: HTMLElement | null = null;
|
||||
@@ -161,7 +161,7 @@ const useObserveAnchorHandle = (
|
||||
}, [intersectionObserver, anchorType]);
|
||||
|
||||
export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
options: VirtualPaginatorOptions<TScrollElement>
|
||||
options: VirtualPaginatorOptions<TScrollElement>,
|
||||
): VirtualPaginator => {
|
||||
const { count, limit, range, onRangeChange, getScrollElement, getItemElement, onEnd } = options;
|
||||
|
||||
@@ -225,7 +225,7 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
});
|
||||
return true;
|
||||
},
|
||||
[getScrollElement]
|
||||
[getScrollElement],
|
||||
);
|
||||
|
||||
const scrollToItem = useCallback<ScrollToItem>(
|
||||
@@ -264,7 +264,7 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
}
|
||||
return scrollToElement(itemElement, opts);
|
||||
},
|
||||
[getScrollElement, scrollToElement, getItemElement, onRangeChange]
|
||||
[getScrollElement, scrollToElement, getItemElement, onRangeChange],
|
||||
);
|
||||
|
||||
const paginate = useCallback(
|
||||
@@ -282,7 +282,7 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
if (scrollEl) {
|
||||
restoreScrollRef.current = getRestoreScrollData(
|
||||
scrollEl.scrollTop,
|
||||
getRestoreAnchor({ start, end }, getItemElement, Direction.Backward)
|
||||
getRestoreAnchor({ start, end }, getItemElement, Direction.Backward),
|
||||
);
|
||||
}
|
||||
if (scrollEl) {
|
||||
@@ -300,7 +300,7 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
if (scrollEl) {
|
||||
restoreScrollRef.current = getRestoreScrollData(
|
||||
scrollEl.scrollTop,
|
||||
getRestoreAnchor({ start, end }, getItemElement, Direction.Forward)
|
||||
getRestoreAnchor({ start, end }, getItemElement, Direction.Forward),
|
||||
);
|
||||
}
|
||||
end = Math.min(end + currentLimit, currentCount);
|
||||
@@ -315,25 +315,25 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
end,
|
||||
});
|
||||
},
|
||||
[getScrollElement, getItemElement, onEnd, onRangeChange]
|
||||
[getScrollElement, getItemElement, onEnd, onRangeChange],
|
||||
);
|
||||
|
||||
const handlePaginatorElIntersection: OnIntersectionCallback = useCallback(
|
||||
(entries) => {
|
||||
const anchorB = entries.find(
|
||||
(entry) => entry.target.getAttribute(PAGINATOR_ANCHOR_ATTR) === Direction.Backward
|
||||
(entry) => entry.target.getAttribute(PAGINATOR_ANCHOR_ATTR) === Direction.Backward,
|
||||
);
|
||||
if (anchorB?.isIntersecting) {
|
||||
paginate(Direction.Backward);
|
||||
}
|
||||
const anchorF = entries.find(
|
||||
(entry) => entry.target.getAttribute(PAGINATOR_ANCHOR_ATTR) === Direction.Forward
|
||||
(entry) => entry.target.getAttribute(PAGINATOR_ANCHOR_ATTR) === Direction.Forward,
|
||||
);
|
||||
if (anchorF?.isIntersecting) {
|
||||
paginate(Direction.Forward);
|
||||
}
|
||||
},
|
||||
[paginate]
|
||||
[paginate],
|
||||
);
|
||||
|
||||
const intersectionObserver = useIntersectionObserver(
|
||||
@@ -342,8 +342,8 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
() => ({
|
||||
root: getScrollElement(),
|
||||
}),
|
||||
[getScrollElement]
|
||||
)
|
||||
[getScrollElement],
|
||||
),
|
||||
);
|
||||
|
||||
const observeBackAnchor = useObserveAnchorHandle(intersectionObserver, Direction.Backward);
|
||||
@@ -399,10 +399,10 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
|
||||
const scrollElement = getScrollElement();
|
||||
if (!scrollElement) return;
|
||||
const backAnchor = scrollElement.querySelector(
|
||||
`[${PAGINATOR_ANCHOR_ATTR}="${Direction.Backward}"]`
|
||||
`[${PAGINATOR_ANCHOR_ATTR}="${Direction.Backward}"]`,
|
||||
) as HTMLElement | null;
|
||||
const frontAnchor = scrollElement.querySelector(
|
||||
`[${PAGINATOR_ANCHOR_ATTR}="${Direction.Forward}"]`
|
||||
`[${PAGINATOR_ANCHOR_ATTR}="${Direction.Forward}"]`,
|
||||
) as HTMLElement | null;
|
||||
|
||||
if (backAnchor && isIntersectingScrollView(scrollElement, backAnchor)) {
|
||||
|
||||
Reference in New Issue
Block a user