chore: upgrade i18next 26, prettier 3, fontsource-variable, domhandler 6, lint-staged 17
- i18next 23->26 + react-i18next 15->17 - prettier 2->3, reformat all files - replace @fontsource/inter with @fontsource-variable/inter 5, update import path - domhandler 5->6 (aligns with transitive deps) - lint-staged 16->17
This commit is contained in:
@@ -66,5 +66,5 @@ export const backupRestoreProgressAtom = atom<
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ export const callEmbedAtom = atom<CallEmbed | undefined, [CallEmbed | undefined]
|
||||
}
|
||||
|
||||
set(baseCallEmbedAtom, callEmbed);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const callChatAtom = atom<boolean>(false);
|
||||
|
||||
@@ -35,7 +35,7 @@ export const makeCallPreferencesAtom = (userId: string): CallPreferencesAtom =>
|
||||
(key, value) => {
|
||||
// Don't persist video state — always resets to off on next load.
|
||||
setLocalStorageItem(key, { ...value, video: false });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return callPreferencesAtom;
|
||||
|
||||
@@ -36,7 +36,7 @@ export const makeClosedLobbyCategoriesAtom = (userId: string): ClosedLobbyCatego
|
||||
(key, value) => {
|
||||
const arrayValue = Array.from(value);
|
||||
setLocalStorageItem(key, arrayValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const closedLobbyCategoriesAtom = atom<Set<string>, [ClosedLobbyCategoriesAction], undefined>(
|
||||
@@ -47,7 +47,7 @@ export const makeClosedLobbyCategoriesAtom = (userId: string): ClosedLobbyCatego
|
||||
baseClosedLobbyCategoriesAtom,
|
||||
produce(get(baseClosedLobbyCategoriesAtom), (draft) => {
|
||||
draft.delete(action.categoryId);
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -56,10 +56,10 @@ export const makeClosedLobbyCategoriesAtom = (userId: string): ClosedLobbyCatego
|
||||
baseClosedLobbyCategoriesAtom,
|
||||
produce(get(baseClosedLobbyCategoriesAtom), (draft) => {
|
||||
draft.add(action.categoryId);
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return closedLobbyCategoriesAtom;
|
||||
|
||||
@@ -36,7 +36,7 @@ export const makeClosedNavCategoriesAtom = (userId: string): ClosedNavCategories
|
||||
(key, value) => {
|
||||
const arrayValue = Array.from(value);
|
||||
setLocalStorageItem(key, arrayValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const closedNavCategoriesAtom = atom<Set<string>, [ClosedNavCategoriesAction], undefined>(
|
||||
@@ -47,7 +47,7 @@ export const makeClosedNavCategoriesAtom = (userId: string): ClosedNavCategories
|
||||
baseClosedNavCategoriesAtom,
|
||||
produce(get(baseClosedNavCategoriesAtom), (draft) => {
|
||||
draft.delete(action.categoryId);
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -56,10 +56,10 @@ export const makeClosedNavCategoriesAtom = (userId: string): ClosedNavCategories
|
||||
baseClosedNavCategoriesAtom,
|
||||
produce(get(baseClosedNavCategoriesAtom), (draft) => {
|
||||
draft.add(action.categoryId);
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return closedNavCategoriesAtom;
|
||||
|
||||
@@ -28,7 +28,7 @@ export const useOpenCreateRoomModal = (): OpenCallback => {
|
||||
(spaceId, type) => {
|
||||
setSettings({ spaceId, type });
|
||||
},
|
||||
[setSettings]
|
||||
[setSettings],
|
||||
);
|
||||
|
||||
return open;
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useOpenCreateSpaceModal = (): OpenCallback => {
|
||||
(spaceId) => {
|
||||
setSettings({ spaceId });
|
||||
},
|
||||
[setSettings]
|
||||
[setSettings],
|
||||
);
|
||||
|
||||
return open;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { allInvitesAtom } from '../room-list/inviteList';
|
||||
export const useSpaceInvites = (mx: MatrixClient, invitesAtom: typeof allInvitesAtom) => {
|
||||
const selector = useCallback(
|
||||
(rooms: string[]) => rooms.filter((roomId) => isSpace(mx.getRoom(roomId))),
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
return useAtomValue(selectAtom(invitesAtom, selector, compareRoomsEqual));
|
||||
};
|
||||
@@ -17,16 +17,16 @@ export const useSpaceInvites = (mx: MatrixClient, invitesAtom: typeof allInvites
|
||||
export const useRoomInvites = (
|
||||
mx: MatrixClient,
|
||||
invitesAtom: typeof allInvitesAtom,
|
||||
mDirects: Set<string>
|
||||
mDirects: Set<string>,
|
||||
) => {
|
||||
const selector = useCallback(
|
||||
(rooms: string[]) =>
|
||||
rooms.filter(
|
||||
(roomId) =>
|
||||
isRoom(mx.getRoom(roomId)) &&
|
||||
!(mDirects.has(roomId) || isDirectInvite(mx.getRoom(roomId), mx.getUserId()))
|
||||
!(mDirects.has(roomId) || isDirectInvite(mx.getRoom(roomId), mx.getUserId())),
|
||||
),
|
||||
[mx, mDirects]
|
||||
[mx, mDirects],
|
||||
);
|
||||
return useAtomValue(selectAtom(invitesAtom, selector, compareRoomsEqual));
|
||||
};
|
||||
@@ -34,14 +34,14 @@ export const useRoomInvites = (
|
||||
export const useDirectInvites = (
|
||||
mx: MatrixClient,
|
||||
invitesAtom: typeof allInvitesAtom,
|
||||
mDirects: Set<string>
|
||||
mDirects: Set<string>,
|
||||
) => {
|
||||
const selector = useCallback(
|
||||
(rooms: string[]) =>
|
||||
rooms.filter(
|
||||
(roomId) => mDirects.has(roomId) || isDirectInvite(mx.getRoom(roomId), mx.getUserId())
|
||||
(roomId) => mDirects.has(roomId) || isDirectInvite(mx.getRoom(roomId), mx.getUserId()),
|
||||
),
|
||||
[mx, mDirects]
|
||||
[mx, mDirects],
|
||||
);
|
||||
return useAtomValue(selectAtom(invitesAtom, selector, compareRoomsEqual));
|
||||
};
|
||||
@@ -49,7 +49,7 @@ export const useDirectInvites = (
|
||||
export const useUnsupportedInvites = (mx: MatrixClient, invitesAtom: typeof allInvitesAtom) => {
|
||||
const selector = useCallback(
|
||||
(rooms: string[]) => rooms.filter((roomId) => isUnsupportedRoom(mx.getRoom(roomId))),
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
return useAtomValue(selectAtom(invitesAtom, selector, compareRoomsEqual));
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ export type RoomSelector = (roomId: string) => boolean | undefined;
|
||||
|
||||
export const selectedRoomsAtom = (
|
||||
roomsAtom: RoomsAtom,
|
||||
selector: (roomId: string) => boolean | undefined
|
||||
selector: (roomId: string) => boolean | undefined,
|
||||
) => selectAtom(roomsAtom, (rooms) => rooms.filter(selector), compareRoomsEqual);
|
||||
|
||||
export const useSelectedRooms = (roomsAtom: RoomsAtom, selector: RoomSelector) => {
|
||||
@@ -24,55 +24,55 @@ export type SpaceChildSelectorFactory = (parentId: string) => RoomSelector;
|
||||
|
||||
export const useRecursiveChildScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
isRoom(mx.getRoom(roomId)) &&
|
||||
roomToParents.has(roomId) &&
|
||||
getAllParents(roomToParents, roomId).has(parentId),
|
||||
[mx, roomToParents]
|
||||
[mx, roomToParents],
|
||||
);
|
||||
|
||||
export const useChildSpaceScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
isSpace(mx.getRoom(roomId)) && roomToParents.get(roomId)?.has(parentId),
|
||||
[mx, roomToParents]
|
||||
[mx, roomToParents],
|
||||
);
|
||||
|
||||
export const useRecursiveChildSpaceScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
isSpace(mx.getRoom(roomId)) &&
|
||||
roomToParents.has(roomId) &&
|
||||
getAllParents(roomToParents, roomId).has(parentId),
|
||||
[mx, roomToParents]
|
||||
[mx, roomToParents],
|
||||
);
|
||||
|
||||
export const useChildRoomScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
mDirects: Set<string>,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
isRoom(mx.getRoom(roomId)) &&
|
||||
!mDirects.has(roomId) &&
|
||||
roomToParents.get(roomId)?.has(parentId),
|
||||
[mx, mDirects, roomToParents]
|
||||
[mx, mDirects, roomToParents],
|
||||
);
|
||||
|
||||
export const useRecursiveChildRoomScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
mDirects: Set<string>,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
@@ -80,26 +80,26 @@ export const useRecursiveChildRoomScopeFactory = (
|
||||
!mDirects.has(roomId) &&
|
||||
roomToParents.has(roomId) &&
|
||||
getAllParents(roomToParents, roomId).has(parentId),
|
||||
[mx, mDirects, roomToParents]
|
||||
[mx, mDirects, roomToParents],
|
||||
);
|
||||
|
||||
export const useChildDirectScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
mDirects: Set<string>,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
isRoom(mx.getRoom(roomId)) &&
|
||||
mDirects.has(roomId) &&
|
||||
roomToParents.get(roomId)?.has(parentId),
|
||||
[mx, mDirects, roomToParents]
|
||||
[mx, mDirects, roomToParents],
|
||||
);
|
||||
|
||||
export const useRecursiveChildDirectScopeFactory = (
|
||||
mx: MatrixClient,
|
||||
mDirects: Set<string>,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
): SpaceChildSelectorFactory =>
|
||||
useCallback(
|
||||
(parentId: string) => (roomId) =>
|
||||
@@ -107,17 +107,17 @@ export const useRecursiveChildDirectScopeFactory = (
|
||||
mDirects.has(roomId) &&
|
||||
roomToParents.has(roomId) &&
|
||||
getAllParents(roomToParents, roomId).has(parentId),
|
||||
[mx, mDirects, roomToParents]
|
||||
[mx, mDirects, roomToParents],
|
||||
);
|
||||
|
||||
export const useSpaceChildren = (
|
||||
roomsAtom: RoomsAtom,
|
||||
spaceId: string,
|
||||
selectorFactory: SpaceChildSelectorFactory
|
||||
selectorFactory: SpaceChildSelectorFactory,
|
||||
) => {
|
||||
const recursiveChildRoomSelector = useMemo(
|
||||
() => selectorFactory(spaceId),
|
||||
[selectorFactory, spaceId]
|
||||
[selectorFactory, spaceId],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, recursiveChildRoomSelector);
|
||||
};
|
||||
@@ -130,11 +130,11 @@ export const useSpaces = (mx: MatrixClient, roomsAtom: RoomsAtom) => {
|
||||
export const useOrphanSpaces = (
|
||||
mx: MatrixClient,
|
||||
roomsAtom: RoomsAtom,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
) => {
|
||||
const selector: RoomSelector = useCallback(
|
||||
(roomId) => isSpace(mx.getRoom(roomId)) && !roomToParents.has(roomId),
|
||||
[mx, roomToParents]
|
||||
[mx, roomToParents],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, selector);
|
||||
};
|
||||
@@ -142,7 +142,7 @@ export const useOrphanSpaces = (
|
||||
export const useRooms = (mx: MatrixClient, roomsAtom: RoomsAtom, mDirects: Set<string>) => {
|
||||
const selector: RoomSelector = useCallback(
|
||||
(roomId: string) => isRoom(mx.getRoom(roomId)) && !mDirects.has(roomId),
|
||||
[mx, mDirects]
|
||||
[mx, mDirects],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, selector);
|
||||
};
|
||||
@@ -151,11 +151,11 @@ export const useOrphanRooms = (
|
||||
mx: MatrixClient,
|
||||
roomsAtom: RoomsAtom,
|
||||
mDirects: Set<string>,
|
||||
roomToParents: RoomToParents
|
||||
roomToParents: RoomToParents,
|
||||
) => {
|
||||
const selector: RoomSelector = useCallback(
|
||||
(roomId) => isRoom(mx.getRoom(roomId)) && !mDirects.has(roomId) && !roomToParents.has(roomId),
|
||||
[mx, mDirects, roomToParents]
|
||||
[mx, mDirects, roomToParents],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, selector);
|
||||
};
|
||||
@@ -163,7 +163,7 @@ export const useOrphanRooms = (
|
||||
export const useDirects = (mx: MatrixClient, roomsAtom: RoomsAtom, mDirects: Set<string>) => {
|
||||
const selector: RoomSelector = useCallback(
|
||||
(roomId) => isRoom(mx.getRoom(roomId)) && mDirects.has(roomId),
|
||||
[mx, mDirects]
|
||||
[mx, mDirects],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, selector);
|
||||
};
|
||||
@@ -171,7 +171,7 @@ export const useDirects = (mx: MatrixClient, roomsAtom: RoomsAtom, mDirects: Set
|
||||
export const useUnsupportedRooms = (mx: MatrixClient, roomsAtom: RoomsAtom) => {
|
||||
const selector: RoomSelector = useCallback(
|
||||
(roomId) => isUnsupportedRoom(mx.getRoom(roomId)),
|
||||
[mx]
|
||||
[mx],
|
||||
);
|
||||
return useSelectedRooms(roomsAtom, selector);
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useOpenRoomSettings = (): OpenCallback => {
|
||||
(roomId, spaceId, page) => {
|
||||
setSettings({ roomId, spaceId, page });
|
||||
},
|
||||
[setSettings]
|
||||
[setSettings],
|
||||
);
|
||||
|
||||
return open;
|
||||
|
||||
@@ -15,7 +15,7 @@ export const useSetSetting = <K extends keyof Settings>(settingsAtom: typeof sAt
|
||||
s[key] = typeof value === 'function' ? value(s[key]) : value;
|
||||
set(settingsAtom, s);
|
||||
}),
|
||||
[settingsAtom, key]
|
||||
[settingsAtom, key],
|
||||
);
|
||||
|
||||
return useSetAtom(setterAtom);
|
||||
@@ -23,7 +23,7 @@ export const useSetSetting = <K extends keyof Settings>(settingsAtom: typeof sAt
|
||||
|
||||
export const useSetting = <K extends keyof Settings>(
|
||||
settingsAtom: typeof sAtom,
|
||||
key: K
|
||||
key: K,
|
||||
): [Settings[K], ReturnType<typeof useSetSetting<K>>] => {
|
||||
const selector = useMemo(() => (s: Settings) => s[key], [key]);
|
||||
const derivedAtom = useMemo(() => selectAtom(settingsAtom, selector), [settingsAtom, selector]);
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useOpenSpaceSettings = (): OpenCallback => {
|
||||
(roomId, spaceId, page) => {
|
||||
setSettings({ roomId, spaceId, page });
|
||||
},
|
||||
[setSettings]
|
||||
[setSettings],
|
||||
);
|
||||
|
||||
return open;
|
||||
|
||||
@@ -28,18 +28,18 @@ const getRoomsUnread = (rooms: string[], roomToUnread: RoomToUnread): Unread | u
|
||||
|
||||
export const useRoomsUnread = (
|
||||
rooms: string[],
|
||||
roomToUnreadAtm: typeof roomToUnreadAtom
|
||||
roomToUnreadAtm: typeof roomToUnreadAtom,
|
||||
): Unread | undefined => {
|
||||
const selector = useCallback(
|
||||
(roomToUnread: RoomToUnread) => getRoomsUnread(rooms, roomToUnread),
|
||||
[rooms]
|
||||
[rooms],
|
||||
);
|
||||
return useAtomValue(selectAtom(roomToUnreadAtm, selector, compareUnreadEqual));
|
||||
};
|
||||
|
||||
export const useRoomUnread = (
|
||||
roomId: string,
|
||||
roomToUnreadAtm: typeof roomToUnreadAtom
|
||||
roomToUnreadAtm: typeof roomToUnreadAtom,
|
||||
): Unread | undefined => {
|
||||
const selector = useCallback((roomToUnread: RoomToUnread) => roomToUnread.get(roomId), [roomId]);
|
||||
return useAtomValue(selectAtom(roomToUnreadAtm, selector, compareUnreadEqual));
|
||||
|
||||
@@ -25,7 +25,7 @@ type OpenCallback = (
|
||||
spaceId: string | undefined,
|
||||
userId: string,
|
||||
cords: RectCords,
|
||||
position?: Position
|
||||
position?: Position,
|
||||
) => void;
|
||||
export const useOpenUserRoomProfile = (): OpenCallback => {
|
||||
const setUserRoomProfile = useSetAtom(userRoomProfileAtom);
|
||||
@@ -34,7 +34,7 @@ export const useOpenUserRoomProfile = (): OpenCallback => {
|
||||
(roomId, spaceId, userId, cords, position) => {
|
||||
setUserRoomProfile({ roomId, spaceId, userId, cords, position });
|
||||
},
|
||||
[setUserRoomProfile]
|
||||
[setUserRoomProfile],
|
||||
);
|
||||
|
||||
return open;
|
||||
|
||||
@@ -25,7 +25,7 @@ export const createListAtom = <T>() => {
|
||||
if (action.type === 'DELETE') {
|
||||
set(
|
||||
baseListAtom,
|
||||
items.filter((item) => !newItems.includes(item))
|
||||
items.filter((item) => !newItems.includes(item)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -36,10 +36,10 @@ export const createListAtom = <T>() => {
|
||||
if (action.type === 'REPLACE') {
|
||||
set(
|
||||
baseListAtom,
|
||||
items.map((item) => (item === action.item ? action.replacement : item))
|
||||
items.map((item) => (item === action.item ? action.replacement : item)),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
export type TListAtom<T> = ReturnType<typeof createListAtom<T>>;
|
||||
|
||||
@@ -14,7 +14,7 @@ export const mDirectAtom = atom<Set<string>, [MDirectAction], undefined>(
|
||||
(get) => get(baseMDirectAtom),
|
||||
(get, set, action) => {
|
||||
set(baseMDirectAtom, action.rooms);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const useBindMDirectAtom = (mx: MatrixClient, mDirect: typeof mDirectAtom) => {
|
||||
|
||||
@@ -38,7 +38,7 @@ export const makeNavToActivePathAtom = (userId: string): NavToActivePathAtom =>
|
||||
(key, value) => {
|
||||
const obj: Record<string, Path> = Object.fromEntries(value);
|
||||
setLocalStorageItem(key, obj);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const navToActivePathAtom = atom<NavToActivePath, [NavToActivePathAction], undefined>(
|
||||
@@ -49,7 +49,7 @@ export const makeNavToActivePathAtom = (userId: string): NavToActivePathAtom =>
|
||||
baseNavToActivePathAtom,
|
||||
produce(get(baseNavToActivePathAtom), (draft) => {
|
||||
draft.delete(action.navId);
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -58,10 +58,10 @@ export const makeNavToActivePathAtom = (userId: string): NavToActivePathAtom =>
|
||||
baseNavToActivePathAtom,
|
||||
produce(get(baseNavToActivePathAtom), (draft) => {
|
||||
draft.set(action.navId, action.path);
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return navToActivePathAtom;
|
||||
|
||||
@@ -36,7 +36,7 @@ export const makeOpenedSidebarFolderAtom = (userId: string): OpenedSidebarFolder
|
||||
(key, value) => {
|
||||
const arrayValue = Array.from(value);
|
||||
setLocalStorageItem(key, arrayValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const openedSidebarFolderAtom = atom<Set<string>, [OpenedSidebarFolderAction], undefined>(
|
||||
@@ -47,7 +47,7 @@ export const makeOpenedSidebarFolderAtom = (userId: string): OpenedSidebarFolder
|
||||
baseOpenedSidebarFolderAtom,
|
||||
produce(get(baseOpenedSidebarFolderAtom), (draft) => {
|
||||
draft.delete(action.id);
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -56,10 +56,10 @@ export const makeOpenedSidebarFolderAtom = (userId: string): OpenedSidebarFolder
|
||||
baseOpenedSidebarFolderAtom,
|
||||
produce(get(baseOpenedSidebarFolderAtom), (draft) => {
|
||||
draft.add(action.id);
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return openedSidebarFolderAtom;
|
||||
|
||||
@@ -17,16 +17,16 @@ export const allInvitesAtom = atom<string[], [RoomsAction], undefined>(
|
||||
if (action.type === 'PUT') newIds.push(action.roomId);
|
||||
return newIds;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const useBindAllInvitesAtom = (
|
||||
mx: MatrixClient,
|
||||
allRooms: WritableAtom<string[], [RoomsAction], undefined>
|
||||
allRooms: WritableAtom<string[], [RoomsAction], undefined>,
|
||||
) => {
|
||||
useBindRoomsWithMembershipsAtom(
|
||||
mx,
|
||||
allRooms,
|
||||
useMemo(() => [Membership.Invite], [])
|
||||
useMemo(() => [Membership.Invite], []),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -17,12 +17,12 @@ export const allRoomsAtom = atom<string[], [RoomsAction], undefined>(
|
||||
if (action.type === 'PUT') newIds.push(action.roomId);
|
||||
return newIds;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
export const useBindAllRoomsAtom = (mx: MatrixClient, allRooms: typeof allRoomsAtom) => {
|
||||
useBindRoomsWithMembershipsAtom(
|
||||
mx,
|
||||
allRooms,
|
||||
useMemo(() => [Membership.Join], [])
|
||||
useMemo(() => [Membership.Join], []),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ export type RoomsAction =
|
||||
export const useBindRoomsWithMembershipsAtom = (
|
||||
mx: MatrixClient,
|
||||
roomsAtom: WritableAtom<string[], [RoomsAction], undefined>,
|
||||
memberships: Membership[]
|
||||
memberships: Membership[],
|
||||
) => {
|
||||
const setRoomsAtom = useSetAtom(roomsAtom);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export type RoomIdToMsgAction =
|
||||
const createMsgDraftAtom = () => atom<Descendant[]>([]);
|
||||
export type TMsgDraftAtom = ReturnType<typeof createMsgDraftAtom>;
|
||||
export const roomIdToMsgDraftAtomFamily = atomFamily<string, TMsgDraftAtom>(() =>
|
||||
createMsgDraftAtom()
|
||||
createMsgDraftAtom(),
|
||||
);
|
||||
|
||||
export type IReplyDraft = {
|
||||
@@ -52,5 +52,5 @@ export type IReplyDraft = {
|
||||
const createReplyDraftAtom = () => atom<IReplyDraft | undefined>(undefined);
|
||||
export type TReplyDraftAtom = ReturnType<typeof createReplyDraftAtom>;
|
||||
export const roomIdToReplyDraftAtomFamily = atomFamily<string, TReplyDraftAtom>(() =>
|
||||
createReplyDraftAtom()
|
||||
createReplyDraftAtom(),
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ export const roomToParentsAtom = atom<RoomToParents, [RoomToParentsAction], unde
|
||||
baseRoomToParents,
|
||||
produce(get(baseRoomToParents), (draftRoomToParents) => {
|
||||
mapParentWithChildren(draftRoomToParents, action.parent, action.children);
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -61,15 +61,15 @@ export const roomToParentsAtom = atom<RoomToParents, [RoomToParentsAction], unde
|
||||
if (parents.size === 0) noParentRooms.push(child);
|
||||
});
|
||||
noParentRooms.forEach((room) => draftRoomToParents.delete(room));
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const useBindRoomToParentsAtom = (
|
||||
mx: MatrixClient,
|
||||
roomToParents: typeof roomToParentsAtom
|
||||
roomToParents: typeof roomToParentsAtom,
|
||||
) => {
|
||||
const setRoomToParents = useSetAtom(roomToParents);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export const unreadInfoToUnread = (unreadInfo: UnreadInfo): Unread => ({
|
||||
const putUnreadInfo = (
|
||||
roomToUnread: RoomToUnread,
|
||||
allParents: Set<string>,
|
||||
unreadInfo: UnreadInfo
|
||||
unreadInfo: UnreadInfo,
|
||||
) => {
|
||||
const oldUnread = roomToUnread.get(unreadInfo.roomId) ?? { highlight: 0, total: 0, from: null };
|
||||
roomToUnread.set(unreadInfo.roomId, unreadInfoToUnread(unreadInfo));
|
||||
@@ -125,7 +125,7 @@ export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefin
|
||||
putUnreadInfo(
|
||||
draftRoomToUnread,
|
||||
getAllParents(get(roomToParentsAtom), unreadInfo.roomId),
|
||||
unreadInfo
|
||||
unreadInfo,
|
||||
);
|
||||
});
|
||||
set(baseRoomToUnread, draftRoomToUnread);
|
||||
@@ -145,9 +145,9 @@ export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefin
|
||||
putUnreadInfo(
|
||||
draftRoomToUnread,
|
||||
getAllParents(get(roomToParentsAtom), unreadInfo.roomId),
|
||||
unreadInfo
|
||||
)
|
||||
)
|
||||
unreadInfo,
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -158,12 +158,12 @@ export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefin
|
||||
deleteUnreadInfo(
|
||||
draftRoomToUnread,
|
||||
getAllParents(get(roomToParentsAtom), action.roomId),
|
||||
action.roomId
|
||||
)
|
||||
)
|
||||
action.roomId,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roomToUnreadAtom) => {
|
||||
@@ -191,8 +191,8 @@ export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roo
|
||||
});
|
||||
}
|
||||
},
|
||||
[mx, setUnreadAtom]
|
||||
)
|
||||
[mx, setUnreadAtom],
|
||||
),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -201,7 +201,7 @@ export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roo
|
||||
room: Room | undefined,
|
||||
toStartOfTimeline: boolean | undefined,
|
||||
removed: boolean,
|
||||
data: IRoomTimelineData
|
||||
data: IRoomTimelineData,
|
||||
) => {
|
||||
if (!room || !data.liveEvent || room.isSpaceRoom() || !isNotificationEvent(mEvent)) return;
|
||||
if (getNotificationType(mx, room.roomId) === NotificationType.Mute) {
|
||||
@@ -230,8 +230,8 @@ export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roo
|
||||
|
||||
const isMyReceipt = Object.keys(content).find((eventId) =>
|
||||
(Object.keys(content[eventId]) as ReceiptType[]).find(
|
||||
(receiptType) => content[eventId][receiptType][myUserId]
|
||||
)
|
||||
(receiptType) => content[eventId][receiptType][myUserId],
|
||||
),
|
||||
);
|
||||
if (isMyReceipt) {
|
||||
setUnreadAtom({ type: 'DELETE', roomId: room.roomId });
|
||||
@@ -276,7 +276,7 @@ export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roo
|
||||
});
|
||||
}
|
||||
},
|
||||
[mx, setUnreadAtom]
|
||||
)
|
||||
[mx, setUnreadAtom],
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ export function setFallbackSession(
|
||||
accessToken: string,
|
||||
deviceId: string,
|
||||
userId: string,
|
||||
baseUrl: string
|
||||
baseUrl: string,
|
||||
) {
|
||||
localStorage.setItem('cinny_access_token', accessToken);
|
||||
localStorage.setItem('cinny_device_id', deviceId);
|
||||
|
||||
@@ -144,5 +144,5 @@ export const settingsAtom = atom<Settings, [Settings], undefined>(
|
||||
(get, set, update) => {
|
||||
set(baseSettings, update);
|
||||
setSettings(update);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ const baseSpaceRoomsAtom = atomWithLocalStorage<Set<string>>(
|
||||
(key, value) => {
|
||||
const arrayValue = Array.from(value);
|
||||
setLocalStorageItem(key, arrayValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
type SpaceRoomsAction =
|
||||
@@ -41,7 +41,7 @@ export const spaceRoomsAtom = atom<Set<string>, [SpaceRoomsAction], undefined>(
|
||||
baseSpaceRoomsAtom,
|
||||
produce(current, (draft) => {
|
||||
roomIds.forEach((roomId) => draft.delete(roomId));
|
||||
})
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -52,8 +52,8 @@ export const spaceRoomsAtom = atom<Set<string>, [SpaceRoomsAction], undefined>(
|
||||
baseSpaceRoomsAtom,
|
||||
produce(current, (draft) => {
|
||||
newEntries.forEach((roomId) => draft.add(roomId));
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -30,7 +30,7 @@ const baseRoomIdToTypingMembersAtom = atom<IRoomIdToTypingMembers>(new Map());
|
||||
|
||||
const putTypingMember = (
|
||||
roomToMembers: IRoomIdToTypingMembers,
|
||||
action: TypingMemberPutAction
|
||||
action: TypingMemberPutAction,
|
||||
): IRoomIdToTypingMembers => {
|
||||
let typingMembers = roomToMembers.get(action.roomId) ?? [];
|
||||
|
||||
@@ -45,7 +45,7 @@ const putTypingMember = (
|
||||
|
||||
const deleteTypingMember = (
|
||||
roomToMembers: IRoomIdToTypingMembers,
|
||||
action: TypingMemberDeleteAction
|
||||
action: TypingMemberDeleteAction,
|
||||
): IRoomIdToTypingMembers => {
|
||||
let typingMembers = roomToMembers.get(action.roomId) ?? [];
|
||||
|
||||
@@ -62,7 +62,7 @@ const timeoutReceipt = (
|
||||
roomToMembers: IRoomIdToTypingMembers,
|
||||
roomId: string,
|
||||
userId: string,
|
||||
timeout: number
|
||||
timeout: number,
|
||||
): boolean | undefined => {
|
||||
const typingMembers = roomToMembers.get(roomId) ?? [];
|
||||
|
||||
@@ -84,7 +84,7 @@ export const roomIdToTypingMembersAtom = atom<
|
||||
if (action.type === 'PUT') {
|
||||
set(
|
||||
baseRoomIdToTypingMembersAtom,
|
||||
produce(rToTyping, (draft) => putTypingMember(draft, action))
|
||||
produce(rToTyping, (draft) => putTypingMember(draft, action)),
|
||||
);
|
||||
|
||||
// remove typing receipt after some timeout
|
||||
@@ -101,7 +101,7 @@ export const roomIdToTypingMembersAtom = atom<
|
||||
get(baseRoomIdToTypingMembersAtom),
|
||||
roomId,
|
||||
userId,
|
||||
TYPING_TIMEOUT_MS
|
||||
TYPING_TIMEOUT_MS,
|
||||
);
|
||||
if (timeout) {
|
||||
set(
|
||||
@@ -111,11 +111,11 @@ export const roomIdToTypingMembersAtom = atom<
|
||||
type: 'DELETE',
|
||||
roomId,
|
||||
userId,
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}, TYPING_TIMEOUT_MS)
|
||||
}, TYPING_TIMEOUT_MS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,15 +125,15 @@ export const roomIdToTypingMembersAtom = atom<
|
||||
) {
|
||||
set(
|
||||
baseRoomIdToTypingMembersAtom,
|
||||
produce(rToTyping, (draft) => deleteTypingMember(draft, action))
|
||||
produce(rToTyping, (draft) => deleteTypingMember(draft, action)),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const useBindRoomIdToTypingMembersAtom = (
|
||||
mx: MatrixClient,
|
||||
typingMembersAtom: typeof roomIdToTypingMembersAtom
|
||||
typingMembersAtom: typeof roomIdToTypingMembersAtom,
|
||||
) => {
|
||||
const setTypingMembers = useSetAtom(typingMembersAtom);
|
||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||
@@ -141,7 +141,7 @@ export const useBindRoomIdToTypingMembersAtom = (
|
||||
useEffect(() => {
|
||||
const handleTypingEvent: RoomMemberEventHandlerMap[RoomMemberEvent.Typing] = (
|
||||
event,
|
||||
member
|
||||
member,
|
||||
) => {
|
||||
if (hideActivity) {
|
||||
return;
|
||||
|
||||
@@ -92,7 +92,7 @@ export const createUploadAtom = (file: TUploadContent) => {
|
||||
error: update.error,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
export type TUploadAtom = ReturnType<typeof createUploadAtom>;
|
||||
@@ -100,14 +100,14 @@ export type TUploadAtom = ReturnType<typeof createUploadAtom>;
|
||||
export const useBindUploadAtom = (
|
||||
mx: MatrixClient,
|
||||
uploadAtom: TUploadAtom,
|
||||
hideFilename?: boolean
|
||||
hideFilename?: boolean,
|
||||
) => {
|
||||
const [upload, setUpload] = useAtom(uploadAtom);
|
||||
const { file } = upload;
|
||||
|
||||
const handleProgress = useThrottle(
|
||||
useCallback((progress: UploadProgress) => setUpload({ progress }), [setUpload]),
|
||||
{ immediate: true, wait: 200 }
|
||||
{ immediate: true, wait: 200 },
|
||||
);
|
||||
|
||||
const startUpload = useCallback(
|
||||
@@ -119,7 +119,7 @@ export const useBindUploadAtom = (
|
||||
onSuccess: (mxc) => setUpload({ mxc }),
|
||||
onError: (error) => setUpload({ error }),
|
||||
}),
|
||||
[mx, file, hideFilename, setUpload, handleProgress]
|
||||
[mx, file, hideFilename, setUpload, handleProgress],
|
||||
);
|
||||
|
||||
const cancelUpload = useCallback(async () => {
|
||||
@@ -141,6 +141,6 @@ export type TUploadAtomFamily = ReturnType<typeof createUploadAtomFamily>;
|
||||
|
||||
export const createUploadFamilyObserverAtom = (
|
||||
uploadFamily: TUploadAtomFamily,
|
||||
uploads: TUploadContent[]
|
||||
uploads: TUploadContent[],
|
||||
) => atom<Upload[]>((get) => uploads.map((upload) => get(uploadFamily(upload))));
|
||||
export type TUploadFamilyObserverAtom = ReturnType<typeof createUploadFamilyObserverAtom>;
|
||||
|
||||
@@ -21,7 +21,7 @@ export type SetLocalStorageItem<T> = (key: string, value: T) => void;
|
||||
export const atomWithLocalStorage = <T>(
|
||||
key: string,
|
||||
getItem: GetLocalStorageItem<T>,
|
||||
setItem: SetLocalStorageItem<T>
|
||||
setItem: SetLocalStorageItem<T>,
|
||||
) => {
|
||||
const value = getItem(key);
|
||||
|
||||
@@ -44,7 +44,7 @@ export const atomWithLocalStorage = <T>(
|
||||
(get, set, newValue) => {
|
||||
set(baseAtom, newValue);
|
||||
setItem(key, newValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return localStorageAtom;
|
||||
|
||||
Reference in New Issue
Block a user