diff --git a/.github/workflows/release/reviewers.json b/.github/workflows/release/reviewers.json index dd339abc1..35bfa9e3e 100644 --- a/.github/workflows/release/reviewers.json +++ b/.github/workflows/release/reviewers.json @@ -1,13 +1,8 @@ { "packages/react-native/src/**/*": { - "users": [ - "techwritermat", - "are" - ] + "users": ["techwritermat", "are"] }, "packages/react/src/**/*.ts": { - "users": [ - "parfeon" - ] + "users": ["parfeon"] } -} \ No newline at end of file +} diff --git a/packages/common/src/channel-list/channel-list.tsx b/packages/common/src/channel-list/channel-list.tsx index 47c25125a..062feb0dd 100644 --- a/packages/common/src/channel-list/channel-list.tsx +++ b/packages/common/src/channel-list/channel-list.tsx @@ -40,7 +40,7 @@ export const useChannelListCore = (props: CommonChannelListProps) => { const channelSorter = (a: ChannelEntity, b: ChannelEntity) => { if (props.sort) return props.sort(a, b); - return a?.name?.localeCompare(b.name as string, "en", { sensitivity: "base" }); + return a?.name?.localeCompare(b.name as string, "en", { sensitivity: "base" }) as number; }; const channelFromString = (channel: ChannelEntity | string) => { @@ -48,7 +48,7 @@ export const useChannelListCore = (props: CommonChannelListProps) => { return { id: channel, name: channel, - }; + } as ChannelEntity; } return channel; }; diff --git a/packages/common/src/helpers.ts b/packages/common/src/helpers.ts index 7070b4db4..03a4ed3d2 100644 --- a/packages/common/src/helpers.ts +++ b/packages/common/src/helpers.ts @@ -8,7 +8,7 @@ export const getNameInitials = (name: string): string => { return initials.toUpperCase(); }; -export const getPredefinedColor = (uuid: string): string => { +export const getPredefinedColor = (uuid: string): string | undefined => { if (!uuid || !uuid.length) return; const colors = ["#80deea", "#9fa7df", "#aed581", "#ce93d8", "#ef9a9a", "#ffab91", "#ffe082"]; const sum = uuid diff --git a/packages/common/src/hooks/use-channel-members.ts b/packages/common/src/hooks/use-channel-members.ts index 19bfd1bd9..39aff67dc 100644 --- a/packages/common/src/hooks/use-channel-members.ts +++ b/packages/common/src/hooks/use-channel-members.ts @@ -1,5 +1,5 @@ import { useState, useEffect, useMemo } from "react"; -import { GetChannelMembersParameters } from "pubnub"; +import { GetChannelMembersParameters, ObjectsEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { merge, cloneDeep } from "lodash"; import { UserEntity } from "../types"; @@ -55,11 +55,11 @@ export const useChannelMembers = (options: GetChannelMembersParameters): HookRet ...members, ...(response.data.map((m) => m.uuid) as UserEntity[]), ]); - setTotalCount(response.totalCount); - setPage(response.next); + setTotalCount(response.totalCount || 0); + setPage(response.next || ""); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -70,7 +70,7 @@ export const useChannelMembers = (options: GetChannelMembersParameters): HookRet useEffect(() => { const listener = { - objects: (event) => { + objects: (event: ObjectsEvent) => { const message = event.message; if (message.type !== "membership") return; @@ -99,5 +99,5 @@ export const useChannelMembers = (options: GetChannelMembersParameters): HookRet }; }, [pubnub, paginatedOptions.channel]); - return [members, fetchMoreMembers, resetHook, totalCount, error]; + return [members, fetchMoreMembers, resetHook, totalCount, error as Error]; }; diff --git a/packages/common/src/hooks/use-channels.ts b/packages/common/src/hooks/use-channels.ts index 774b4d61d..977e2c8e0 100644 --- a/packages/common/src/hooks/use-channels.ts +++ b/packages/common/src/hooks/use-channels.ts @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { GetAllMetadataParameters } from "pubnub"; +import { GetAllMetadataParameters, ObjectsEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { merge, cloneDeep } from "lodash"; import { ChannelEntity } from "../types"; @@ -10,7 +10,7 @@ export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnV const pubnub = usePubNub(); const [channels, setChannels] = useState([]); - const [page, setPage] = useState(""); + const [page, setPage] = useState(""); const [totalCount, setTotalCount] = useState(0); const [error, setError] = useState(); const [doFetch, setDoFetch] = useState(true); @@ -35,11 +35,11 @@ export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnV if (ignoreRequest) return; setDoFetch(false); setChannels((channels) => [...channels, ...response.data]); - setTotalCount(response.totalCount); + setTotalCount(response.totalCount || 0); setPage(response.next); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -50,7 +50,7 @@ export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnV useEffect(() => { const listener = { - objects: (event) => { + objects: (event: ObjectsEvent) => { const message = event.message; if (message.type !== "channel") return; @@ -79,5 +79,5 @@ export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnV }; }, [pubnub]); - return [channels, fetchMoreChannels, totalCount, error]; + return [channels, fetchMoreChannels, totalCount, error as Error]; }; diff --git a/packages/common/src/hooks/use-messages.ts b/packages/common/src/hooks/use-messages.ts index 4a48b6bd5..f99007bbc 100644 --- a/packages/common/src/hooks/use-messages.ts +++ b/packages/common/src/hooks/use-messages.ts @@ -1,3 +1,6 @@ +// This file is unused so there is no need to keep it ts-checked +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck import { useState, useEffect, useRef } from "react"; import { FetchMessagesParameters, MessageActionEvent, MessageEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; diff --git a/packages/common/src/hooks/use-presence.ts b/packages/common/src/hooks/use-presence.ts index 6e2de4db4..7cd1b8a4e 100644 --- a/packages/common/src/hooks/use-presence.ts +++ b/packages/common/src/hooks/use-presence.ts @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { HereNowParameters, HereNowResponse } from "pubnub"; +import { HereNowParameters, HereNowResponse, PresenceEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { cloneDeep } from "lodash"; @@ -39,7 +39,7 @@ export const usePresence = (options: HereNowParameters = {}): HookReturnValue => setPresence(response.channels); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -50,7 +50,7 @@ export const usePresence = (options: HereNowParameters = {}): HookReturnValue => useEffect(() => { const listener = { - presence: (event) => { + presence: (event: PresenceEvent) => { setPresence((presence) => { const presenceClone = cloneDeep(presence); if (!presenceClone[event.channel]) @@ -97,5 +97,5 @@ export const usePresence = (options: HereNowParameters = {}): HookReturnValue => }; }, [pubnub, options.includeUUIDs]); - return [presence, resetHook, total, error]; + return [presence, resetHook, total, error as Error]; }; diff --git a/packages/common/src/hooks/use-subscribe.ts b/packages/common/src/hooks/use-subscribe.ts index 44b784091..f5b6be7e0 100644 --- a/packages/common/src/hooks/use-subscribe.ts +++ b/packages/common/src/hooks/use-subscribe.ts @@ -17,10 +17,14 @@ export const useSubscribe = (options: SubscribeParameters = {}): (() => void) => const currentGroups = pubnub.getSubscribedChannelGroups() || []; const subscribeChannels = options.channels.filter((c) => !currentSubscriptions.includes(c)); - const unsubscribeChannels = currentSubscriptions.filter((c) => !options.channels.includes(c)); + const unsubscribeChannels = currentSubscriptions.filter( + (c) => !(options.channels as string[]).includes(c) + ); const subscribeGroups = options.channelGroups.filter((c) => !currentGroups.includes(c)); - const unsubscribeGroups = currentGroups.filter((c) => !options.channelGroups.includes(c)); + const unsubscribeGroups = currentGroups.filter( + (c) => !(options.channelGroups as string[]).includes(c) + ); if (subscribeChannels.length || subscribeGroups.length) { pubnub.subscribe({ diff --git a/packages/common/src/hooks/use-user-memberships.ts b/packages/common/src/hooks/use-user-memberships.ts index 88185c3f9..1aca7146c 100644 --- a/packages/common/src/hooks/use-user-memberships.ts +++ b/packages/common/src/hooks/use-user-memberships.ts @@ -1,18 +1,18 @@ import { useState, useEffect, useMemo } from "react"; -import { GetMembershipsParametersv2 } from "pubnub"; +import { GetMembershipsParametersv2, ObjectsEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { merge, cloneDeep } from "lodash"; import { ChannelEntity } from "../types"; -type HookReturnValue = [ChannelEntity[], () => void, () => void, number, Error]; +type HookReturnValue = [ChannelEntity[], () => void, () => void, number | undefined, Error]; export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): HookReturnValue => { const jsonOptions = JSON.stringify(options); const pubnub = usePubNub(); const [channels, setChannels] = useState([]); - const [totalCount, setTotalCount] = useState(0); - const [page, setPage] = useState(""); + const [totalCount, setTotalCount] = useState(0); + const [page, setPage] = useState(""); const [error, setError] = useState(); const [doFetch, setDoFetch] = useState(true); @@ -59,7 +59,7 @@ export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): Ho setPage(response.next); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -70,7 +70,7 @@ export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): Ho useEffect(() => { const listener = { - objects: (event) => { + objects: (event: ObjectsEvent) => { const message = event.message; if (message.type !== "membership") return; @@ -100,5 +100,5 @@ export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): Ho }; }, [pubnub, paginatedOptions.uuid]); - return [channels, fetchMoreMemberships, resetHook, totalCount, error]; + return [channels, fetchMoreMemberships, resetHook, totalCount, error as Error]; }; diff --git a/packages/common/src/hooks/use-user.ts b/packages/common/src/hooks/use-user.ts index d39dd37e5..a1c286bd0 100644 --- a/packages/common/src/hooks/use-user.ts +++ b/packages/common/src/hooks/use-user.ts @@ -1,14 +1,14 @@ import { useState, useEffect } from "react"; -import { GetUUIDMetadataParameters } from "pubnub"; +import { GetUUIDMetadataParameters, ObjectsEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { cloneDeep } from "lodash"; import { UserEntity } from "../types"; -export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, Error] => { +export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity | null, Error] => { const jsonOptions = JSON.stringify(options); const pubnub = usePubNub(); - const [user, setUser] = useState(null); + const [user, setUser] = useState(null); const [error, setError] = useState(); const [doFetch, setDoFetch] = useState(true); @@ -34,7 +34,7 @@ export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, E setUser(response.data); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -45,14 +45,14 @@ export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, E useEffect(() => { const listener = { - objects: (event) => { + objects: (event: ObjectsEvent) => { const message = event.message; if (message.type !== "uuid") return; setUser((user) => { const userCopy = cloneDeep(user); - if (message.data.id == user.id) { + if (message.data.id == userCopy?.id) { Object.assign(userCopy, message.data); } @@ -68,5 +68,5 @@ export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, E }; }, [pubnub]); - return [user, error]; + return [user, error as Error]; }; diff --git a/packages/common/src/hooks/use-users.ts b/packages/common/src/hooks/use-users.ts index 2e0f1a133..9c8cc8983 100644 --- a/packages/common/src/hooks/use-users.ts +++ b/packages/common/src/hooks/use-users.ts @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { GetAllMetadataParameters } from "pubnub"; +import { GetAllMetadataParameters, ObjectsEvent } from "pubnub"; import { usePubNub } from "pubnub-react"; import { merge, cloneDeep } from "lodash"; import { UserEntity } from "../types"; @@ -35,11 +35,11 @@ export const useUsers = (options: GetAllMetadataParameters = {}): HookReturnValu if (ignoreRequest) return; setDoFetch(false); setUsers((users) => [...users, ...response.data]); - setTotalCount(response.totalCount); - setPage(response.next); + setTotalCount(response.totalCount || 0); + setPage(response.next || ""); } catch (e) { setDoFetch(false); - setError(e); + setError(e as Error); } } @@ -50,7 +50,7 @@ export const useUsers = (options: GetAllMetadataParameters = {}): HookReturnValu useEffect(() => { const listener = { - objects: (event) => { + objects: (event: ObjectsEvent) => { const message = event.message; if (message.type !== "uuid") return; @@ -79,5 +79,5 @@ export const useUsers = (options: GetAllMetadataParameters = {}): HookReturnValu }; }, [pubnub]); - return [users, fetchMoreUsers, totalCount, error]; + return [users, fetchMoreUsers, totalCount, error as Error]; }; diff --git a/packages/common/src/member-list/member-list.tsx b/packages/common/src/member-list/member-list.tsx index dba5a8e76..c3faf07be 100644 --- a/packages/common/src/member-list/member-list.tsx +++ b/packages/common/src/member-list/member-list.tsx @@ -46,7 +46,7 @@ export const useMemberListCore = (props: CommonMemberListProps) => { return props.presentMembers?.includes(uuid); }; - const memberSorter = (a, b) => { + const memberSorter = (a: UserEntity, b: UserEntity) => { if (props.sort) return props.sort(a, b); if (isOwnMember(a.id)) return -1; @@ -55,7 +55,7 @@ export const useMemberListCore = (props: CommonMemberListProps) => { if (isPresentMember(a.id) && !isPresentMember(b.id)) return -1; if (isPresentMember(b.id) && !isPresentMember(a.id)) return 1; - return a.name.localeCompare(b.name, "en", { sensitivity: "base" }); + return a.name?.localeCompare(b.name as string, "en", { sensitivity: "base" }); }; const memberFromString = (member: UserEntity | string) => { diff --git a/packages/common/src/message-input/message-input.tsx b/packages/common/src/message-input/message-input.tsx index b2b235f94..57c24a9c9 100644 --- a/packages/common/src/message-input/message-input.tsx +++ b/packages/common/src/message-input/message-input.tsx @@ -47,7 +47,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { const pubnub = usePubNub(); const [text, setText] = useState(props.draftMessage || ""); - const [file, setFile] = useState(null); + const [file, setFile] = useState(null); const [typingIndicatorSent, setTypingIndicatorSent] = useState(false); const [loader, setLoader] = useState(false); const [users] = useAtom(UsersMetaAtom); @@ -92,7 +92,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { if (props.typingIndicator) stopTypingIndicator(); clearInput(); } catch (e) { - onError(e); + onError(e as Error); } finally { setLoader(false); } @@ -105,7 +105,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { const message = { message: { type: "typing_on" }, channel }; pubnub.signal(message); } catch (e) { - onError(e); + onError(e as Error); } }; @@ -116,7 +116,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { const message = { message: { type: "typing_off" }, channel }; pubnub.signal(message); } catch (e) { - onError(e); + onError(e as Error); } }; @@ -137,17 +137,19 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { props.onChange && props.onChange(newText); setText(newText); } catch (e) { - onError(e); + onError(e as Error); } }; const handleFileChange = (event: ChangeEvent) => { try { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore const file = event.target.files[0]; setFile(file); setText(file.name); } catch (e) { - onError(e); + onError(e as Error); } }; @@ -155,7 +157,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { /* Lifecycle */ useEffect(() => { - let timer = null; + let timer: ReturnType | null = null; if (typingIndicatorSent) { timer = setTimeout(() => { @@ -163,7 +165,7 @@ export const useMessageInputCore = (props: CommonMessageInputProps) => { }, (typingIndicatorTimeout - 1) * 1000); } - return () => clearTimeout(timer); + return () => clearTimeout(timer as ReturnType); }, [typingIndicatorSent, typingIndicatorTimeout]); return { diff --git a/packages/common/src/message-list/message-list.tsx b/packages/common/src/message-list/message-list.tsx index c075810ae..a93175313 100644 --- a/packages/common/src/message-list/message-list.tsx +++ b/packages/common/src/message-list/message-list.tsx @@ -107,14 +107,14 @@ export const useMessageListCore = (props: CommonMessageListProps) => { try { const url = pubnub.getFileUrl({ - channel: envelope.channel, + channel: envelope.channel as string, id: envelope.message.file.id, name: envelope.message.file.name, }); envelope.message.file.url = url; } catch (e) { - onError(e); + onError(e as Error); } finally { return envelope; } @@ -146,7 +146,7 @@ export const useMessageListCore = (props: CommonMessageListProps) => { !response.more && (!allMessages.length || newMessages.length !== props.fetchMessages) ); } catch (e) { - onError(e); + onError(e as Error); } finally { setFetchingMessages(false); } @@ -163,7 +163,7 @@ export const useMessageListCore = (props: CommonMessageListProps) => { setPaginationEnd, ]); - const addReaction = (reaction: string, messageTimetoken) => { + const addReaction = (reaction: string, messageTimetoken: string) => { try { pubnub.addMessageAction({ channel, @@ -174,15 +174,15 @@ export const useMessageListCore = (props: CommonMessageListProps) => { }, }); } catch (e) { - onError(e); + onError(e as Error); } }; - const removeReaction = (reaction: string, messageTimetoken, actionTimetoken) => { + const removeReaction = (reaction: string, messageTimetoken: string, actionTimetoken: string) => { try { pubnub.removeMessageAction({ channel, messageTimetoken, actionTimetoken }); } catch (e) { - onError(e); + onError(e as Error); } }; diff --git a/packages/common/src/state-atoms.ts b/packages/common/src/state-atoms.ts index 92a0adea6..9d86893dc 100644 --- a/packages/common/src/state-atoms.ts +++ b/packages/common/src/state-atoms.ts @@ -8,11 +8,13 @@ export const SubscribeChannelGroupsAtom = atom([]); export const UsersMetaAtom = atom([]); export const MessagesAtom = atom<{ [channel: string]: MessageEnvelope[] }>({}); export const PaginationAtom = atom<{ [channel: string]: boolean }>({}); -export const TypingIndicatorAtom = atom({}); +export const TypingIndicatorAtom = atom<{ [key: string]: string }>({}); export const TypingIndicatorTimeoutAtom = atom(10); -export const RetryFunctionAtom = atom<{ function: (fn: () => Promise) => Promise }>({ - function: () => null, +export const RetryFunctionAtom = atom<{ + function: (fn: () => Promise) => Promise; +}>({ + function: () => Promise.resolve(null) as never, }); export const ErrorFunctionAtom = atom<{ function: (error: Error) => unknown }>({ @@ -34,7 +36,7 @@ export const CurrentChannelPaginationAtom = atom( ) ); -export const CurrentChannelTypingIndicatorAtom = atom( +export const CurrentChannelTypingIndicatorAtom = atom<{ [key: string]: string }, unknown>( (get) => get(TypingIndicatorAtom)[get(CurrentChannelAtom)] || {}, (get, set, value) => set( diff --git a/packages/common/src/typing-indicator/typing-indicator.tsx b/packages/common/src/typing-indicator/typing-indicator.tsx index 3e36a6ef5..33d3005ea 100644 --- a/packages/common/src/typing-indicator/typing-indicator.tsx +++ b/packages/common/src/typing-indicator/typing-indicator.tsx @@ -27,7 +27,7 @@ export const useTypingIndicatorCore = (props: CommonTypingIndicatorProps) => { const [users] = useAtom(UsersMetaAtom); const [typingIndicators] = useAtom(CurrentChannelTypingIndicatorAtom); const [typingIndicatorTimeout] = useAtom(TypingIndicatorTimeoutAtom); - const [activeUUIDs, setActiveUUIDs] = useState([]); + const [activeUUIDs, setActiveUUIDs] = useState([]); const typingIndicatorsRef = useRef(typingIndicators); if (!isEqual(typingIndicatorsRef.current, typingIndicators)) { diff --git a/packages/common/test/use-channel-members.test.tsx b/packages/common/test/use-channel-members.test.tsx index 90c9dc055..7910d9b3f 100644 --- a/packages/common/test/use-channel-members.test.tsx +++ b/packages/common/test/use-channel-members.test.tsx @@ -6,8 +6,11 @@ import { useChannelMembers } from "../src/hooks"; import { PubNubMock } from "../mock/pubnub-mock"; import users from "../../../data/users/users.json"; -const pubnub = new PubNubMock({}); -const wrapper = ({ children }) => {children}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const pubnub = new (PubNubMock as any)({}); +const wrapper = ({ children }: { children: React.ReactNode | React.ReactNode[] | null }) => ( + {children} +); describe("useChannelMembers", () => { test("fetches and returns the full list of memberships", async () => { diff --git a/packages/common/test/use-channels.test.tsx b/packages/common/test/use-channels.test.tsx index d797518ed..147455926 100644 --- a/packages/common/test/use-channels.test.tsx +++ b/packages/common/test/use-channels.test.tsx @@ -6,8 +6,11 @@ import { useChannels } from "../src/hooks"; import { PubNubMock } from "../mock/pubnub-mock"; import channels from "../../../data/channels/work.json"; -const pubnub = new PubNubMock({}); -const wrapper = ({ children }) => {children}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const pubnub = new (PubNubMock as any)({}); +const wrapper = ({ children }: { children: React.ReactNode | React.ReactNode[] | null }) => ( + {children} +); describe("useChannels", () => { test("fetches and returns the full list of channels", async () => { diff --git a/packages/common/test/use-presence.test.tsx b/packages/common/test/use-presence.test.tsx index cac52e476..43ce7b63e 100644 --- a/packages/common/test/use-presence.test.tsx +++ b/packages/common/test/use-presence.test.tsx @@ -6,8 +6,11 @@ import { usePresence } from "../src/hooks"; import { PubNubMock } from "../mock/pubnub-mock"; import users from "../../../data/users/users.json"; -const pubnub = new PubNubMock({}); -const wrapper = ({ children }) => {children}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const pubnub = new (PubNubMock as any)({}); +const wrapper = ({ children }: { children: React.ReactNode | React.ReactNode[] | null }) => ( + {children} +); describe("usePresence", () => { test("fetches and returns presence data for a single channel", async () => { diff --git a/packages/common/test/use-user-memberships.test.tsx b/packages/common/test/use-user-memberships.test.tsx index 02c4fd035..d7a09dbca 100644 --- a/packages/common/test/use-user-memberships.test.tsx +++ b/packages/common/test/use-user-memberships.test.tsx @@ -6,8 +6,11 @@ import { useUserMemberships } from "../src/hooks"; import { PubNubMock } from "../mock/pubnub-mock"; import channels from "../../../data/channels/work.json"; -const pubnub = new PubNubMock({}); -const wrapper = ({ children }) => {children}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const pubnub = new (PubNubMock as any)({}); +const wrapper = ({ children }: { children: React.ReactNode | React.ReactNode[] | null }) => ( + {children} +); describe("useUserMemberships", () => { test("fetches and returns the full list of memberships", async () => { diff --git a/packages/common/test/use-user.test.tsx b/packages/common/test/use-user.test.tsx index 54b49acef..217fc59eb 100644 --- a/packages/common/test/use-user.test.tsx +++ b/packages/common/test/use-user.test.tsx @@ -6,8 +6,11 @@ import { useUser } from "../src/hooks"; import { PubNubMock } from "../mock/pubnub-mock"; import users from "../../../data/users/users.json"; -const pubnub = new PubNubMock({}); -const wrapper = ({ children }) => {children}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const pubnub = new (PubNubMock as any)({}); +const wrapper = ({ children }: { children: React.ReactNode | React.ReactNode[] | null }) => ( + {children} +); describe("useUser", () => { test("fetches and returns given user", async () => { diff --git a/packages/react/src/message-list/message-list.tsx b/packages/react/src/message-list/message-list.tsx index 75eee8be4..7bb736e95 100644 --- a/packages/react/src/message-list/message-list.tsx +++ b/packages/react/src/message-list/message-list.tsx @@ -298,8 +298,12 @@ export const MessageList: FC = (props: MessageListProps) => { data-tooltip={tooltipContent} onClick={() => { userReaction - ? removeReaction(reaction, envelope.timetoken, userReaction.actionTimetoken) - : addReaction(reaction, envelope.timetoken); + ? removeReaction( + reaction, + envelope.timetoken as string, + userReaction.actionTimetoken as string + ) + : addReaction(reaction, envelope.timetoken as string); }} > {reaction} {instancesLimited.length} diff --git a/samples/react/group-chat/src/components/create-chat-modal.tsx b/samples/react/group-chat/src/components/create-chat-modal.tsx index 8c8ce1281..03fa6e89f 100644 --- a/samples/react/group-chat/src/components/create-chat-modal.tsx +++ b/samples/react/group-chat/src/components/create-chat-modal.tsx @@ -10,7 +10,7 @@ import { interface CreateChatModalProps { users: UserEntity[]; - currentUser: UserEntity; + currentUser: UserEntity | null; setCurrentChannel: (channel: Pick) => void; hideModal: () => void; } @@ -59,11 +59,11 @@ export const CreateChatModal = ({ if (user) { /** 1-on-1 chat */ const users = [currentUser, user]; - uuids = users.map((m) => m.id).sort(); + uuids = users.map((m) => m?.id).sort(); channel = `direct.${uuids.join("@")}`; remoteData = { name: users - .map((m) => m.name) + .map((m) => m?.name) .sort() .join(" and "), custom, @@ -75,12 +75,12 @@ export const CreateChatModal = ({ } else { /** Group chat */ const users = [currentUser, ...selectedUsers]; - uuids = users.map((m) => m.id).sort(); + uuids = users.map((m) => m?.id).sort(); channel = `group.${randomHex}`; const name = channelName || users - .map((m) => m.name?.split(" ")[0]) + .map((m) => m?.name?.split(" ")[0]) .sort() .join(", "); remoteData = { name, custom }; @@ -88,6 +88,8 @@ export const CreateChatModal = ({ } await pubnub.objects.setChannelMetadata({ channel, data: remoteData }); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore await pubnub.objects.setChannelMembers({ channel, uuids }); setCurrentChannel({ id: channel, ...localData }); setCreatingChannel(false); diff --git a/samples/react/group-chat/src/moderated-chat.tsx b/samples/react/group-chat/src/moderated-chat.tsx index b398df655..b4e655f3b 100644 --- a/samples/react/group-chat/src/moderated-chat.tsx +++ b/samples/react/group-chat/src/moderated-chat.tsx @@ -15,6 +15,7 @@ import { useChannelMembers, useChannels, usePresence, + UserEntity, useUser, useUserMemberships, useUsers, @@ -188,7 +189,7 @@ export default function ModeratedChat(): JSX.Element { {showReportUserModal && ( setShowReportUserModal(false), users: allUsers,