diff --git a/.releaserc.json b/.releaserc.json index b6a2f3330..6122b357a 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -72,9 +72,11 @@ } ], [ - "@semantic-release/exec", { - "prepareCmd": "NEXT_VERSION=${nextRelease.version} npm run build" - }], + "@semantic-release/exec", + { + "prepareCmd": "NEXT_VERSION=${nextRelease.version} npm run build" + } + ], [ "@semantic-release/changelog", { diff --git a/docusaurus/react_versioned_sidebars/version-11.x.x-sidebars.json b/docusaurus/react_versioned_sidebars/version-11.x.x-sidebars.json index dfa7e279c..8f084dc97 100644 --- a/docusaurus/react_versioned_sidebars/version-11.x.x-sidebars.json +++ b/docusaurus/react_versioned_sidebars/version-11.x.x-sidebars.json @@ -146,4 +146,4 @@ "troubleshooting/troubleshooting", "resources/resources" ] -} \ No newline at end of file +} diff --git a/docusaurus/react_versions.json b/docusaurus/react_versions.json index 68753b9d4..554f0e458 100644 --- a/docusaurus/react_versions.json +++ b/docusaurus/react_versions.json @@ -1,4 +1 @@ -[ - "11.x.x", - "11.x.x-legacy" -] +["11.x.x", "11.x.x-legacy"] diff --git a/e2e/fixtures/data/attachment.mjs b/e2e/fixtures/data/attachment.mjs index 5e468d85f..f89dbaa54 100644 --- a/e2e/fixtures/data/attachment.mjs +++ b/e2e/fixtures/data/attachment.mjs @@ -1,4 +1,4 @@ -/* eslint-disable sort-keys */ + const smallImageAttachment = [ { type: 'image', diff --git a/e2e/user/Controller.ts b/e2e/user/Controller.ts index c15d526c4..27d2265cb 100644 --- a/e2e/user/Controller.ts +++ b/e2e/user/Controller.ts @@ -3,7 +3,10 @@ import type { Page } from '@playwright/test'; import selectors from './selectors'; export class Controller { - constructor(private baseURL: string | undefined, private page: Page) {} + constructor( + private baseURL: string | undefined, + private page: Page, + ) {} async openStory(story: string, waitForPresence: string) { await Promise.all([ diff --git a/e2e/user/components/Attachment/Attachment.ts b/e2e/user/components/Attachment/Attachment.ts index f418b4c03..51d109a32 100644 --- a/e2e/user/components/Attachment/Attachment.ts +++ b/e2e/user/components/Attachment/Attachment.ts @@ -2,7 +2,7 @@ import { expect, Page } from '@playwright/test'; const attachmentTypes = ['card', 'img', 'gallery', 'video', 'file', 'media'] as const; -type AttachmentType = typeof attachmentTypes[number]; +type AttachmentType = (typeof attachmentTypes)[number]; export function getAttachment(page: Page, type: AttachmentType) { return page.locator(`.str-chat__message-attachment--${type}`); diff --git a/examples/capacitor/src/App.tsx b/examples/capacitor/src/App.tsx index 10826cafd..70efddf31 100644 --- a/examples/capacitor/src/App.tsx +++ b/examples/capacitor/src/App.tsx @@ -17,7 +17,7 @@ const apiKey = process.env.REACT_APP_STREAM_KEY as string; const userId = process.env.REACT_APP_USER_ID as string; const userToken = process.env.REACT_APP_USER_TOKEN as string; -const filters: ChannelFilters = { type: 'messaging', members: {$in: [userId]} }; +const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] } }; const options: ChannelOptions = { state: true, presence: true, limit: 10 }; const sort: ChannelSort = { last_message_at: -1, updated_at: -1 }; diff --git a/examples/capacitor/src/components/CustomMessage.tsx b/examples/capacitor/src/components/CustomMessage.tsx index b7dbfec54..5d6f3e715 100644 --- a/examples/capacitor/src/components/CustomMessage.tsx +++ b/examples/capacitor/src/components/CustomMessage.tsx @@ -16,12 +16,8 @@ import { import './CustomMessage.scss'; export const CustomMessage = () => { - const { - showDetailedReactions, - isReactionEnabled, - message, - reactionSelectorRef, - } = useMessageContext(); + const { showDetailedReactions, isReactionEnabled, message, reactionSelectorRef } = + useMessageContext(); const messageWrapperRef = useRef(null); diff --git a/examples/capacitor/src/index.tsx b/examples/capacitor/src/index.tsx index e9d9d29a0..ee44bb255 100644 --- a/examples/capacitor/src/index.tsx +++ b/examples/capacitor/src/index.tsx @@ -7,7 +7,7 @@ import * as serviceWorker from './serviceWorker'; createRoot(document.getElementById('root')!).render( - + , ); // If you want your app to work offline and load faster, you can change diff --git a/examples/nextjs/pages/_app.js b/examples/nextjs/pages/_app.jsx similarity index 100% rename from examples/nextjs/pages/_app.js rename to examples/nextjs/pages/_app.jsx diff --git a/examples/nextjs/pages/index.js b/examples/nextjs/pages/index.jsx similarity index 100% rename from examples/nextjs/pages/index.js rename to examples/nextjs/pages/index.jsx diff --git a/examples/typescript/src/App.tsx b/examples/typescript/src/App.tsx index ee16cb311..77dec5c64 100644 --- a/examples/typescript/src/App.tsx +++ b/examples/typescript/src/App.tsx @@ -11,9 +11,9 @@ import { Window, } from 'stream-chat-react'; -const params = (new Proxy(new URLSearchParams(window.location.search), { +const params = new Proxy(new URLSearchParams(window.location.search), { get: (searchParams, property) => searchParams.get(property as string), -}) as unknown) as Record; +}) as unknown as Record; const apiKey = process.env.REACT_APP_STREAM_KEY as string; const userId = params.uid || (process.env.REACT_APP_USER_ID as string); diff --git a/examples/typescript/src/components/CustomMessage.tsx b/examples/typescript/src/components/CustomMessage.tsx index b7dbfec54..5d6f3e715 100644 --- a/examples/typescript/src/components/CustomMessage.tsx +++ b/examples/typescript/src/components/CustomMessage.tsx @@ -16,12 +16,8 @@ import { import './CustomMessage.scss'; export const CustomMessage = () => { - const { - showDetailedReactions, - isReactionEnabled, - message, - reactionSelectorRef, - } = useMessageContext(); + const { showDetailedReactions, isReactionEnabled, message, reactionSelectorRef } = + useMessageContext(); const messageWrapperRef = useRef(null); diff --git a/examples/vite/src/App.tsx b/examples/vite/src/App.tsx index dd52d39be..d603e96f4 100644 --- a/examples/vite/src/App.tsx +++ b/examples/vite/src/App.tsx @@ -15,9 +15,9 @@ import { ChatView, } from 'stream-chat-react'; -const params = (new Proxy(new URLSearchParams(window.location.search), { +const params = new Proxy(new URLSearchParams(window.location.search), { get: (searchParams, property) => searchParams.get(property as string), -}) as unknown) as Record; +}) as unknown as Record; const parseUserIdFromToken = (token: string) => { const [, payload] = token.split('.'); diff --git a/src/components/AIStateIndicator/AIStateIndicator.tsx b/src/components/AIStateIndicator/AIStateIndicator.tsx index 2bbe572f1..977bd240a 100644 --- a/src/components/AIStateIndicator/AIStateIndicator.tsx +++ b/src/components/AIStateIndicator/AIStateIndicator.tsx @@ -8,20 +8,19 @@ import { useChannelStateContext, useTranslationContext } from '../../context'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type AIStateIndicatorProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { channel?: Channel; }; export const AIStateIndicator = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ channel: channelFromProps, }: AIStateIndicatorProps) => { const { t } = useTranslationContext(); - const { channel: channelFromContext } = useChannelStateContext( - 'AIStateIndicator', - ); + const { channel: channelFromContext } = + useChannelStateContext('AIStateIndicator'); const channel = channelFromProps || channelFromContext; const { aiState } = useAIState(channel); const allowedStates = { diff --git a/src/components/AIStateIndicator/hooks/useAIState.ts b/src/components/AIStateIndicator/hooks/useAIState.ts index 54e955a6f..33d744fda 100644 --- a/src/components/AIStateIndicator/hooks/useAIState.ts +++ b/src/components/AIStateIndicator/hooks/useAIState.ts @@ -18,7 +18,7 @@ export const AIStates = { * @returns {{ aiState: AIState }} The current AI state for the given channel. */ export const useAIState = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel?: Channel, ): { aiState: AIState } => { diff --git a/src/components/Attachment/Attachment.tsx b/src/components/Attachment/Attachment.tsx index f1c32c43a..972e12ad5 100644 --- a/src/components/Attachment/Attachment.tsx +++ b/src/components/Attachment/Attachment.tsx @@ -55,7 +55,7 @@ export const ATTACHMENT_GROUPS_ORDER = [ ] as const; export type AttachmentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** The message attachments to render, see [attachment structure](https://getstream.io/chat/docs/javascript/message_format/?language=javascript) **/ attachments: StreamAttachment[]; @@ -87,7 +87,7 @@ export type AttachmentProps< * A component used for rendering message attachments. By default, the component supports: AttachmentActions, Audio, Card, File, Gallery, Image, and Video */ export const Attachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: AttachmentProps, ) => { @@ -107,7 +107,7 @@ export const Attachment = < }; const renderGroupedAttachments = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachments, ...rest @@ -169,7 +169,7 @@ const renderGroupedAttachments = < }; const getAttachmentType = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: AttachmentProps['attachments'][number], ): keyof typeof CONTAINER_MAP => { diff --git a/src/components/Attachment/AttachmentActions.tsx b/src/components/Attachment/AttachmentActions.tsx index 72fef6982..ec323edfb 100644 --- a/src/components/Attachment/AttachmentActions.tsx +++ b/src/components/Attachment/AttachmentActions.tsx @@ -7,7 +7,7 @@ import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler' import type { DefaultStreamChatGenerics } from '../../types/types'; export type AttachmentActionsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Attachment & { /** A list of actions */ actions: Action[]; @@ -20,7 +20,7 @@ export type AttachmentActionsProps< }; const UnMemoizedAttachmentActions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: AttachmentActionsProps, ) => { diff --git a/src/components/Attachment/AttachmentContainer.tsx b/src/components/Attachment/AttachmentContainer.tsx index 94e73d179..a434839d8 100644 --- a/src/components/Attachment/AttachmentContainer.tsx +++ b/src/components/Attachment/AttachmentContainer.tsx @@ -30,13 +30,13 @@ import type { import type { Attachment } from 'stream-chat'; export type AttachmentContainerProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachment: Attachment | GalleryAttachment; componentType: AttachmentComponentType; }; export const AttachmentWithinContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, children, @@ -50,8 +50,8 @@ export const AttachmentWithinContainer = < componentType === 'card' && !attachment?.image_url && !attachment?.thumb_url ? 'no-image' : attachment?.actions?.length - ? 'actions' - : ''; + ? 'actions' + : ''; } const classNames = clsx( @@ -69,7 +69,7 @@ export const AttachmentWithinContainer = < }; export const AttachmentActionsContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ actionHandler, attachment, @@ -108,7 +108,7 @@ function getCssDimensionsVariables(url: string) { } export const GalleryContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, Gallery = DefaultGallery, @@ -150,7 +150,7 @@ export const GalleryContainer = < }; export const ImageContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: RenderAttachmentProps, ) => { @@ -194,7 +194,7 @@ export const ImageContainer = < }; export const CardContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: RenderAttachmentProps, ) => { @@ -220,7 +220,7 @@ export const CardContainer = < }; export const FileContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, File = DefaultFile, @@ -234,7 +234,7 @@ export const FileContainer = < ); }; export const AudioContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, Audio = DefaultAudio, @@ -247,11 +247,11 @@ export const AudioContainer = < ); export const VoiceRecordingContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, - VoiceRecording = DefaultVoiceRecording, isQuoted, + VoiceRecording = DefaultVoiceRecording, }: RenderAttachmentProps) => (
@@ -261,7 +261,7 @@ export const VoiceRecordingContainer = < ); export const MediaContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: RenderAttachmentProps, ) => { @@ -269,10 +269,8 @@ export const MediaContainer = < const componentType = 'media'; const { shouldGenerateVideoThumbnail, videoAttachmentSizeHandler } = useChannelStateContext(); const videoElement = useRef(null); - const [ - attachmentConfiguration, - setAttachmentConfiguration, - ] = useState(); + const [attachmentConfiguration, setAttachmentConfiguration] = + useState(); useLayoutEffect(() => { if (videoElement.current && videoAttachmentSizeHandler) { @@ -319,7 +317,7 @@ export const MediaContainer = < }; export const UnsupportedAttachmentContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, UnsupportedAttachment = DefaultUnsupportedAttachment, diff --git a/src/components/Attachment/Audio.tsx b/src/components/Attachment/Audio.tsx index baff2d7ef..c9b76a100 100644 --- a/src/components/Attachment/Audio.tsx +++ b/src/components/Attachment/Audio.tsx @@ -8,14 +8,14 @@ import { useAudioController } from './hooks/useAudioController'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type AudioProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { // fixme: rename og to attachment og: Attachment; }; const UnMemoizedAudio = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: AudioProps, ) => { diff --git a/src/components/Attachment/FileAttachment.tsx b/src/components/Attachment/FileAttachment.tsx index 0e66e74a7..40acc537f 100644 --- a/src/components/Attachment/FileAttachment.tsx +++ b/src/components/Attachment/FileAttachment.tsx @@ -7,13 +7,13 @@ import { DownloadButton, FileSizeIndicator } from './components'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type FileAttachmentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachment: Attachment; }; const UnMemoizedFileAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, }: FileAttachmentProps) => ( diff --git a/src/components/Attachment/UnsupportedAttachment.tsx b/src/components/Attachment/UnsupportedAttachment.tsx index e738ec8fe..6071ba500 100644 --- a/src/components/Attachment/UnsupportedAttachment.tsx +++ b/src/components/Attachment/UnsupportedAttachment.tsx @@ -5,13 +5,13 @@ import type { Attachment } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type UnsupportedAttachmentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachment: Attachment; }; export const UnsupportedAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, }: UnsupportedAttachmentProps) => { diff --git a/src/components/Attachment/VoiceRecording.tsx b/src/components/Attachment/VoiceRecording.tsx index 2b1d62fe6..c8ed2d7db 100644 --- a/src/components/Attachment/VoiceRecording.tsx +++ b/src/components/Attachment/VoiceRecording.tsx @@ -12,7 +12,7 @@ import type { DefaultStreamChatGenerics } from '../../types'; const rootClassName = 'str-chat__message-attachment__voice-recording-widget'; export type VoiceRecordingPlayerProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, 'attachment'> & { /** An array of fractional numeric values of playback speed to override the defaults (1.0, 1.5, 2.0) */ playbackRates?: number[]; @@ -86,7 +86,7 @@ export const VoiceRecordingPlayer = ({ attachment, playbackRates }: VoiceRecordi }; export type QuotedVoiceRecordingProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, 'attachment'>; export const QuotedVoiceRecording = ({ attachment }: QuotedVoiceRecordingProps) => { @@ -120,7 +120,7 @@ export const QuotedVoiceRecording = ({ attachment }: QuotedVoiceRecordingProps) }; export type VoiceRecordingProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** The attachment object from the message's attachment list. */ attachment: Attachment; diff --git a/src/components/Attachment/__tests__/Attachment.test.js b/src/components/Attachment/__tests__/Attachment.test.js index ee24ee014..e7c218289 100644 --- a/src/components/Attachment/__tests__/Attachment.test.js +++ b/src/components/Attachment/__tests__/Attachment.test.js @@ -213,7 +213,6 @@ describe('attachment', () => { ], }); await waitFor(() => { - /* eslint-disable jest-dom/prefer-in-document */ const Card = queryAllByTestId('card-attachment'); expect(Card).toHaveLength(3); diff --git a/src/components/Attachment/__tests__/AttachmentActions.test.js b/src/components/Attachment/__tests__/AttachmentActions.test.js index b864614af..d11e989cb 100644 --- a/src/components/Attachment/__tests__/AttachmentActions.test.js +++ b/src/components/Attachment/__tests__/AttachmentActions.test.js @@ -51,7 +51,6 @@ describe('AttachmentActions', () => { fireEvent.click(getByTestId(actions[1].name)); await waitFor(() => { - // eslint-disable-next-line jest/prefer-called-with expect(actionHandler).toHaveBeenCalledTimes(2); }); }); diff --git a/src/components/Attachment/__tests__/Audio.test.js b/src/components/Attachment/__tests__/Audio.test.js index ff5388325..c263b326d 100644 --- a/src/components/Attachment/__tests__/Audio.test.js +++ b/src/components/Attachment/__tests__/Audio.test.js @@ -15,7 +15,7 @@ const originalConsoleError = console.error; jest.spyOn(console, 'error').mockImplementationOnce((...errorOrTextorArg) => { const msg = Array.isArray(errorOrTextorArg) ? errorOrTextorArg[0] - : errorOrTextorArg.message ?? errorOrTextorArg; + : (errorOrTextorArg.message ?? errorOrTextorArg); if (msg.match('Not implemented')) return; originalConsoleError(...errorOrTextorArg); }); diff --git a/src/components/Attachment/audioSampling.ts b/src/components/Attachment/audioSampling.ts index ff8b7638d..289a49157 100644 --- a/src/components/Attachment/audioSampling.ts +++ b/src/components/Attachment/audioSampling.ts @@ -4,8 +4,8 @@ export const resampleWaveformData = (waveformData: number[], amplitudesCount: nu waveformData.length === amplitudesCount ? waveformData : waveformData.length > amplitudesCount - ? downSample(waveformData, amplitudesCount) - : upSample(waveformData, amplitudesCount); + ? downSample(waveformData, amplitudesCount) + : upSample(waveformData, amplitudesCount); /** * The downSample function uses the Largest-Triangle-Three-Buckets (LTTB) algorithm. diff --git a/src/components/Attachment/utils.tsx b/src/components/Attachment/utils.tsx index 26c8696dc..2160b7bd6 100644 --- a/src/components/Attachment/utils.tsx +++ b/src/components/Attachment/utils.tsx @@ -15,89 +15,89 @@ import type { export const SUPPORTED_VIDEO_FORMATS = ['video/mp4', 'video/ogg', 'video/webm', 'video/quicktime']; -export type AttachmentComponentType = typeof ATTACHMENT_GROUPS_ORDER[number]; +export type AttachmentComponentType = (typeof ATTACHMENT_GROUPS_ORDER)[number]; export type GroupedRenderedAttachment = Record; export type GalleryAttachment< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { images: Attachment[]; type: 'gallery'; }; export type RenderAttachmentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, 'attachments'> & { attachment: Attachment; }; export type RenderGalleryProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, 'attachments'> & { attachment: GalleryAttachment; }; export const isLocalAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: UnknownType, ): attachment is LocalAttachment => !!(attachment.localMetadata as LocalAttachment)?.id; export const isScrapedContent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment, ) => attachment.og_scrape_url || attachment.title_link; export const isUploadedImage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment, ) => attachment.type === 'image' && !isScrapedContent(attachment); export const isLocalImageAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is LocalImageAttachment => isUploadedImage(attachment) && isLocalAttachment(attachment); export const isGalleryAttachmentType = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( output: Attachment | GalleryAttachment, ): output is GalleryAttachment => Array.isArray(output.images); export const isAudioAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ) => attachment.type === 'audio'; export const isLocalAudioAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is LocalAudioAttachment => isAudioAttachment(attachment) && isLocalAttachment(attachment); export const isVoiceRecordingAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is VoiceRecordingAttachment => attachment.type === 'voiceRecording'; export const isLocalVoiceRecordingAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is LocalVoiceRecordingAttachment => isVoiceRecordingAttachment(attachment) && isLocalAttachment(attachment); export const isFileAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ) => @@ -109,14 +109,14 @@ export const isFileAttachment = < ); export const isLocalFileAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is LocalFileAttachment => isFileAttachment(attachment) && isLocalAttachment(attachment); export const isMediaAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ) => @@ -124,7 +124,7 @@ export const isMediaAttachment = < attachment.type === 'video'; export const isLocalMediaAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): attachment is LocalVideoAttachment => diff --git a/src/components/AutoCompleteTextarea/Textarea.jsx b/src/components/AutoCompleteTextarea/Textarea.jsx index 899c72676..43391ead3 100644 --- a/src/components/AutoCompleteTextarea/Textarea.jsx +++ b/src/components/AutoCompleteTextarea/Textarea.jsx @@ -455,7 +455,7 @@ export class ReactTextareaAutocomplete extends React.Component { 'value', ]; - // eslint-disable-next-line + for (const prop in props) { if (notSafe.includes(prop)) delete props[prop]; } diff --git a/src/components/AutoCompleteTextarea/utils.js b/src/components/AutoCompleteTextarea/utils.js index 52314ec96..7b01d6310 100644 --- a/src/components/AutoCompleteTextarea/utils.js +++ b/src/components/AutoCompleteTextarea/utils.js @@ -17,7 +17,6 @@ export function defaultScrollToItem(container, item) { return; } - // eslint-disable-next-line container.scrollTop = itemOffsetTop; } diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx index 4c8ab2005..d5381b7fb 100644 --- a/src/components/Avatar/Avatar.tsx +++ b/src/components/Avatar/Avatar.tsx @@ -9,7 +9,7 @@ import { getWholeChar } from '../../utils'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type AvatarProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Custom root element class that will be merged with the default class */ className?: string; @@ -29,7 +29,7 @@ export type AvatarProps< * A round avatar image with fallback to username's first letter */ export const Avatar = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: AvatarProps, ) => { diff --git a/src/components/Avatar/ChannelAvatar.tsx b/src/components/Avatar/ChannelAvatar.tsx index eab6b088f..6a9bd86ad 100644 --- a/src/components/Avatar/ChannelAvatar.tsx +++ b/src/components/Avatar/ChannelAvatar.tsx @@ -3,11 +3,11 @@ import { Avatar, AvatarProps, GroupAvatar, GroupAvatarProps } from './index'; import type { DefaultStreamChatGenerics } from '../../types'; export type ChannelAvatarProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial & AvatarProps; export const ChannelAvatar = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ groupChannelDisplayInfo, image, diff --git a/src/components/Avatar/__tests__/Avatar.test.js b/src/components/Avatar/__tests__/Avatar.test.js index b45990d7c..6ebe5393f 100644 --- a/src/components/Avatar/__tests__/Avatar.test.js +++ b/src/components/Avatar/__tests__/Avatar.test.js @@ -9,7 +9,7 @@ const AVATAR_ROOT_TEST_ID = 'avatar'; const AVATAR_FALLBACK_TEST_ID = 'avatar-fallback'; const AVATAR_IMG_TEST_ID = 'avatar-img'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('Avatar', () => { it('should render component with default props', () => { diff --git a/src/components/Channel/Channel.tsx b/src/components/Channel/Channel.tsx index e468e79b8..3f3542c47 100644 --- a/src/components/Channel/Channel.tsx +++ b/src/components/Channel/Channel.tsx @@ -100,7 +100,7 @@ import { useThreadContext } from '../Threads'; import { CHANNEL_CONTAINER_ID } from './constants'; type ChannelPropsForwardedToComponentContext< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick< ComponentContextValue, | 'Attachment' @@ -166,7 +166,7 @@ type ChannelPropsForwardedToComponentContext< >; const isUserResponseArray = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( output: string[] | UserResponse[], ): output is UserResponse[] => @@ -174,7 +174,7 @@ const isUserResponseArray = < export type ChannelProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = ChannelPropsForwardedToComponentContext & { /** List of accepted file types */ acceptedFiles?: string[]; @@ -255,7 +255,7 @@ export type ChannelProps< }; const ChannelContainer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, className: additionalClassName, @@ -275,7 +275,7 @@ const ChannelContainer = < const UnMemoizedChannel = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: PropsWithChildren>, ) => { @@ -286,9 +286,8 @@ const UnMemoizedChannel = < LoadingIndicator = DefaultLoadingIndicator, } = props; - const { channel: contextChannel, channelsQueryState } = useChatContext( - 'Channel', - ); + const { channel: contextChannel, channelsQueryState } = + useChatContext('Channel'); const channel = propsChannel || contextChannel; @@ -317,7 +316,7 @@ const UnMemoizedChannel = < const ChannelInner = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: PropsWithChildren< ChannelProps & { @@ -360,12 +359,8 @@ const ChannelInner = < [propChannelQueryOptions], ); - const { - client, - customClasses, - latestMessageDatesByChannels, - mutes, - } = useChatContext('Channel'); + const { client, customClasses, latestMessageDatesByChannels, mutes } = + useChatContext('Channel'); const { t } = useTranslationContext('Channel'); const chatContainerClass = getChatContainerClass(customClasses?.chatContainer); const windowsEmojiClass = useImageFlagEmojisOnWindowsClass(); @@ -750,140 +745,142 @@ const ChannelInner = < [channel, loadMoreFinished], ); - const jumpToLatestMessage: ChannelActionContextValue['jumpToLatestMessage'] = useCallback(async () => { - await channel.state.loadMessageIntoState('latest'); - loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); - dispatch({ - type: 'jumpToLatestMessage', - }); - }, [channel, loadMoreFinished]); + const jumpToLatestMessage: ChannelActionContextValue['jumpToLatestMessage'] = + useCallback(async () => { + await channel.state.loadMessageIntoState('latest'); + loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); + dispatch({ + type: 'jumpToLatestMessage', + }); + }, [channel, loadMoreFinished]); - const jumpToFirstUnreadMessage: ChannelActionContextValue['jumpToFirstUnreadMessage'] = useCallback( - async ( - queryMessageLimit = DEFAULT_JUMP_TO_PAGE_SIZE, - highlightDuration = DEFAULT_HIGHLIGHT_DURATION, - ) => { - if (!channelUnreadUiState?.unread_messages) return; - let lastReadMessageId = channelUnreadUiState?.last_read_message_id; - let firstUnreadMessageId = channelUnreadUiState?.first_unread_message_id; - let isInCurrentMessageSet = false; - - if (firstUnreadMessageId) { - const result = findInMsgSetById(firstUnreadMessageId, channel.state.messages); - isInCurrentMessageSet = result.index !== -1; - } else if (lastReadMessageId) { - const result = findInMsgSetById(lastReadMessageId, channel.state.messages); - isInCurrentMessageSet = !!result.target; - firstUnreadMessageId = - result.index > -1 ? channel.state.messages[result.index + 1]?.id : undefined; - } else { - const lastReadTimestamp = channelUnreadUiState.last_read.getTime(); - const { index: lastReadMessageIndex, target: lastReadMessage } = findInMsgSetByDate( - channelUnreadUiState.last_read, - channel.state.messages, - true, - ); - - if (lastReadMessage) { - firstUnreadMessageId = channel.state.messages[lastReadMessageIndex + 1]?.id; - isInCurrentMessageSet = !!firstUnreadMessageId; - lastReadMessageId = lastReadMessage.id; + const jumpToFirstUnreadMessage: ChannelActionContextValue['jumpToFirstUnreadMessage'] = + useCallback( + async ( + queryMessageLimit = DEFAULT_JUMP_TO_PAGE_SIZE, + highlightDuration = DEFAULT_HIGHLIGHT_DURATION, + ) => { + if (!channelUnreadUiState?.unread_messages) return; + let lastReadMessageId = channelUnreadUiState?.last_read_message_id; + let firstUnreadMessageId = channelUnreadUiState?.first_unread_message_id; + let isInCurrentMessageSet = false; + + if (firstUnreadMessageId) { + const result = findInMsgSetById(firstUnreadMessageId, channel.state.messages); + isInCurrentMessageSet = result.index !== -1; + } else if (lastReadMessageId) { + const result = findInMsgSetById(lastReadMessageId, channel.state.messages); + isInCurrentMessageSet = !!result.target; + firstUnreadMessageId = + result.index > -1 ? channel.state.messages[result.index + 1]?.id : undefined; } else { - dispatch({ loadingMore: true, type: 'setLoadingMore' }); - let messages; - try { - messages = ( - await channel.query( - { - messages: { - created_at_around: channelUnreadUiState.last_read.toISOString(), - limit: queryMessageLimit, + const lastReadTimestamp = channelUnreadUiState.last_read.getTime(); + const { index: lastReadMessageIndex, target: lastReadMessage } = findInMsgSetByDate( + channelUnreadUiState.last_read, + channel.state.messages, + true, + ); + + if (lastReadMessage) { + firstUnreadMessageId = channel.state.messages[lastReadMessageIndex + 1]?.id; + isInCurrentMessageSet = !!firstUnreadMessageId; + lastReadMessageId = lastReadMessage.id; + } else { + dispatch({ loadingMore: true, type: 'setLoadingMore' }); + let messages; + try { + messages = ( + await channel.query( + { + messages: { + created_at_around: channelUnreadUiState.last_read.toISOString(), + limit: queryMessageLimit, + }, }, - }, - 'new', - ) - ).messages; - } catch (e) { - addNotification(t('Failed to jump to the first unread message'), 'error'); + 'new', + ) + ).messages; + } catch (e) { + addNotification(t('Failed to jump to the first unread message'), 'error'); + loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); + return; + } + + const firstMessageWithCreationDate = messages.find((msg) => msg.created_at); + if (!firstMessageWithCreationDate) { + addNotification(t('Failed to jump to the first unread message'), 'error'); + loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); + return; + } + const firstMessageTimestamp = new Date( + firstMessageWithCreationDate.created_at as string, + ).getTime(); + if (lastReadTimestamp < firstMessageTimestamp) { + // whole channel is unread + firstUnreadMessageId = firstMessageWithCreationDate.id; + } else { + const result = findInMsgSetByDate(channelUnreadUiState.last_read, messages); + lastReadMessageId = result.target?.id; + } loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); - return; } + } - const firstMessageWithCreationDate = messages.find((msg) => msg.created_at); - if (!firstMessageWithCreationDate) { + if (!firstUnreadMessageId && !lastReadMessageId) { + addNotification(t('Failed to jump to the first unread message'), 'error'); + return; + } + + if (!isInCurrentMessageSet) { + dispatch({ loadingMore: true, type: 'setLoadingMore' }); + try { + const targetId = (firstUnreadMessageId ?? lastReadMessageId) as string; + await channel.state.loadMessageIntoState(targetId, undefined, queryMessageLimit); + /** + * if the index of the last read message on the page is beyond the half of the page, + * we have arrived to the oldest page of the channel + */ + const indexOfTarget = channel.state.messages.findIndex( + (message) => message.id === targetId, + ) as number; + loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); + firstUnreadMessageId = + firstUnreadMessageId ?? channel.state.messages[indexOfTarget + 1]?.id; + } catch (e) { addNotification(t('Failed to jump to the first unread message'), 'error'); loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); return; } - const firstMessageTimestamp = new Date( - firstMessageWithCreationDate.created_at as string, - ).getTime(); - if (lastReadTimestamp < firstMessageTimestamp) { - // whole channel is unread - firstUnreadMessageId = firstMessageWithCreationDate.id; - } else { - const result = findInMsgSetByDate(channelUnreadUiState.last_read, messages); - lastReadMessageId = result.target?.id; - } - loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); } - } - if (!firstUnreadMessageId && !lastReadMessageId) { - addNotification(t('Failed to jump to the first unread message'), 'error'); - return; - } - - if (!isInCurrentMessageSet) { - dispatch({ loadingMore: true, type: 'setLoadingMore' }); - try { - const targetId = (firstUnreadMessageId ?? lastReadMessageId) as string; - await channel.state.loadMessageIntoState(targetId, undefined, queryMessageLimit); - /** - * if the index of the last read message on the page is beyond the half of the page, - * we have arrived to the oldest page of the channel - */ - const indexOfTarget = channel.state.messages.findIndex( - (message) => message.id === targetId, - ) as number; - loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); - firstUnreadMessageId = - firstUnreadMessageId ?? channel.state.messages[indexOfTarget + 1]?.id; - } catch (e) { + if (!firstUnreadMessageId) { addNotification(t('Failed to jump to the first unread message'), 'error'); - loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages); return; } - } + if (!channelUnreadUiState.first_unread_message_id) + _setChannelUnreadUiState({ + ...channelUnreadUiState, + first_unread_message_id: firstUnreadMessageId, + last_read_message_id: lastReadMessageId, + }); - if (!firstUnreadMessageId) { - addNotification(t('Failed to jump to the first unread message'), 'error'); - return; - } - if (!channelUnreadUiState.first_unread_message_id) - _setChannelUnreadUiState({ - ...channelUnreadUiState, - first_unread_message_id: firstUnreadMessageId, - last_read_message_id: lastReadMessageId, + dispatch({ + hasMoreNewer: channel.state.messagePagination.hasNext, + highlightedMessageId: firstUnreadMessageId, + type: 'jumpToMessageFinished', }); - dispatch({ - hasMoreNewer: channel.state.messagePagination.hasNext, - highlightedMessageId: firstUnreadMessageId, - type: 'jumpToMessageFinished', - }); - - if (clearHighlightedMessageTimeoutId.current) { - clearTimeout(clearHighlightedMessageTimeoutId.current); - } + if (clearHighlightedMessageTimeoutId.current) { + clearTimeout(clearHighlightedMessageTimeoutId.current); + } - clearHighlightedMessageTimeoutId.current = setTimeout(() => { - clearHighlightedMessageTimeoutId.current = null; - dispatch({ type: 'clearHighlightedMessage' }); - }, highlightDuration); - }, - [addNotification, channel, loadMoreFinished, t, channelUnreadUiState], - ); + clearHighlightedMessageTimeoutId.current = setTimeout(() => { + clearHighlightedMessageTimeoutId.current = null; + dispatch({ type: 'clearHighlightedMessage' }); + }, highlightDuration); + }, + [addNotification, channel, loadMoreFinished, t, channelUnreadUiState], + ); const deleteMessage = useCallback( async ( @@ -979,9 +976,9 @@ const ChannelInner = < } catch (error) { // error response isn't usable so needs to be stringified then parsed const stringError = JSON.stringify(error); - const parsedError = (stringError - ? JSON.parse(stringError) - : {}) as ErrorFromResponse; + const parsedError = ( + stringError ? JSON.parse(stringError) : {} + ) as ErrorFromResponse; // Handle the case where the message already exists // (typically, when retrying to send a message). @@ -1003,16 +1000,16 @@ const ChannelInner = < updateMessage({ ...message, error: parsedError, - errorStatusCode: parsedError.status || undefined, + errorStatusCode: parsedError.status ?? undefined, status: 'failed', }); thread?.upsertReplyLocally({ - // @ts-expect-error + // @ts-expect-error message type mismatch message: { ...message, error: parsedError, - errorStatusCode: parsedError.status || undefined, + errorStatusCode: parsedError.status ?? undefined, status: 'failed', }, }); @@ -1047,7 +1044,7 @@ const ChannelInner = < }; thread?.upsertReplyLocally({ - // @ts-expect-error + // @ts-expect-error message type mismatch message: messagePreview, }); @@ -1224,7 +1221,7 @@ const ChannelInner = < ], ); - // @ts-expect-error + // @ts-expect-error SCG is missing from ComponentContextValue type const componentContextValue: Partial = useMemo( () => ({ Attachment: props.Attachment, diff --git a/src/components/Channel/__tests__/Channel.test.js b/src/components/Channel/__tests__/Channel.test.js index 298a0f4fc..4035c7b44 100644 --- a/src/components/Channel/__tests__/Channel.test.js +++ b/src/components/Channel/__tests__/Channel.test.js @@ -206,6 +206,7 @@ describe('Channel', () => { it('should render empty channel container if channel does not have cid', async () => { const { channel } = await initClient(); const childrenContent = 'Channel children'; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { cid, ...channelWithoutCID } = channel; const { asFragment } = render( { }); describe('delete message', () => { it('should throw error instead of calling default client.deleteMessage() function', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { id, ...message } = generateMessage(); const { channel, chatClient } = await initClient(); const clientDeleteMessageSpy = jest.spyOn(chatClient, 'deleteMessage'); @@ -1509,6 +1511,7 @@ describe('Channel', () => { }); it('should throw error instead of calling custom doDeleteMessageRequest function', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { id, ...message } = generateMessage(); const { channel, chatClient } = await initClient(); const clientDeleteMessageSpy = jest @@ -1935,9 +1938,11 @@ describe('Channel', () => { name: 'MessageList', }, { - callback: (message) => ({ openThread, thread }) => { - if (!thread) openThread(message, { preventDefault: () => null }); - }, + callback: + (message) => + ({ openThread, thread }) => { + if (!thread) openThread(message, { preventDefault: () => null }); + }, component: Thread, getFirstMessageAvatar: () => { // the first avatar is that of the ThreadHeader diff --git a/src/components/Channel/channelState.ts b/src/components/Channel/channelState.ts index 98bf48665..7e3492450 100644 --- a/src/components/Channel/channelState.ts +++ b/src/components/Channel/channelState.ts @@ -6,7 +6,7 @@ import type { ChannelState, StreamMessage } from '../../context/ChannelStateCont import type { DefaultStreamChatGenerics } from '../../types/types'; export type ChannelStateReducerAction< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = | { type: 'closeThread'; @@ -86,11 +86,11 @@ export type ChannelStateReducerAction< }; export type ChannelStateReducer< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Reducer, ChannelStateReducerAction>; export const channelReducer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( state: ChannelState, action: ChannelStateReducerAction, diff --git a/src/components/Channel/hooks/useChannelContainerClasses.ts b/src/components/Channel/hooks/useChannelContainerClasses.ts index f3d847735..ecaed31ea 100644 --- a/src/components/Channel/hooks/useChannelContainerClasses.ts +++ b/src/components/Channel/hooks/useChannelContainerClasses.ts @@ -4,7 +4,7 @@ import { useChatContext } from '../../../context/ChatContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useImageFlagEmojisOnWindowsClass = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { useImageFlagEmojisOnWindows } = useChatContext('Channel'); return useImageFlagEmojisOnWindows && navigator.userAgent.match(/Win/) @@ -15,7 +15,7 @@ export const useImageFlagEmojisOnWindowsClass = < export const getChatContainerClass = (customClass?: string) => customClass ?? 'str-chat__container'; export const useChannelContainerClasses = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ customClasses, }: Pick) => { diff --git a/src/components/Channel/hooks/useCreateChannelStateContext.ts b/src/components/Channel/hooks/useCreateChannelStateContext.ts index 114b95cf3..933e99a31 100644 --- a/src/components/Channel/hooks/useCreateChannelStateContext.ts +++ b/src/components/Channel/hooks/useCreateChannelStateContext.ts @@ -7,7 +7,7 @@ import type { ChannelStateContextValue } from '../../../context/ChannelStateCont import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useCreateChannelStateContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( value: Omit, 'channelCapabilities'> & { channelCapabilitiesArray: string[]; @@ -19,17 +19,17 @@ export const useCreateChannelStateContext = < channel, channelCapabilitiesArray = [], channelConfig, + channelUnreadUiState, debounceURLEnrichmentMs, dragAndDropWindow, enrichURLForPreview, - giphyVersion, error, findURLFn, + giphyVersion, hasMore, hasMoreNewer, - imageAttachmentSizeHandler, - suppressAutoscroll, highlightedMessageId, + imageAttachmentSizeHandler, loading, loadingMore, maxNumberOfFiles, @@ -44,14 +44,14 @@ export const useCreateChannelStateContext = < read = {}, shouldGenerateVideoThumbnail, skipMessageDataMemoization, + suppressAutoscroll, thread, threadHasMore, threadLoadingMore, threadMessages = [], - channelUnreadUiState, videoAttachmentSizeHandler, - watcherCount, watcher_count, + watcherCount, watchers, } = value; diff --git a/src/components/Channel/hooks/useCreateTypingContext.ts b/src/components/Channel/hooks/useCreateTypingContext.ts index ee55dfe04..726156fee 100644 --- a/src/components/Channel/hooks/useCreateTypingContext.ts +++ b/src/components/Channel/hooks/useCreateTypingContext.ts @@ -4,7 +4,7 @@ import type { TypingContextValue } from '../../../context/TypingContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useCreateTypingContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( value: TypingContextValue, ) => { diff --git a/src/components/Channel/hooks/useEditMessageHandler.ts b/src/components/Channel/hooks/useEditMessageHandler.ts index f5067e887..90936157e 100644 --- a/src/components/Channel/hooks/useEditMessageHandler.ts +++ b/src/components/Channel/hooks/useEditMessageHandler.ts @@ -5,7 +5,7 @@ import type { StreamChat, UpdatedMessage } from 'stream-chat'; import type { DefaultStreamChatGenerics, UpdateMessageOptions } from '../../../types/types'; type UpdateHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ( cid: string, updatedMessage: UpdatedMessage, @@ -13,7 +13,7 @@ type UpdateHandler< ) => ReturnType['updateMessage']>; export const useEditMessageHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( doUpdateMessageRequest?: UpdateHandler, ) => { diff --git a/src/components/Channel/hooks/useMentionsHandlers.ts b/src/components/Channel/hooks/useMentionsHandlers.ts index ea42f6fab..9860acc34 100644 --- a/src/components/Channel/hooks/useMentionsHandlers.ts +++ b/src/components/Channel/hooks/useMentionsHandlers.ts @@ -5,11 +5,11 @@ import type { UserResponse } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type OnMentionAction< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (event: React.BaseSyntheticEvent, user?: UserResponse) => void; export const useMentionsHandlers = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( onMentionsHover?: OnMentionAction, onMentionsClick?: OnMentionAction, diff --git a/src/components/Channel/utils.ts b/src/components/Channel/utils.ts index aa7b6af1b..9242bcdd9 100644 --- a/src/components/Channel/utils.ts +++ b/src/components/Channel/utils.ts @@ -4,28 +4,30 @@ import type { ChannelState, MessageResponse } from 'stream-chat'; import type { ChannelNotifications } from '../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../types'; -export const makeAddNotifications = ( - setNotifications: Dispatch>, - notificationTimeouts: NodeJS.Timeout[], -) => (text: string, type: 'success' | 'error') => { - if (typeof text !== 'string' || (type !== 'success' && type !== 'error')) { - return; - } +export const makeAddNotifications = + ( + setNotifications: Dispatch>, + notificationTimeouts: NodeJS.Timeout[], + ) => + (text: string, type: 'success' | 'error') => { + if (typeof text !== 'string' || (type !== 'success' && type !== 'error')) { + return; + } - const id = nanoid(); + const id = nanoid(); - setNotifications((prevNotifications) => [...prevNotifications, { id, text, type }]); + setNotifications((prevNotifications) => [...prevNotifications, { id, text, type }]); - const timeout = setTimeout( - () => - setNotifications((prevNotifications) => - prevNotifications.filter((notification) => notification.id !== id), - ), - 5000, - ); + const timeout = setTimeout( + () => + setNotifications((prevNotifications) => + prevNotifications.filter((notification) => notification.id !== id), + ), + 5000, + ); - notificationTimeouts.push(timeout); -}; + notificationTimeouts.push(timeout); + }; /** * Utility function for jumpToFirstUnreadMessage @@ -33,7 +35,7 @@ export const makeAddNotifications = ( * @param msgSet */ export const findInMsgSetById = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( targetId: string, msgSet: ReturnType['formatMessage']>[], @@ -59,7 +61,7 @@ export const findInMsgSetById = < * @param exact */ export const findInMsgSetByDate = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( targetDate: Date, msgSet: diff --git a/src/components/ChannelHeader/ChannelHeader.tsx b/src/components/ChannelHeader/ChannelHeader.tsx index 05e56d9d9..384bb4ecc 100644 --- a/src/components/ChannelHeader/ChannelHeader.tsx +++ b/src/components/ChannelHeader/ChannelHeader.tsx @@ -28,15 +28,15 @@ export type ChannelHeaderProps = { * The ChannelHeader component renders some basic information about a Channel. */ export const ChannelHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ChannelHeaderProps, ) => { const { Avatar = DefaultAvatar, - MenuIcon = DefaultMenuIcon, image: overrideImage, live, + MenuIcon = DefaultMenuIcon, title: overrideTitle, } = props; diff --git a/src/components/ChannelHeader/__tests__/ChannelHeader.test.js b/src/components/ChannelHeader/__tests__/ChannelHeader.test.js index b6d10b749..3988ca731 100644 --- a/src/components/ChannelHeader/__tests__/ChannelHeader.test.js +++ b/src/components/ChannelHeader/__tests__/ChannelHeader.test.js @@ -59,7 +59,7 @@ async function renderComponent(props, channelData, channelType = 'messaging') { return renderComponentBase({ channel, client, props }); } -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('ChannelHeader', () => { it('should display live label when prop live is true', async () => { diff --git a/src/components/ChannelList/ChannelList.tsx b/src/components/ChannelList/ChannelList.tsx index 4f22c8995..7eb0981ad 100644 --- a/src/components/ChannelList/ChannelList.tsx +++ b/src/components/ChannelList/ChannelList.tsx @@ -35,7 +35,7 @@ const DEFAULT_OPTIONS = {}; const DEFAULT_SORT = {}; export type ChannelListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Additional props for underlying ChannelSearch component and channel search controller, [available props](https://getstream.io/chat/docs/sdk/react/utility-components/channel_search/#props) */ additionalChannelSearchProps?: Omit, 'setChannels'>; @@ -158,8 +158,8 @@ const UnMemoizedChannelList = { const { additionalChannelSearchProps, - Avatar = DefaultAvatar, allowNewMessagesFromUnfilteredChannels = true, + Avatar = DefaultAvatar, channelRenderFilterFn, ChannelSearch = DefaultChannelSearch, customActiveChannel, @@ -167,9 +167,9 @@ const UnMemoizedChannelList = chan.id === customActiveChannel); if (!customActiveChannelObject) { - //@ts-expect-error + //@ts-expect-error valid query [customActiveChannelObject] = await client.queryChannels({ id: customActiveChannel }); } diff --git a/src/components/ChannelList/ChannelListMessenger.tsx b/src/components/ChannelList/ChannelListMessenger.tsx index 234222bcc..fab76f40a 100644 --- a/src/components/ChannelList/ChannelListMessenger.tsx +++ b/src/components/ChannelList/ChannelListMessenger.tsx @@ -8,7 +8,7 @@ import type { APIErrorResponse, Channel, ErrorFromResponse } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type ChannelListMessengerProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Whether the channel query request returned an errored response */ error: ErrorFromResponse | null; @@ -28,7 +28,7 @@ export type ChannelListMessengerProps< * A preview list of channels, allowing you to select the channel you want to open */ export const ChannelListMessenger = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: PropsWithChildren>, ) => { diff --git a/src/components/ChannelList/__tests__/ChannelList.test.js b/src/components/ChannelList/__tests__/ChannelList.test.js index b576b0c52..25bc4a83d 100644 --- a/src/components/ChannelList/__tests__/ChannelList.test.js +++ b/src/components/ChannelList/__tests__/ChannelList.test.js @@ -294,7 +294,7 @@ describe('ChannelList', () => { // Wait for list of channels to load in DOM. await waitFor(() => { expect(getByRole('list')).toBeInTheDocument(); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(queryAllByRole('listitem')).toHaveLength(1); }); const results = await axe(container); @@ -620,7 +620,7 @@ describe('ChannelList', () => { let channel; beforeEach(async () => { client = await getTestClientWithUser({ id: user1.id }); - // eslint-disable-next-line react-hooks/rules-of-hooks + useMockedApis(client, [getOrCreateChannelApi(mockedChannels[0])]); channel = client.channel('messaging', mockedChannels[0].id); await channel.watch(); diff --git a/src/components/ChannelList/hooks/useChannelDeletedListener.ts b/src/components/ChannelList/hooks/useChannelDeletedListener.ts index 9e8db7527..f09b808e9 100644 --- a/src/components/ChannelList/hooks/useChannelDeletedListener.ts +++ b/src/components/ChannelList/hooks/useChannelDeletedListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useChannelDeletedListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useChannelHiddenListener.ts b/src/components/ChannelList/hooks/useChannelHiddenListener.ts index e8b221a7d..4b159dc44 100644 --- a/src/components/ChannelList/hooks/useChannelHiddenListener.ts +++ b/src/components/ChannelList/hooks/useChannelHiddenListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useChannelHiddenListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useChannelListShape.ts b/src/components/ChannelList/hooks/useChannelListShape.ts index e0cc1424d..87a2d2615 100644 --- a/src/components/ChannelList/hooks/useChannelListShape.ts +++ b/src/components/ChannelList/hooks/useChannelListShape.ts @@ -43,17 +43,15 @@ type HandleNotificationMessageNewParameters = Ba lockChannelOrder: boolean; } & Required, 'filters' | 'sort'>>; -type HandleNotificationRemovedFromChannelParameters< - SCG extends ExtendableGenerics -> = BaseParameters & RepeatedParameters; - -type HandleNotificationAddedToChannelParameters< - SCG extends ExtendableGenerics -> = BaseParameters & - RepeatedParameters & { - allowNewMessagesFromUnfilteredChannels: boolean; - lockChannelOrder: boolean; - } & Required, 'sort'>>; +type HandleNotificationRemovedFromChannelParameters = + BaseParameters & RepeatedParameters; + +type HandleNotificationAddedToChannelParameters = + BaseParameters & + RepeatedParameters & { + allowNewMessagesFromUnfilteredChannels: boolean; + lockChannelOrder: boolean; + } & Required, 'sort'>>; type HandleMemberUpdatedParameters = BaseParameters & { lockChannelOrder: boolean; diff --git a/src/components/ChannelList/hooks/useChannelTruncatedListener.ts b/src/components/ChannelList/hooks/useChannelTruncatedListener.ts index 77e7c8b5d..295b05447 100644 --- a/src/components/ChannelList/hooks/useChannelTruncatedListener.ts +++ b/src/components/ChannelList/hooks/useChannelTruncatedListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useChannelTruncatedListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useChannelUpdatedListener.ts b/src/components/ChannelList/hooks/useChannelUpdatedListener.ts index aa6fcfda8..39620b7e8 100644 --- a/src/components/ChannelList/hooks/useChannelUpdatedListener.ts +++ b/src/components/ChannelList/hooks/useChannelUpdatedListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useChannelUpdatedListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useChannelVisibleListener.ts b/src/components/ChannelList/hooks/useChannelVisibleListener.ts index cd7120292..8b4cd8c34 100644 --- a/src/components/ChannelList/hooks/useChannelVisibleListener.ts +++ b/src/components/ChannelList/hooks/useChannelVisibleListener.ts @@ -10,7 +10,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useChannelVisibleListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useConnectionRecoveredListener.ts b/src/components/ChannelList/hooks/useConnectionRecoveredListener.ts index d54bcebc5..4e6543893 100644 --- a/src/components/ChannelList/hooks/useConnectionRecoveredListener.ts +++ b/src/components/ChannelList/hooks/useConnectionRecoveredListener.ts @@ -5,7 +5,7 @@ import { useChatContext } from '../../../context/ChatContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useConnectionRecoveredListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( forceUpdate?: () => void, ) => { diff --git a/src/components/ChannelList/hooks/useMessageNewListener.ts b/src/components/ChannelList/hooks/useMessageNewListener.ts index 548d5f22d..889501d4f 100644 --- a/src/components/ChannelList/hooks/useMessageNewListener.ts +++ b/src/components/ChannelList/hooks/useMessageNewListener.ts @@ -10,7 +10,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useMessageNewListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts b/src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts index 520d580ef..0dfb07421 100644 --- a/src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts +++ b/src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts @@ -10,7 +10,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useNotificationAddedToChannelListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useNotificationMessageNewListener.ts b/src/components/ChannelList/hooks/useNotificationMessageNewListener.ts index 6fd242b7d..5f39beef9 100644 --- a/src/components/ChannelList/hooks/useNotificationMessageNewListener.ts +++ b/src/components/ChannelList/hooks/useNotificationMessageNewListener.ts @@ -10,7 +10,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useNotificationMessageNewListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/useNotificationRemovedFromChannelListener.ts b/src/components/ChannelList/hooks/useNotificationRemovedFromChannelListener.ts index 00a5d3db2..57366e058 100644 --- a/src/components/ChannelList/hooks/useNotificationRemovedFromChannelListener.ts +++ b/src/components/ChannelList/hooks/useNotificationRemovedFromChannelListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useNotificationRemovedFromChannelListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, customHandler?: ( diff --git a/src/components/ChannelList/hooks/usePaginatedChannels.ts b/src/components/ChannelList/hooks/usePaginatedChannels.ts index 8387bdc09..341f4af75 100644 --- a/src/components/ChannelList/hooks/usePaginatedChannels.ts +++ b/src/components/ChannelList/hooks/usePaginatedChannels.ts @@ -17,7 +17,7 @@ const MIN_RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS = 2000; type AllowedQueryType = Extract; export type CustomQueryChannelParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { currentChannels: Array>; queryType: AllowedQueryType; @@ -26,11 +26,11 @@ export type CustomQueryChannelParams< }; export type CustomQueryChannelsFn< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (params: CustomQueryChannelParams) => Promise; export const usePaginatedChannels = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( client: StreamChat, filters: ChannelFilters, @@ -53,7 +53,7 @@ export const usePaginatedChannels = < const recoveryThrottleInterval = recoveryThrottleIntervalMs < MIN_RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS ? MIN_RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS - : recoveryThrottleIntervalMs ?? RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS; + : (recoveryThrottleIntervalMs ?? RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS); // memoize props const filterString = useMemo(() => JSON.stringify(filters), [filters]); const sortString = useMemo(() => JSON.stringify(sort), [sort]); diff --git a/src/components/ChannelList/hooks/useSelectedChannelState.ts b/src/components/ChannelList/hooks/useSelectedChannelState.ts index bf1e67730..3100e6ffa 100644 --- a/src/components/ChannelList/hooks/useSelectedChannelState.ts +++ b/src/components/ChannelList/hooks/useSelectedChannelState.ts @@ -17,8 +17,8 @@ export function useSelectedChannelState(_: { }): O | undefined; export function useSelectedChannelState({ channel, - stateChangeEventKeys = ['all'], selector, + stateChangeEventKeys = ['all'], }: { selector: (channel: Channel) => O; channel?: Channel; diff --git a/src/components/ChannelList/hooks/useUserPresenceChangedListener.ts b/src/components/ChannelList/hooks/useUserPresenceChangedListener.ts index 771942caa..9d876f994 100644 --- a/src/components/ChannelList/hooks/useUserPresenceChangedListener.ts +++ b/src/components/ChannelList/hooks/useUserPresenceChangedListener.ts @@ -7,7 +7,7 @@ import type { Channel, Event } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useUserPresenceChangedListener = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( setChannels: React.Dispatch>>>, ) => { diff --git a/src/components/ChannelList/utils.ts b/src/components/ChannelList/utils.ts index 5c3830109..64e0dd5f8 100644 --- a/src/components/ChannelList/utils.ts +++ b/src/components/ChannelList/utils.ts @@ -68,7 +68,7 @@ type MoveChannelUpwardsParams({ channels, channelToMove, diff --git a/src/components/ChannelPreview/ChannelPreview.tsx b/src/components/ChannelPreview/ChannelPreview.tsx index a25bd333e..0a3234fc9 100644 --- a/src/components/ChannelPreview/ChannelPreview.tsx +++ b/src/components/ChannelPreview/ChannelPreview.tsx @@ -19,7 +19,7 @@ import type { TranslationContextValue } from '../../context/TranslationContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type ChannelPreviewUIComponentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ChannelPreviewProps & { /** If the component's channel is the active (selected) Channel */ active?: boolean; @@ -42,7 +42,7 @@ export type ChannelPreviewUIComponentProps< }; export type ChannelPreviewProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) */ channel: Channel; @@ -72,15 +72,15 @@ export type ChannelPreviewProps< }; export const ChannelPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ChannelPreviewProps, ) => { const { channel, - Preview = ChannelPreviewMessenger, channelUpdateCount, getLatestMessagePreview = defaultGetLatestMessagePreview, + Preview = ChannelPreviewMessenger, } = props; const { channel: activeChannel, diff --git a/src/components/ChannelPreview/ChannelPreviewMessenger.tsx b/src/components/ChannelPreview/ChannelPreviewMessenger.tsx index ed93d7585..9216861bb 100644 --- a/src/components/ChannelPreview/ChannelPreviewMessenger.tsx +++ b/src/components/ChannelPreview/ChannelPreviewMessenger.tsx @@ -8,7 +8,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import type { ChannelPreviewUIComponentProps } from './ChannelPreview'; const UnMemoizedChannelPreviewMessenger = < - SCG extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + SCG extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ChannelPreviewUIComponentProps, ) => { @@ -27,9 +27,8 @@ const UnMemoizedChannelPreviewMessenger = < watchers, } = props; - const { - ChannelPreviewActionButtons = DefaultChannelPreviewActionButtons, - } = useComponentContext(); + const { ChannelPreviewActionButtons = DefaultChannelPreviewActionButtons } = + useComponentContext(); const channelPreviewButton = useRef(null); diff --git a/src/components/ChannelPreview/__tests__/ChannelPreview.test.js b/src/components/ChannelPreview/__tests__/ChannelPreview.test.js index 035ac4bb5..993e98a20 100644 --- a/src/components/ChannelPreview/__tests__/ChannelPreview.test.js +++ b/src/components/ChannelPreview/__tests__/ChannelPreview.test.js @@ -98,7 +98,6 @@ describe('ChannelPreview', () => { [c0, c1] = await client.queryChannels({}, {}); }); - // eslint-disable-next-line jest/expect-expect it('should mark channel as read, when set as active channel', async () => { // Mock the countUnread function on channel, to return 10. c0.countUnread = () => 10; diff --git a/src/components/ChannelPreview/__tests__/ChannelPreviewMessenger.test.js b/src/components/ChannelPreview/__tests__/ChannelPreviewMessenger.test.js index f60e5fb29..dad6bdefe 100644 --- a/src/components/ChannelPreview/__tests__/ChannelPreviewMessenger.test.js +++ b/src/components/ChannelPreview/__tests__/ChannelPreviewMessenger.test.js @@ -75,7 +75,6 @@ describe('ChannelPreviewMessenger', () => { fireEvent.click(getByTestId(PREVIEW_TEST_ID)); await waitFor(() => { - // eslint-disable-next-line jest/prefer-called-with expect(setActiveChannel).toHaveBeenCalledTimes(1); expect(setActiveChannel).toHaveBeenCalledWith(channel, {}); }); diff --git a/src/components/ChannelPreview/hooks/useChannelPreviewInfo.ts b/src/components/ChannelPreview/hooks/useChannelPreviewInfo.ts index 336b7eb76..27cd346a9 100644 --- a/src/components/ChannelPreview/hooks/useChannelPreviewInfo.ts +++ b/src/components/ChannelPreview/hooks/useChannelPreviewInfo.ts @@ -15,7 +15,7 @@ export type ChannelPreviewInfoParams( props: ChannelPreviewInfoParams, ) => { diff --git a/src/components/ChannelPreview/hooks/useIsChannelMuted.ts b/src/components/ChannelPreview/hooks/useIsChannelMuted.ts index cda462f77..2e9c47197 100644 --- a/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +++ b/src/components/ChannelPreview/hooks/useIsChannelMuted.ts @@ -7,7 +7,7 @@ import type { Channel } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useIsChannelMuted = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel: Channel, ) => { diff --git a/src/components/ChannelPreview/hooks/useMessageDeliveryStatus.ts b/src/components/ChannelPreview/hooks/useMessageDeliveryStatus.ts index d7c63aa34..301fcd9f3 100644 --- a/src/components/ChannelPreview/hooks/useMessageDeliveryStatus.ts +++ b/src/components/ChannelPreview/hooks/useMessageDeliveryStatus.ts @@ -12,7 +12,7 @@ export enum MessageDeliveryStatus { } type UseMessageStatusParamsChannelPreviewProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { channel: Channel; /** The last message received in a channel */ @@ -20,7 +20,7 @@ type UseMessageStatusParamsChannelPreviewProps< }; export const useMessageDeliveryStatus = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ channel, lastMessage, diff --git a/src/components/ChannelPreview/icons.tsx b/src/components/ChannelPreview/icons.tsx index 7ef798b1c..04507fdaa 100644 --- a/src/components/ChannelPreview/icons.tsx +++ b/src/components/ChannelPreview/icons.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/display-name */ import React from 'react'; import { ComponentPropsWithoutRef } from 'react'; diff --git a/src/components/ChannelPreview/utils.tsx b/src/components/ChannelPreview/utils.tsx index 4b79ddd0b..9a59b7bb3 100644 --- a/src/components/ChannelPreview/utils.tsx +++ b/src/components/ChannelPreview/utils.tsx @@ -12,7 +12,7 @@ import { ChatContextValue } from '../../context'; export const renderPreviewText = (text: string) => {text}; const getLatestPollVote = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( latestVotesByOption: Record[]>, ) => { @@ -28,7 +28,7 @@ const getLatestPollVote = < }; export const getLatestMessagePreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel: Channel, t: TranslationContextValue['t'], @@ -55,7 +55,7 @@ export const getLatestMessagePreview = < const createdBy = poll.created_by?.id === channel.getClient().userID ? t('You') - : poll.created_by?.name ?? t('Poll'); + : (poll.created_by?.name ?? t('Poll')); return t('📊 {{createdBy}} created: {{ pollName}}', { createdBy, pollName: poll.name, @@ -72,7 +72,7 @@ export const getLatestMessagePreview = < votedBy: latestVote?.user?.id === channel.getClient().userID ? t('You') - : latestVote.user?.name ?? t('Poll'), + : (latestVote.user?.name ?? t('Poll')), }); } } @@ -98,7 +98,7 @@ export const getLatestMessagePreview = < export type GroupChannelDisplayInfo = { image?: string; name?: string }[]; export const getGroupChannelDisplayInfo = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel: Channel, ): GroupChannelDisplayInfo | undefined => { @@ -116,7 +116,7 @@ export const getGroupChannelDisplayInfo = < }; const getChannelDisplayInfo = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( info: 'name' | 'image', channel: Channel, @@ -130,14 +130,14 @@ const getChannelDisplayInfo = < }; export const getDisplayTitle = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel: Channel, currentUser?: UserResponse, ) => getChannelDisplayInfo('name', channel, currentUser); export const getDisplayImage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( channel: Channel, currentUser?: UserResponse, diff --git a/src/components/ChannelSearch/ChannelSearch.tsx b/src/components/ChannelSearch/ChannelSearch.tsx index d6229db6f..019f4743a 100644 --- a/src/components/ChannelSearch/ChannelSearch.tsx +++ b/src/components/ChannelSearch/ChannelSearch.tsx @@ -22,7 +22,7 @@ export type AdditionalChannelSearchProps = { }; export type ChannelSearchProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = AdditionalSearchBarProps & AdditionalSearchInputProps & AdditionalSearchResultsProps & @@ -30,7 +30,7 @@ export type ChannelSearchProps< ChannelSearchControllerParams; const UnMemoizedChannelSearch = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ChannelSearchProps, ) => { @@ -44,11 +44,11 @@ const UnMemoizedChannelSearch = < SearchBar = DefaultSearchBar, SearchEmpty, SearchInput = DefaultSearchInput, - SearchLoading, SearchInputIcon, + SearchLoading, SearchResultItem, - SearchResultsList, SearchResultsHeader, + SearchResultsList, ...channelSearchParams } = props; diff --git a/src/components/ChannelSearch/SearchResults.tsx b/src/components/ChannelSearch/SearchResults.tsx index ea03d8246..05f9da69c 100644 --- a/src/components/ChannelSearch/SearchResults.tsx +++ b/src/components/ChannelSearch/SearchResults.tsx @@ -21,11 +21,11 @@ const DefaultSearchEmpty = () => { }; export type SearchResultsHeaderProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, 'results'>; const DefaultSearchResultsHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ results, }: SearchResultsHeaderProps) => { @@ -43,7 +43,7 @@ const DefaultSearchResultsHeader = < }; export type SearchResultsListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Required< Pick, 'results' | 'SearchResultItem' | 'selectResult'> > & { @@ -51,7 +51,7 @@ export type SearchResultsListProps< }; const DefaultSearchResultsList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: SearchResultsListProps, ) => { @@ -73,7 +73,7 @@ const DefaultSearchResultsList = < }; export type SearchResultItemProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, 'selectResult'> & { index: number; result: ChannelOrUserResponse; @@ -81,7 +81,7 @@ export type SearchResultItemProps< }; const DefaultSearchResultItem = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: SearchResultItemProps, ) => { @@ -143,7 +143,7 @@ const ResultsContainer = ({ }; export type SearchResultsController< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { results: Array>; searching: boolean; @@ -151,7 +151,7 @@ export type SearchResultsController< }; export type AdditionalSearchResultsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Display search results as an absolutely positioned popup, defaults to false and shows inline */ popupResults?: boolean; @@ -168,22 +168,22 @@ export type AdditionalSearchResultsProps< }; export type SearchResultsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = AdditionalSearchResultsProps & SearchResultsController; export const SearchResults = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: SearchResultsProps, ) => { const { popupResults, results, - searching, SearchEmpty = DefaultSearchEmpty, - SearchResultsHeader = DefaultSearchResultsHeader, + searching, SearchLoading, SearchResultItem = DefaultSearchResultItem, + SearchResultsHeader = DefaultSearchResultsHeader, SearchResultsList = DefaultSearchResultsList, selectResult, } = props; diff --git a/src/components/ChannelSearch/__tests__/SearchBar.test.js b/src/components/ChannelSearch/__tests__/SearchBar.test.js index 0f5f8f5ac..cf391b341 100644 --- a/src/components/ChannelSearch/__tests__/SearchBar.test.js +++ b/src/components/ChannelSearch/__tests__/SearchBar.test.js @@ -43,7 +43,7 @@ describe('SearchBar', () => { beforeEach(async () => { const user = generateUser(); client = await getTestClientWithUser({ id: user.id }); - useMockedApis(client, [queryUsersApi([user])]); // eslint-disable-line react-hooks/rules-of-hooks + useMockedApis(client, [queryUsersApi([user])]); }); it.each([ diff --git a/src/components/ChannelSearch/hooks/useChannelSearch.ts b/src/components/ChannelSearch/hooks/useChannelSearch.ts index f48da6ab5..d55ca4ef7 100644 --- a/src/components/ChannelSearch/hooks/useChannelSearch.ts +++ b/src/components/ChannelSearch/hooks/useChannelSearch.ts @@ -22,7 +22,7 @@ import type { SearchResultsController } from '../SearchResults'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type ChannelSearchFunctionParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { setQuery: React.Dispatch>; setResults: React.Dispatch[]>>; @@ -30,11 +30,11 @@ export type ChannelSearchFunctionParams< }; export type SearchController< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = SearchInputController & SearchBarController & SearchResultsController; export type SearchQueryParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { channelFilters?: { filters?: ChannelFilters; @@ -51,7 +51,7 @@ export type SearchQueryParams< }; export type ChannelSearchParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** The type of channel to create on user result select, defaults to `messaging` */ channelType?: string; @@ -82,14 +82,14 @@ export type ChannelSearchParams< }; export type ChannelSearchControllerParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ChannelSearchParams & { /** Set the array of channels displayed in the ChannelList */ setChannels?: React.Dispatch>>>; }; export const useChannelSearch = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ channelType = 'messaging', clearSearchOnClickOutside = true, @@ -156,7 +156,6 @@ export const useChannelSearch = < document.addEventListener('click', clickListener); return () => document.removeEventListener('click', clickListener); - // eslint-disable-next-line react-hooks/exhaustive-deps }, [disabled, inputIsFocused, query, exitSearch, clearSearchOnClickOutside]); useEffect(() => { @@ -213,7 +212,7 @@ export const useChannelSearch = < let results: ChannelOrUserResponse[] = []; try { const userQueryPromise = client.queryUsers( - // @ts-expect-error + // @ts-expect-error valid query { $or: [{ id: { $autocomplete: text } }, { name: { $autocomplete: text } }], ...searchQueryParams?.userFilters?.filters, @@ -228,7 +227,7 @@ export const useChannelSearch = < results = users.filter((u) => u.id !== client.user?.id); } else { const channelQueryPromise = client.queryChannels( - // @ts-expect-error + // @ts-expect-error valid query { name: { $autocomplete: text }, ...searchQueryParams?.channelFilters?.filters, diff --git a/src/components/ChannelSearch/utils.ts b/src/components/ChannelSearch/utils.ts index 31409f92e..89e03d308 100644 --- a/src/components/ChannelSearch/utils.ts +++ b/src/components/ChannelSearch/utils.ts @@ -3,11 +3,11 @@ import type { Channel, UserResponse } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type ChannelOrUserResponse< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Channel | UserResponse; export const isChannel = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( output: ChannelOrUserResponse, ): output is Channel => (output as Channel).cid != null; diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index b908ee47b..f65b6a1ff 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -15,7 +15,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import type { MessageContextValue } from '../../context'; export type ChatProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** The StreamChat client object */ client: StreamChat; @@ -44,7 +44,7 @@ export type ChatProps< * as it provides the ChatContext. */ export const Chat = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: PropsWithChildren>, ) => { diff --git a/src/components/Chat/hooks/useChat.ts b/src/components/Chat/hooks/useChat.ts index 168c4c76e..a31d2a32d 100644 --- a/src/components/Chat/hooks/useChat.ts +++ b/src/components/Chat/hooks/useChat.ts @@ -13,7 +13,7 @@ import type { AppSettingsAPIResponse, Channel, Event, Mute, StreamChat } from 's import type { DefaultStreamChatGenerics } from '../../../types/types'; export type UseChatParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { client: StreamChat; defaultLanguage?: SupportedTranslations; @@ -22,7 +22,7 @@ export type UseChatParams< }; export const useChat = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ client, defaultLanguage = 'en', diff --git a/src/components/Chat/hooks/useCreateChatContext.ts b/src/components/Chat/hooks/useCreateChatContext.ts index d9cec2b0b..542362847 100644 --- a/src/components/Chat/hooks/useCreateChatContext.ts +++ b/src/components/Chat/hooks/useCreateChatContext.ts @@ -4,7 +4,7 @@ import type { ChatContextValue } from '../../../context/ChatContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useCreateChatContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( value: ChatContextValue, ) => { diff --git a/src/components/ChatAutoComplete/ChatAutoComplete.tsx b/src/components/ChatAutoComplete/ChatAutoComplete.tsx index 7c5f2c512..f405dcde6 100644 --- a/src/components/ChatAutoComplete/ChatAutoComplete.tsx +++ b/src/components/ChatAutoComplete/ChatAutoComplete.tsx @@ -16,24 +16,24 @@ import { EmojiSearchIndex, EmojiSearchIndexResult } from '../MessageInput'; type ObjectUnion = T[keyof T]; export type SuggestionCommand< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = CommandResponse; export type SuggestionUser< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = UserResponse; export type SuggestionEmoji = EmojiSearchIndexResult & T; export type SuggestionItem< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - T extends UnknownType = UnknownType + T extends UnknownType = UnknownType, > = SuggestionUser | SuggestionCommand | SuggestionEmoji; // FIXME: entity type is wrong, fix export type SuggestionItemProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - T extends UnknownType = UnknownType + T extends UnknownType = UnknownType, > = { className: string; component: React.ComponentType<{ @@ -59,41 +59,39 @@ export interface SuggestionHeaderProps { export type SuggestionListProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger -> = ObjectUnion< - { - [key in keyof TriggerSettings]: { - component: TriggerSettings[key]['component']; - currentTrigger: string; - dropdownScroll: (element: HTMLDivElement) => void; - getSelectedItem: - | ((item: Parameters[key]['output']>[0]) => void) - | null; - getTextToReplace: ( - item: Parameters[key]['output']>[0], - ) => { - caretPosition: 'start' | 'end' | 'next' | number; - text: string; - key?: string; - }; - Header: React.ComponentType; - onSelect: (newToken: { - caretPosition: 'start' | 'end' | 'next' | number; - text: string; - }) => void; - selectionEnd: number; - SuggestionItem: React.ComponentType; - values: Parameters< - Parameters[key]['dataProvider']>[2] - >[0]; - className?: string; - itemClassName?: string; - itemStyle?: React.CSSProperties; - style?: React.CSSProperties; - value?: string; + V extends CustomTrigger = CustomTrigger, +> = ObjectUnion<{ + [key in keyof TriggerSettings]: { + component: TriggerSettings[key]['component']; + currentTrigger: string; + dropdownScroll: (element: HTMLDivElement) => void; + getSelectedItem: + | ((item: Parameters[key]['output']>[0]) => void) + | null; + getTextToReplace: ( + item: Parameters[key]['output']>[0], + ) => { + caretPosition: 'start' | 'end' | 'next' | number; + text: string; + key?: string; }; - } ->; + Header: React.ComponentType; + onSelect: (newToken: { + caretPosition: 'start' | 'end' | 'next' | number; + text: string; + }) => void; + selectionEnd: number; + SuggestionItem: React.ComponentType; + values: Parameters< + Parameters[key]['dataProvider']>[2] + >[0]; + className?: string; + itemClassName?: string; + itemStyle?: React.CSSProperties; + style?: React.CSSProperties; + value?: string; + }; +}>; export type ChatAutoCompleteProps = { /** Override the default disabled state of the underlying `textarea` component. */ @@ -120,14 +118,12 @@ export type ChatAutoCompleteProps = { const UnMemoizedChatAutoComplete = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: ChatAutoCompleteProps, ) => { - const { - AutocompleteSuggestionItem: SuggestionItem, - AutocompleteSuggestionList: SuggestionList, - } = useComponentContext('ChatAutoComplete'); + const { AutocompleteSuggestionItem: SuggestionItem, AutocompleteSuggestionList: SuggestionList } = + useComponentContext('ChatAutoComplete'); const { t } = useTranslationContext('ChatAutoComplete'); const messageInput = useMessageInputContext('ChatAutoComplete'); diff --git a/src/components/ChatAutoComplete/__tests__/ChatAutocomplete.test.js b/src/components/ChatAutoComplete/__tests__/ChatAutocomplete.test.js index d5055a162..c6b90369a 100644 --- a/src/components/ChatAutoComplete/__tests__/ChatAutocomplete.test.js +++ b/src/components/ChatAutoComplete/__tests__/ChatAutocomplete.test.js @@ -236,7 +236,6 @@ describe('ChatAutoComplete', () => { typeText(userAutocompleteText); const userText = await queryAllByText(user.name); - // eslint-disable-next-line jest-dom/prefer-in-document expect(userText).toHaveLength(0); }); diff --git a/src/components/ChatView/ChatView.tsx b/src/components/ChatView/ChatView.tsx index 7ff684c67..014731c87 100644 --- a/src/components/ChatView/ChatView.tsx +++ b/src/components/ChatView/ChatView.tsx @@ -10,10 +10,10 @@ import type { PropsWithChildren } from 'react'; import type { Thread, ThreadManagerState } from 'stream-chat'; import clsx from 'clsx'; -const availableChatViews = ['channels', 'threads'] as const; +type ChatView = 'channels' | 'threads'; type ChatViewContextValue = { - activeChatView: typeof availableChatViews[number]; + activeChatView: ChatView; setActiveChatView: (cv: ChatViewContextValue['activeChatView']) => void; }; @@ -23,9 +23,8 @@ const ChatViewContext = createContext({ }); export const ChatView = ({ children }: PropsWithChildren) => { - const [activeChatView, setActiveChatView] = useState( - 'channels', - ); + const [activeChatView, setActiveChatView] = + useState('channels'); const { theme } = useChatContext(); @@ -60,9 +59,8 @@ export const useThreadsViewContext = () => useContext(ThreadsViewContext); const ThreadsView = ({ children }: PropsWithChildren) => { const { activeChatView } = useContext(ChatViewContext); - const [activeThread, setActiveThread] = useState( - undefined, - ); + const [activeThread, setActiveThread] = + useState(undefined); const value = useMemo(() => ({ activeThread, setActiveThread }), [activeThread]); diff --git a/src/components/CommandItem/__tests__/CommandItem.test.js b/src/components/CommandItem/__tests__/CommandItem.test.js index fceb833cb..dd21eb54c 100644 --- a/src/components/CommandItem/__tests__/CommandItem.test.js +++ b/src/components/CommandItem/__tests__/CommandItem.test.js @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import { CommandItem } from '../CommandItem'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('commandItem', () => { it('should render component with empty entity', () => { diff --git a/src/components/DateSeparator/__tests__/DateSeparator.test.js b/src/components/DateSeparator/__tests__/DateSeparator.test.js index bcd549043..0ae4015f2 100644 --- a/src/components/DateSeparator/__tests__/DateSeparator.test.js +++ b/src/components/DateSeparator/__tests__/DateSeparator.test.js @@ -12,7 +12,7 @@ import { Streami18n } from '../../../i18n'; Dayjs.extend(calendar); -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); const DATE_SEPARATOR_TEST_ID = 'date-separator'; const dateMock = 'the date'; diff --git a/src/components/Dialog/FormDialog.tsx b/src/components/Dialog/FormDialog.tsx index d9eacd9d3..07fa88cc7 100644 --- a/src/components/Dialog/FormDialog.tsx +++ b/src/components/Dialog/FormDialog.tsx @@ -36,7 +36,7 @@ type FormValue> = { }; export const FormDialog = < - F extends FormValue> = FormValue> + F extends FormValue> = FormValue>, >({ className, close, diff --git a/src/components/DragAndDrop/DragAndDropContainer.tsx b/src/components/DragAndDrop/DragAndDropContainer.tsx index fda1cbd90..5a054cdf0 100644 --- a/src/components/DragAndDrop/DragAndDropContainer.tsx +++ b/src/components/DragAndDrop/DragAndDropContainer.tsx @@ -22,8 +22,8 @@ export const DragAndDropContainer = ({ dragStartIndex === null || dragOverIndex === null ? undefined : dragStartIndex <= dragOverIndex - ? 'down' - : 'up'; + ? 'down' + : 'up'; const childrenArray = React.Children.toArray(children); diff --git a/src/components/EmoticonItem/__tests__/EmoticonItem.test.js b/src/components/EmoticonItem/__tests__/EmoticonItem.test.js index 0ac8822c9..286b08372 100644 --- a/src/components/EmoticonItem/__tests__/EmoticonItem.test.js +++ b/src/components/EmoticonItem/__tests__/EmoticonItem.test.js @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import { EmoticonItem } from '../EmoticonItem'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('EmoticonItem', () => { it('should render component with empty entity', () => { diff --git a/src/components/EmptyStateIndicator/__tests__/EmptyStateIndicator.test.js b/src/components/EmptyStateIndicator/__tests__/EmptyStateIndicator.test.js index 4e2703f3d..34ec6dc44 100644 --- a/src/components/EmptyStateIndicator/__tests__/EmptyStateIndicator.test.js +++ b/src/components/EmptyStateIndicator/__tests__/EmptyStateIndicator.test.js @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import { EmptyStateIndicator } from '../EmptyStateIndicator'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('EmptyStateIndicator', () => { it('should render with default props', () => { diff --git a/src/components/EventComponent/EventComponent.tsx b/src/components/EventComponent/EventComponent.tsx index ce09b8e21..44d1f80db 100644 --- a/src/components/EventComponent/EventComponent.tsx +++ b/src/components/EventComponent/EventComponent.tsx @@ -10,7 +10,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import type { TimestampFormatterOptions } from '../../i18n/types'; export type EventComponentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = TimestampFormatterOptions & { /** Message object */ message: StreamMessage; @@ -22,11 +22,11 @@ export type EventComponentProps< * Component to display system and channel event messages */ const UnMemoizedEventComponent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: EventComponentProps, ) => { - const { calendar, calendarFormats, format, Avatar = DefaultAvatar, message } = props; + const { Avatar = DefaultAvatar, calendar, calendarFormats, format, message } = props; const { t, tDateTimeParser } = useTranslationContext('EventComponent'); const { created_at = '', event, text, type } = message; diff --git a/src/components/Gallery/Gallery.tsx b/src/components/Gallery/Gallery.tsx index c5bd3aa50..b4cc3954b 100644 --- a/src/components/Gallery/Gallery.tsx +++ b/src/components/Gallery/Gallery.tsx @@ -14,7 +14,7 @@ import type { Attachment } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type GalleryProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { images: (( | { @@ -27,7 +27,7 @@ export type GalleryProps< }; const UnMemoizedGallery = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: GalleryProps, ) => { @@ -36,9 +36,8 @@ const UnMemoizedGallery = < const [index, setIndex] = useState(0); const [modalOpen, setModalOpen] = useState(false); - const { BaseImage = DefaultBaseImage, ModalGallery = DefaultModalGallery } = useComponentContext( - 'Gallery', - ); + const { BaseImage = DefaultBaseImage, ModalGallery = DefaultModalGallery } = + useComponentContext('Gallery'); const { t } = useTranslationContext('Gallery'); const imageFallbackTitle = t('User uploaded content'); diff --git a/src/components/Gallery/Image.tsx b/src/components/Gallery/Image.tsx index d3d23f7fc..70f7e6373 100644 --- a/src/components/Gallery/Image.tsx +++ b/src/components/Gallery/Image.tsx @@ -10,7 +10,7 @@ import type { Attachment } from 'stream-chat'; import type { DefaultStreamChatGenerics, Dimensions } from '../../types/types'; export type ImageProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { dimensions?: Dimensions; innerRef?: MutableRefObject; @@ -32,16 +32,15 @@ export type ImageProps< * A simple component that displays an image. */ export const ImageComponent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ImageProps, ) => { - const { dimensions = {}, fallback, image_url, thumb_url, innerRef, previewUrl, style } = props; + const { dimensions = {}, fallback, image_url, innerRef, previewUrl, style, thumb_url } = props; const [modalIsOpen, setModalIsOpen] = useState(false); - const { BaseImage = DefaultBaseImage, ModalGallery = DefaultModalGallery } = useComponentContext( - 'ImageComponent', - ); + const { BaseImage = DefaultBaseImage, ModalGallery = DefaultModalGallery } = + useComponentContext('ImageComponent'); const imageSrc = sanitizeUrl(previewUrl || image_url || thumb_url); diff --git a/src/components/Gallery/ModalGallery.tsx b/src/components/Gallery/ModalGallery.tsx index dd55e040f..f2a7942b3 100644 --- a/src/components/Gallery/ModalGallery.tsx +++ b/src/components/Gallery/ModalGallery.tsx @@ -7,7 +7,7 @@ import type { Attachment } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type ModalGalleryProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** The images for the Carousel component */ images: Attachment[]; @@ -26,7 +26,7 @@ const renderItem = ({ original, originalAlt }: ReactImageGalleryItem) => ( ); export const ModalGallery = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ModalGalleryProps, ) => { diff --git a/src/components/InfiniteScrollPaginator/InfiniteScrollPaginator.tsx b/src/components/InfiniteScrollPaginator/InfiniteScrollPaginator.tsx index b26b7168a..79126279d 100644 --- a/src/components/InfiniteScrollPaginator/InfiniteScrollPaginator.tsx +++ b/src/components/InfiniteScrollPaginator/InfiniteScrollPaginator.tsx @@ -25,12 +25,12 @@ export type InfiniteScrollPaginatorProps = React.ComponentProps<'div'> & { export const InfiniteScrollPaginator = (props: PropsWithChildren) => { const { children, + className, listenToScroll, loadNextOnScrollToBottom, loadNextOnScrollToTop, threshold = DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD, useCapture = false, - className, ...componentProps } = props; diff --git a/src/components/InfiniteScrollPaginator/__tests__/InfiniteScroll.test.js b/src/components/InfiniteScrollPaginator/__tests__/InfiniteScroll.test.js index 206768fd2..ef122d037 100644 --- a/src/components/InfiniteScrollPaginator/__tests__/InfiniteScroll.test.js +++ b/src/components/InfiniteScrollPaginator/__tests__/InfiniteScroll.test.js @@ -105,7 +105,7 @@ describe('InfiniteScroll', () => { consoleWarnSpy.mockRestore(); expect(oldLoaderSpy).not.toHaveBeenCalled(); - // eslint-disable-next-line jest/prefer-called-with + expect(newLoaderSpy).toHaveBeenCalled(); }, ); diff --git a/src/components/Loading/LoadingErrorIndicator.tsx b/src/components/Loading/LoadingErrorIndicator.tsx index fc0b635bb..f79ed6693 100644 --- a/src/components/Loading/LoadingErrorIndicator.tsx +++ b/src/components/Loading/LoadingErrorIndicator.tsx @@ -15,11 +15,7 @@ const UnMemoizedLoadingErrorIndicator = ({ error }: LoadingErrorIndicatorProps) if (!error) return null; - return ( -
- {t('Error: {{ errorMessage }}', { errorMessage: error.message })} -
- ); + return
{t('Error: {{ errorMessage }}', { errorMessage: error.message })}
; }; export const LoadingErrorIndicator = React.memo( diff --git a/src/components/Loading/__tests__/LoadingChannels.test.js b/src/components/Loading/__tests__/LoadingChannels.test.js index 5318a3c9d..bb684cca6 100644 --- a/src/components/Loading/__tests__/LoadingChannels.test.js +++ b/src/components/Loading/__tests__/LoadingChannels.test.js @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import { LoadingChannels } from '../LoadingChannels'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('LoadingChannels', () => { it('should render component with default props', () => { diff --git a/src/components/Loading/__tests__/LoadingErrorIndicator.test.js b/src/components/Loading/__tests__/LoadingErrorIndicator.test.js index 946e08708..4d65ac4f8 100644 --- a/src/components/Loading/__tests__/LoadingErrorIndicator.test.js +++ b/src/components/Loading/__tests__/LoadingErrorIndicator.test.js @@ -9,7 +9,7 @@ import { Chat } from '../../Chat'; import { getTestClientWithUser } from '../../../mock-builders'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('LoadingErrorIndicator', () => { it('should return null if no error is provided', () => { diff --git a/src/components/Loading/__tests__/LoadingIndicator.test.js b/src/components/Loading/__tests__/LoadingIndicator.test.js index 1c87815be..0b4622911 100644 --- a/src/components/Loading/__tests__/LoadingIndicator.test.js +++ b/src/components/Loading/__tests__/LoadingIndicator.test.js @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import { LoadingIndicator } from '../LoadingIndicator'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('LoadingIndicator', () => { it('should render with default props', () => { diff --git a/src/components/MML/MML.tsx b/src/components/MML/MML.tsx index 6d2c3c679..76fd6c498 100644 --- a/src/components/MML/MML.tsx +++ b/src/components/MML/MML.tsx @@ -5,6 +5,7 @@ import { useChatContext } from '../../context/ChatContext'; import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler'; const MMLReact = React.lazy(async () => { + // eslint-disable-next-line import/no-extraneous-dependencies const mml = await import('mml-react'); return { default: mml.MML }; }); diff --git a/src/components/MML/__tests__/MML.test.js b/src/components/MML/__tests__/MML.test.js index 932c36db5..c84c52f5b 100644 --- a/src/components/MML/__tests__/MML.test.js +++ b/src/components/MML/__tests__/MML.test.js @@ -7,7 +7,7 @@ import { MML } from '../MML'; import { ChatProvider } from '../../../context/ChatContext'; import { MessageProvider } from '../../../context/MessageContext'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); const renderComponent = async ( { chatCtx = {}, messageCtx = {}, mmlProps }, diff --git a/src/components/MediaRecorder/AudioRecorder/__tests__/AudioRecorder.test.js b/src/components/MediaRecorder/AudioRecorder/__tests__/AudioRecorder.test.js index eb260da33..afc5c6bcd 100644 --- a/src/components/MediaRecorder/AudioRecorder/__tests__/AudioRecorder.test.js +++ b/src/components/MediaRecorder/AudioRecorder/__tests__/AudioRecorder.test.js @@ -116,13 +116,10 @@ window.navigator.permissions = { query: jest.fn(), }; -// eslint-disable-next-line window.MediaRecorder = MediaRecorderMock; -// eslint-disable-next-line window.AudioContext = AudioContextMock; -// eslint-disable-next-line window.AnalyserNode = AnalyserNodeMock; const fileObjectURL = 'fileObjectURL'; @@ -307,6 +304,7 @@ describe('MessageInput', () => { }); expect(doFileUploadRequest).toHaveBeenCalledTimes(1); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { localMetadata, ...uploadedRecordingAtt } = recording; expect(sendMessage.mock.calls[0][0]).toStrictEqual({ attachments: [uploadedRecordingAtt], diff --git a/src/components/MediaRecorder/classes/BrowserPermission.ts b/src/components/MediaRecorder/classes/BrowserPermission.ts index 749c2c117..0ecb702ae 100644 --- a/src/components/MediaRecorder/classes/BrowserPermission.ts +++ b/src/components/MediaRecorder/classes/BrowserPermission.ts @@ -42,7 +42,7 @@ export class BrowserPermission { const status = this.status.value; const handlePermissionChange = (e: Event) => { - const { state } = ((e as unknown) as ChangeEvent).target; + const { state } = (e as unknown as ChangeEvent).target; this.state.next(state); }; status.addEventListener('change', handlePermissionChange); @@ -67,7 +67,7 @@ export class BrowserPermission { let permissionState: PermissionState; try { const permissionStatus = await navigator.permissions.query({ - name: (this.name as unknown) as PermissionName, + name: this.name as unknown as PermissionName, }); permissionState = permissionStatus.state; this.status.next(permissionStatus); diff --git a/src/components/MediaRecorder/classes/MediaRecorderController.ts b/src/components/MediaRecorder/classes/MediaRecorderController.ts index 13533c52a..b4bc91cb6 100644 --- a/src/components/MediaRecorder/classes/MediaRecorderController.ts +++ b/src/components/MediaRecorder/classes/MediaRecorderController.ts @@ -80,7 +80,7 @@ export enum RecordingAttachmentType { } export class MediaRecorderController< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > { permission: BrowserPermission; mediaRecorder: MediaRecorder | undefined; diff --git a/src/components/MediaRecorder/classes/__tests__/AmplitudeRecorder.test.js b/src/components/MediaRecorder/classes/__tests__/AmplitudeRecorder.test.js index 1cef13a0d..8ae669592 100644 --- a/src/components/MediaRecorder/classes/__tests__/AmplitudeRecorder.test.js +++ b/src/components/MediaRecorder/classes/__tests__/AmplitudeRecorder.test.js @@ -5,7 +5,6 @@ import { } from '../AmplitudeRecorder'; import { AudioContextMock } from '../../../../mock-builders/browser'; -// eslint-disable-next-line window.AudioContext = AudioContextMock; const intervalID = 1; diff --git a/src/components/MediaRecorder/classes/__tests__/MediaRecorderController.test.js b/src/components/MediaRecorder/classes/__tests__/MediaRecorderController.test.js index ce89e1593..1e25f43ea 100644 --- a/src/components/MediaRecorder/classes/__tests__/MediaRecorderController.test.js +++ b/src/components/MediaRecorder/classes/__tests__/MediaRecorderController.test.js @@ -65,10 +65,8 @@ const expectRegistersError = async ({ action, controller, errorMsg, notification notificationSubscription?.unsubscribe(); }; -// eslint-disable-next-line window.MediaRecorder = MediaRecorderMock; -// eslint-disable-next-line window.AudioContext = AudioContextMock; // eslint-disable-next-line diff --git a/src/components/MediaRecorder/hooks/useMediaRecorder.ts b/src/components/MediaRecorder/hooks/useMediaRecorder.ts index a1550d633..f08f63e5e 100644 --- a/src/components/MediaRecorder/hooks/useMediaRecorder.ts +++ b/src/components/MediaRecorder/hooks/useMediaRecorder.ts @@ -10,7 +10,7 @@ import type { LocalVoiceRecordingAttachment } from '../../MessageInput'; import type { DefaultStreamChatGenerics } from '../../../types'; export type RecordingController< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { completeRecording: () => void; permissionState?: PermissionState; @@ -20,7 +20,7 @@ export type RecordingController< }; type UseMediaRecorderParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick< MessageInputContextValue, 'asyncMessagesMultiSendEnabled' | 'handleSubmit' | 'uploadAttachment' @@ -31,7 +31,7 @@ type UseMediaRecorderParams< }; export const useMediaRecorder = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ asyncMessagesMultiSendEnabled, enabled, diff --git a/src/components/Message/FixedHeightMessage.tsx b/src/components/Message/FixedHeightMessage.tsx index d72a8e9aa..1baa2a933 100644 --- a/src/components/Message/FixedHeightMessage.tsx +++ b/src/components/Message/FixedHeightMessage.tsx @@ -29,8 +29,8 @@ const selectColor = (number: number, dark: boolean) => { const hashUserId = (userId: string) => { const hash = userId.split('').reduce((acc, c) => { - acc = (acc << 5) - acc + c.charCodeAt(0); // eslint-disable-line - return acc & acc; // eslint-disable-line no-bitwise + acc = (acc << 5) - acc + c.charCodeAt(0); + return acc & acc; }, 0); return Math.abs(hash) / 10 ** Math.ceil(Math.log10(Math.abs(hash) + 1)); }; @@ -39,14 +39,14 @@ const getUserColor = (theme: string, userId: string) => selectColor(hashUserId(userId), theme.includes('dark')); export type FixedHeightMessageProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { groupedByUser?: boolean; message?: StreamMessage; }; const UnMemoizedFixedHeightMessage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: FixedHeightMessageProps, ) => { @@ -54,14 +54,11 @@ const UnMemoizedFixedHeightMessage = < const { theme } = useChatContext('FixedHeightMessage'); - const { - groupedByUser: contextGroupedByUser, - message: contextMessage, - } = useMessageContext('FixedHeightMessage'); + const { groupedByUser: contextGroupedByUser, message: contextMessage } = + useMessageContext('FixedHeightMessage'); - const { MessageDeleted = DefaultMessageDeleted } = useComponentContext( - 'FixedHeightMessage', - ); + const { MessageDeleted = DefaultMessageDeleted } = + useComponentContext('FixedHeightMessage'); const { userLanguage } = useTranslationContext('FixedHeightMessage'); @@ -75,10 +72,10 @@ const UnMemoizedFixedHeightMessage = < const messageTextToRender = message?.i18n?.[`${userLanguage}_text` as `${TranslationLanguages}_text`] || message?.text; - const renderedText = useMemo(() => renderText(messageTextToRender, message.mentioned_users), [ - message.mentioned_users, - messageTextToRender, - ]); + const renderedText = useMemo( + () => renderText(messageTextToRender, message.mentioned_users), + [message.mentioned_users, messageTextToRender], + ); const userId = message.user?.id || ''; const userColor = useMemo(() => getUserColor(theme, userId), [userId, theme]); diff --git a/src/components/Message/Message.tsx b/src/components/Message/Message.tsx index 786c9046a..7bfb598b5 100644 --- a/src/components/Message/Message.tsx +++ b/src/components/Message/Message.tsx @@ -53,7 +53,7 @@ type MessageContextPropsToPick = | 'sortReactionDetails'; type MessageWithContextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, MessagePropsToOmit> & Pick, MessageContextPropsToPick> & { canPin: boolean; @@ -61,7 +61,7 @@ type MessageWithContextProps< }; const MessageWithContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageWithContextProps, ) => { @@ -185,7 +185,7 @@ const MemoizedMessage = React.memo( * an individual message. The actual UI of the message is delegated via the Message prop on Channel. */ export const Message = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageProps, ) => { diff --git a/src/components/Message/MessageDeleted.tsx b/src/components/Message/MessageDeleted.tsx index 9b5a73d60..9a665f181 100644 --- a/src/components/Message/MessageDeleted.tsx +++ b/src/components/Message/MessageDeleted.tsx @@ -9,13 +9,13 @@ import type { StreamMessage } from '../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type MessageDeletedProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { message: StreamMessage; }; export const MessageDeleted = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageDeletedProps, ) => { diff --git a/src/components/Message/MessageEditedTimestamp.tsx b/src/components/Message/MessageEditedTimestamp.tsx index 87db8539f..0cc2e2b5b 100644 --- a/src/components/Message/MessageEditedTimestamp.tsx +++ b/src/components/Message/MessageEditedTimestamp.tsx @@ -9,22 +9,21 @@ import type { DefaultStreamChatGenerics } from '../../types'; import type { MessageTimestampProps } from './MessageTimestamp'; export type MessageEditedTimestampProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = MessageTimestampProps & { open: boolean; }; export function MessageEditedTimestamp< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ message: propMessage, open, ...timestampProps }: MessageEditedTimestampProps) { const { t } = useTranslationContext('MessageEditedTimestamp'); - const { message: contextMessage } = useMessageContext( - 'MessageEditedTimestamp', - ); + const { message: contextMessage } = + useMessageContext('MessageEditedTimestamp'); const { Timestamp = DefaultTimestamp } = useComponentContext('MessageEditedTimestamp'); const message = propMessage || contextMessage; diff --git a/src/components/Message/MessageErrorText.tsx b/src/components/Message/MessageErrorText.tsx index fd4f7a137..f1de754e8 100644 --- a/src/components/Message/MessageErrorText.tsx +++ b/src/components/Message/MessageErrorText.tsx @@ -5,14 +5,14 @@ import { DefaultStreamChatGenerics } from '../../types/types'; import { isMessageBounced } from './utils'; export interface MessageErrorTextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > { message: StreamMessage; theme: string; } export function MessageErrorText< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ message, theme }: MessageErrorTextProps) { const { t } = useTranslationContext('MessageText'); diff --git a/src/components/Message/MessageOptions.tsx b/src/components/Message/MessageOptions.tsx index 5f4065427..cb4d5c6d7 100644 --- a/src/components/Message/MessageOptions.tsx +++ b/src/components/Message/MessageOptions.tsx @@ -17,7 +17,7 @@ import type { DefaultStreamChatGenerics, IconProps } from '../../types/types'; import type { MessageContextValue } from '../../context/MessageContext'; export type MessageOptionsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial, 'handleOpenThread'>> & { /* Custom component rendering the icon used in message actions button. This button invokes the message actions menu. */ ActionsIcon?: React.ComponentType; @@ -32,7 +32,7 @@ export type MessageOptionsProps< }; const UnMemoizedMessageOptions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageOptionsProps, ) => { diff --git a/src/components/Message/MessageSimple.tsx b/src/components/Message/MessageSimple.tsx index e82200fed..38bd1f470 100644 --- a/src/components/Message/MessageSimple.tsx +++ b/src/components/Message/MessageSimple.tsx @@ -37,11 +37,11 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import { StreamedMessageText as DefaultStreamedMessageText } from './StreamedMessageText'; type MessageSimpleWithContextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = MessageContextValue; const MessageSimpleWithContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageSimpleWithContextProps, ) => { @@ -89,10 +89,10 @@ const MessageSimpleWithContext = < const hasAttachment = messageHasAttachments(message); const hasReactions = messageHasReactions(message); - const isAIGenerated = useMemo(() => isMessageAIGenerated?.(message), [ - isMessageAIGenerated, - message, - ]); + const isAIGenerated = useMemo( + () => isMessageAIGenerated?.(message), + [isMessageAIGenerated, message], + ); if (message.customType === CUSTOM_MESSAGE_TYPE.date) { return null; @@ -243,7 +243,7 @@ const MemoizedMessageSimple = React.memo( * The default UI component that renders a message and receives functionality and logic from the MessageContext. */ export const MessageSimple = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageUIComponentProps, ) => { diff --git a/src/components/Message/MessageStatus.tsx b/src/components/Message/MessageStatus.tsx index 1c96b7b73..aab360730 100644 --- a/src/components/Message/MessageStatus.tsx +++ b/src/components/Message/MessageStatus.tsx @@ -32,7 +32,7 @@ export type MessageStatusProps = { }; const UnMemoizedMessageStatus = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageStatusProps, ) => { @@ -49,13 +49,8 @@ const UnMemoizedMessageStatus = < const { client } = useChatContext('MessageStatus'); const { Avatar: contextAvatar } = useComponentContext('MessageStatus'); - const { - isMyMessage, - lastReceivedId, - message, - readBy, - threadList, - } = useMessageContext('MessageStatus'); + const { isMyMessage, lastReceivedId, message, readBy, threadList } = + useMessageContext('MessageStatus'); const { t } = useTranslationContext('MessageStatus'); const [referenceElement, setReferenceElement] = useState(null); diff --git a/src/components/Message/MessageText.tsx b/src/components/Message/MessageText.tsx index cb7919d76..2949193b9 100644 --- a/src/components/Message/MessageText.tsx +++ b/src/components/Message/MessageText.tsx @@ -13,7 +13,7 @@ import type { MessageContextValue, StreamMessage } from '../../context'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type MessageTextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /* Replaces the CSS class name placed on the component's inner `div` container */ customInnerClass?: string; @@ -26,7 +26,7 @@ export type MessageTextProps< } & Pick, 'renderText'>; const UnMemoizedMessageTextComponent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageTextProps, ) => { @@ -38,9 +38,8 @@ const UnMemoizedMessageTextComponent = < theme = 'simple', } = props; - const { QuotedMessage = DefaultQuotedMessage } = useComponentContext( - 'MessageText', - ); + const { QuotedMessage = DefaultQuotedMessage } = + useComponentContext('MessageText'); const { message: contextMessage, @@ -59,11 +58,10 @@ const UnMemoizedMessageTextComponent = < const messageTextToRender = message.i18n?.[`${userLanguage}_text` as `${TranslationLanguages}_text`] || message.text; - // eslint-disable-next-line react-hooks/exhaustive-deps - const messageText = useMemo(() => renderText(messageTextToRender, message.mentioned_users), [ - message.mentioned_users, - messageTextToRender, - ]); + const messageText = useMemo( + () => renderText(messageTextToRender, message.mentioned_users), + [message.mentioned_users, messageTextToRender, renderText], + ); const wrapperClass = customWrapperClass || 'str-chat__message-text'; const innerClass = diff --git a/src/components/Message/MessageTimestamp.tsx b/src/components/Message/MessageTimestamp.tsx index bf8959feb..f494ffb78 100644 --- a/src/components/Message/MessageTimestamp.tsx +++ b/src/components/Message/MessageTimestamp.tsx @@ -8,7 +8,7 @@ import type { TimestampFormatterOptions } from '../../i18n/types'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type MessageTimestampProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = TimestampFormatterOptions & { /* Adds a CSS class name to the component's outer `time` container. */ customClass?: string; @@ -17,7 +17,7 @@ export type MessageTimestampProps< }; const UnMemoizedMessageTimestamp = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageTimestampProps, ) => { diff --git a/src/components/Message/QuotedMessage.tsx b/src/components/Message/QuotedMessage.tsx index 22c680355..7f81be721 100644 --- a/src/components/Message/QuotedMessage.tsx +++ b/src/components/Message/QuotedMessage.tsx @@ -16,12 +16,10 @@ import type { TranslationLanguages } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types/types'; export const QuotedMessage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { - const { - Attachment = DefaultAttachment, - Avatar: ContextAvatar, - } = useComponentContext('QuotedMessage'); + const { Attachment = DefaultAttachment, Avatar: ContextAvatar } = + useComponentContext('QuotedMessage'); const { client } = useChatContext(); const { isMyMessage, message } = useMessageContext('QuotedMessage'); const { t, userLanguage } = useTranslationContext('QuotedMessage'); diff --git a/src/components/Message/StreamedMessageText.tsx b/src/components/Message/StreamedMessageText.tsx index 3005f3cd4..779dd030c 100644 --- a/src/components/Message/StreamedMessageText.tsx +++ b/src/components/Message/StreamedMessageText.tsx @@ -6,14 +6,14 @@ import { useMessageContext } from '../../context'; import { useMessageTextStreaming } from './hooks'; export type StreamedMessageTextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, 'message' | 'renderText'> & { renderingLetterCount?: number; streamingLetterIntervalMs?: number; }; export const StreamedMessageText = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: StreamedMessageTextProps, ) => { @@ -23,9 +23,8 @@ export const StreamedMessageText = < renderText, streamingLetterIntervalMs, } = props; - const { message: messageFromContext } = useMessageContext( - 'StreamedMessageText', - ); + const { message: messageFromContext } = + useMessageContext('StreamedMessageText'); const message = messageFromProps || messageFromContext; const { text = '' } = message; const { streamedMessageText } = useMessageTextStreaming({ diff --git a/src/components/Message/__tests__/Message.test.js b/src/components/Message/__tests__/Message.test.js index 67c2f90ad..e433fc486 100644 --- a/src/components/Message/__tests__/Message.test.js +++ b/src/components/Message/__tests__/Message.test.js @@ -71,7 +71,6 @@ async function renderComponent({ > , ...components, }} diff --git a/src/components/Message/__tests__/MessageOptions.test.js b/src/components/Message/__tests__/MessageOptions.test.js index b744bc2ad..3d2b30d34 100644 --- a/src/components/Message/__tests__/MessageOptions.test.js +++ b/src/components/Message/__tests__/MessageOptions.test.js @@ -1,4 +1,3 @@ -/* eslint-disable jest-dom/prefer-to-have-class */ import React from 'react'; import { act, fireEvent, render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; @@ -68,7 +67,7 @@ async function renderMessageOptions({ , reactionOptions: defaultReactionOptions, }} @@ -158,7 +157,7 @@ describe('', () => { }); expect(handleOpenThread).not.toHaveBeenCalled(); fireEvent.click(getByTestId(threadActionTestId)); - // eslint-disable-next-line jest/prefer-called-with + expect(handleOpenThread).toHaveBeenCalled(); }); diff --git a/src/components/Message/__tests__/MessageSimple.test.js b/src/components/Message/__tests__/MessageSimple.test.js index ab27b69df..9d962b86e 100644 --- a/src/components/Message/__tests__/MessageSimple.test.js +++ b/src/components/Message/__tests__/MessageSimple.test.js @@ -55,11 +55,11 @@ const retrySendMessageMock = jest.fn(); const removeMessageMock = jest.fn(); async function renderMessageSimple({ - message, - props = {}, - channelConfigOverrides = { replies: true }, channelCapabilities = { 'send-reaction': true }, + channelConfigOverrides = { replies: true }, components = {}, + message, + props = {}, renderer = render, }) { const channel = generateChannel({ @@ -85,7 +85,7 @@ async function renderMessageSimple({ , reactionOptions: defaultReactionOptions, ...components, @@ -500,7 +500,7 @@ describe('', () => { handleOpenThread: jest.fn(), }, }); - // eslint-disable-next-line jest/prefer-called-with + expect(MessageOptionsMock).toHaveBeenCalled(); const results = await axe(container); expect(results).toHaveNoViolations(); @@ -556,7 +556,7 @@ describe('', () => { unsafeHTML, }, }); - // eslint-disable-next-line jest/prefer-called-with + expect(MessageTextMock).toHaveBeenCalled(); const results = await axe(container); expect(results).toHaveNoViolations(); diff --git a/src/components/Message/__tests__/MessageText.test.js b/src/components/Message/__tests__/MessageText.test.js index 4f561c2a9..fc0117a11 100644 --- a/src/components/Message/__tests__/MessageText.test.js +++ b/src/components/Message/__tests__/MessageText.test.js @@ -54,10 +54,10 @@ function generateAliceMessage(messageOptions) { } async function renderMessageText({ - customProps = {}, + channelCapabilitiesOverrides = {}, channelConfigOverrides = {}, + customProps = {}, renderer = render, - channelCapabilitiesOverrides = {}, } = {}) { const client = await getTestClientWithUser(alice); const channel = generateChannel({ @@ -84,7 +84,7 @@ async function renderMessageText({ , reactionOptions: defaultReactionOptions, }} @@ -281,7 +281,7 @@ describe('', () => { }, }, }); - // eslint-disable-next-line jest/prefer-called-with + expect(MessageOptionsMock).toHaveBeenCalled(); const results = await axe(container); expect(results).toHaveNoViolations(); diff --git a/src/components/Message/hooks/useActionHandler.ts b/src/components/Message/hooks/useActionHandler.ts index 2ac129890..ccf29ac22 100644 --- a/src/components/Message/hooks/useActionHandler.ts +++ b/src/components/Message/hooks/useActionHandler.ts @@ -17,11 +17,10 @@ export const handleActionWarning = `Action handler was called, but it is missing Make sure the ChannelAction and ChannelState contexts are properly set and the hook is initialized with a valid message.`; export function useActionHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(message?: StreamMessage): ActionHandlerReturnType { - const { removeMessage, updateMessage } = useChannelActionContext( - 'useActionHandler', - ); + const { removeMessage, updateMessage } = + useChannelActionContext('useActionHandler'); const { channel } = useChannelStateContext('useActionHandler'); return async (dataOrName, value, event) => { diff --git a/src/components/Message/hooks/useDeleteHandler.ts b/src/components/Message/hooks/useDeleteHandler.ts index 69a21158d..bcda02b23 100644 --- a/src/components/Message/hooks/useDeleteHandler.ts +++ b/src/components/Message/hooks/useDeleteHandler.ts @@ -11,23 +11,22 @@ import type { StreamMessage } from '../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type DeleteMessageNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (message: StreamMessage) => string; notify?: (notificationText: string, type: 'success' | 'error') => void; }; export const useDeleteHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, notifications: DeleteMessageNotifications = {}, ): ReactEventHandler => { const { getErrorNotification, notify } = notifications; - const { deleteMessage, updateMessage } = useChannelActionContext( - 'useDeleteHandler', - ); + const { deleteMessage, updateMessage } = + useChannelActionContext('useDeleteHandler'); const { client } = useChatContext('useDeleteHandler'); const { t } = useTranslationContext('useDeleteHandler'); diff --git a/src/components/Message/hooks/useFlagHandler.ts b/src/components/Message/hooks/useFlagHandler.ts index f4ba463c7..694b80523 100644 --- a/src/components/Message/hooks/useFlagHandler.ts +++ b/src/components/Message/hooks/useFlagHandler.ts @@ -13,7 +13,7 @@ export const missingUseFlagHandlerParameterWarning = 'useFlagHandler was called but it is missing one or more necessary parameters.'; export type FlagMessageNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (message: StreamMessage) => string; getSuccessNotification?: (message: StreamMessage) => string; @@ -21,7 +21,7 @@ export type FlagMessageNotifications< }; export const useFlagHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, notifications: FlagMessageNotifications = {}, diff --git a/src/components/Message/hooks/useMarkUnreadHandler.ts b/src/components/Message/hooks/useMarkUnreadHandler.ts index 943187efa..a601f5715 100644 --- a/src/components/Message/hooks/useMarkUnreadHandler.ts +++ b/src/components/Message/hooks/useMarkUnreadHandler.ts @@ -6,7 +6,7 @@ import type { ReactEventHandler } from '../types'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type MarkUnreadHandlerNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (message: StreamMessage) => string; getSuccessNotification?: (message: StreamMessage) => string; @@ -14,7 +14,7 @@ export type MarkUnreadHandlerNotifications< }; export const useMarkUnreadHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, notifications: MarkUnreadHandlerNotifications = {}, diff --git a/src/components/Message/hooks/useMentionsHandler.ts b/src/components/Message/hooks/useMentionsHandler.ts index 37ad0879e..a0cc66481 100644 --- a/src/components/Message/hooks/useMentionsHandler.ts +++ b/src/components/Message/hooks/useMentionsHandler.ts @@ -10,15 +10,15 @@ import type { StreamMessage } from '../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type CustomMentionHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (event: React.BaseSyntheticEvent, mentioned_users: UserResponse[]) => void; export type MentionedUserEventHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (event: React.BaseSyntheticEvent, mentionedUsers: UserResponse[]) => void; function createEventHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( fn?: CustomMentionHandler, message?: StreamMessage, @@ -32,7 +32,7 @@ function createEventHandler< } export const useMentionsHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, customMentionHandler?: { @@ -40,10 +40,8 @@ export const useMentionsHandler = < onMentionsHover?: CustomMentionHandler; }, ) => { - const { - onMentionsClick: contextOnMentionsClick, - onMentionsHover: contextOnMentionsHover, - } = useChannelActionContext('useMentionsHandler'); + const { onMentionsClick: contextOnMentionsClick, onMentionsHover: contextOnMentionsHover } = + useChannelActionContext('useMentionsHandler'); const onMentionsClick = customMentionHandler?.onMentionsClick || contextOnMentionsClick || (() => null); diff --git a/src/components/Message/hooks/useMessageTextStreaming.ts b/src/components/Message/hooks/useMessageTextStreaming.ts index d791988c9..0d0f50148 100644 --- a/src/components/Message/hooks/useMessageTextStreaming.ts +++ b/src/components/Message/hooks/useMessageTextStreaming.ts @@ -4,7 +4,7 @@ import type { DefaultStreamChatGenerics } from '../../../types/types'; import type { StreamedMessageTextProps } from '../StreamedMessageText'; export type UseMessageTextStreamingProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick< StreamedMessageTextProps, 'streamingLetterIntervalMs' | 'renderingLetterCount' @@ -22,10 +22,10 @@ const DEFAULT_RENDERING_LETTER_COUNT = 2; * @returns {{ streamedMessageText: string }} - A substring of the text property, up until we've finished rendering the typewriter animation. */ export const useMessageTextStreaming = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ - streamingLetterIntervalMs = DEFAULT_LETTER_INTERVAL, renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT, + streamingLetterIntervalMs = DEFAULT_LETTER_INTERVAL, text, }: UseMessageTextStreamingProps): { streamedMessageText: string } => { const [streamedMessageText, setStreamedMessageText] = useState(text); diff --git a/src/components/Message/hooks/useMuteHandler.ts b/src/components/Message/hooks/useMuteHandler.ts index 1e4949e1a..0fc4a8bc7 100644 --- a/src/components/Message/hooks/useMuteHandler.ts +++ b/src/components/Message/hooks/useMuteHandler.ts @@ -14,7 +14,7 @@ export const missingUseMuteHandlerParamsWarning = 'useMuteHandler was called but it is missing one or more necessary parameter.'; export type MuteUserNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (user: UserResponse) => string; getSuccessNotification?: (user: UserResponse) => string; @@ -22,7 +22,7 @@ export type MuteUserNotifications< }; export const useMuteHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, notifications: MuteUserNotifications = {}, diff --git a/src/components/Message/hooks/useOpenThreadHandler.ts b/src/components/Message/hooks/useOpenThreadHandler.ts index b697300b1..2bd85cd38 100644 --- a/src/components/Message/hooks/useOpenThreadHandler.ts +++ b/src/components/Message/hooks/useOpenThreadHandler.ts @@ -7,7 +7,7 @@ import type { StreamMessage } from '../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useOpenThreadHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, customOpenThread?: ( @@ -15,9 +15,8 @@ export const useOpenThreadHandler = < event: React.BaseSyntheticEvent, ) => void, ): ReactEventHandler => { - const { openThread: channelOpenThread } = useChannelActionContext( - 'useOpenThreadHandler', - ); + const { openThread: channelOpenThread } = + useChannelActionContext('useOpenThreadHandler'); const openThread = customOpenThread || channelOpenThread; diff --git a/src/components/Message/hooks/usePinHandler.ts b/src/components/Message/hooks/usePinHandler.ts index b0db607b7..513935e8e 100644 --- a/src/components/Message/hooks/usePinHandler.ts +++ b/src/components/Message/hooks/usePinHandler.ts @@ -34,14 +34,14 @@ export type PinPermissions }; export type PinMessageNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (message: StreamMessage) => string; notify?: (notificationText: string, type: 'success' | 'error') => void; }; export const usePinHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: StreamMessage, // @deprecated in favor of `channelCapabilities` - TODO: remove in next major release diff --git a/src/components/Message/hooks/useReactionHandler.ts b/src/components/Message/hooks/useReactionHandler.ts index 271421342..2172ba917 100644 --- a/src/components/Message/hooks/useReactionHandler.ts +++ b/src/components/Message/hooks/useReactionHandler.ts @@ -15,15 +15,14 @@ export const reactionHandlerWarning = `Reaction handler was called, but it is mi Make sure the ChannelAction and ChannelState contexts are properly set and the hook is initialized with a valid message.`; export const useReactionHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, ) => { const thread = useThreadContext(); const { updateMessage } = useChannelActionContext('useReactionHandler'); - const { channel, channelCapabilities } = useChannelStateContext( - 'useReactionHandler', - ); + const { channel, channelCapabilities } = + useChannelStateContext('useReactionHandler'); const { client } = useChatContext('useReactionHandler'); const createMessagePreview = useCallback( @@ -94,7 +93,7 @@ export const useReactionHandler = < try { updateMessage(tempMessage); - // @ts-expect-error + // @ts-expect-error message type mismatch thread?.upsertReplyLocally({ message: tempMessage }); const messageResponse = add @@ -106,7 +105,7 @@ export const useReactionHandler = < } catch (error) { // revert to the original message if the API call fails updateMessage(message); - // @ts-expect-error + // @ts-expect-error message type mismatch thread?.upsertReplyLocally({ message }); } }, 1000); @@ -120,7 +119,7 @@ export const useReactionHandler = < return console.warn(reactionHandlerWarning); } - let userExistingReaction = (null as unknown) as ReactionResponse; + let userExistingReaction = null as unknown as ReactionResponse; if (message.own_reactions) { message.own_reactions.forEach((reaction) => { diff --git a/src/components/Message/hooks/useReactionsFetcher.ts b/src/components/Message/hooks/useReactionsFetcher.ts index cbd50036c..6dad0f1ed 100644 --- a/src/components/Message/hooks/useReactionsFetcher.ts +++ b/src/components/Message/hooks/useReactionsFetcher.ts @@ -6,14 +6,14 @@ import { ReactionType } from '../../Reactions/types'; export const MAX_MESSAGE_REACTIONS_TO_FETCH = 1000; type FetchMessageReactionsNotifications< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { getErrorNotification?: (message: StreamMessage) => string; notify?: (notificationText: string, type: 'success' | 'error') => void; }; export function useReactionsFetcher< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: StreamMessage, notifications: FetchMessageReactionsNotifications = {}, @@ -37,7 +37,7 @@ export function useReactionsFetcher< } async function fetchMessageReactions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( client: StreamChat, messageId: string, diff --git a/src/components/Message/hooks/useRetryHandler.ts b/src/components/Message/hooks/useRetryHandler.ts index 1e370d5b7..caf6f405d 100644 --- a/src/components/Message/hooks/useRetryHandler.ts +++ b/src/components/Message/hooks/useRetryHandler.ts @@ -3,13 +3,12 @@ import { RetrySendMessage, useChannelActionContext } from '../../../context/Chan import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useRetryHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( customRetrySendMessage?: RetrySendMessage, ): RetrySendMessage => { - const { retrySendMessage: contextRetrySendMessage } = useChannelActionContext( - 'useRetryHandler', - ); + const { retrySendMessage: contextRetrySendMessage } = + useChannelActionContext('useRetryHandler'); const retrySendMessage = customRetrySendMessage || contextRetrySendMessage; diff --git a/src/components/Message/hooks/useUserHandler.ts b/src/components/Message/hooks/useUserHandler.ts index 5ed24b355..debb5b237 100644 --- a/src/components/Message/hooks/useUserHandler.ts +++ b/src/components/Message/hooks/useUserHandler.ts @@ -7,11 +7,11 @@ import type { StreamMessage } from '../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export type UserEventHandler< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (event: React.BaseSyntheticEvent, user: User) => void; export const useUserHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, eventHandlers?: { diff --git a/src/components/Message/hooks/useUserRole.ts b/src/components/Message/hooks/useUserRole.ts index b4077b6d5..b4d058939 100644 --- a/src/components/Message/hooks/useUserRole.ts +++ b/src/components/Message/hooks/useUserRole.ts @@ -4,15 +4,14 @@ import { useChatContext } from '../../../context/ChatContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; export const useUserRole = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: StreamMessage, onlySenderCanEdit?: boolean, disableQuotedMessages?: boolean, ) => { - const { channel, channelCapabilities = {} } = useChannelStateContext( - 'useUserRole', - ); + const { channel, channelCapabilities = {} } = + useChannelStateContext('useUserRole'); const { client } = useChatContext('useUserRole'); /** diff --git a/src/components/Message/icons.tsx b/src/components/Message/icons.tsx index 311b56a69..18c89a293 100644 --- a/src/components/Message/icons.tsx +++ b/src/components/Message/icons.tsx @@ -53,7 +53,7 @@ export const PinIcon = () => ( ); export const PinIndicator = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ message, t, diff --git a/src/components/Message/renderText/componentRenderers/Mention.tsx b/src/components/Message/renderText/componentRenderers/Mention.tsx index b5dd659fc..06fb7f6c9 100644 --- a/src/components/Message/renderText/componentRenderers/Mention.tsx +++ b/src/components/Message/renderText/componentRenderers/Mention.tsx @@ -4,7 +4,7 @@ import type { UserResponse } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export type MentionProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = PropsWithChildren<{ node: { mentionedUser: UserResponse; @@ -12,7 +12,7 @@ export type MentionProps< }>; export const Mention = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, node: { mentionedUser }, diff --git a/src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts b/src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts index 55ffd7e82..ff942708c 100644 --- a/src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts +++ b/src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts @@ -8,65 +8,65 @@ import type { Element } from 'react-markdown/lib/ast-to-react'; import type { UserResponse } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../../types'; -export const mentionsMarkdownPlugin = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ->( - mentioned_users: UserResponse[], -) => () => { - const mentioned_usernames = mentioned_users - .map((user) => user.name || user.id) - .filter(Boolean) - .map(escapeRegExp); +export const mentionsMarkdownPlugin = + ( + mentioned_users: UserResponse[], + ) => + () => { + const mentioned_usernames = mentioned_users + .map((user) => user.name || user.id) + .filter(Boolean) + .map(escapeRegExp); - const mentionedUsersRegex = new RegExp( - mentioned_usernames.map((username) => `@${username}`).join('|'), - 'g', - ); - - const replace: ReplaceFunction = (match) => { - const usernameOrId = match.replace('@', ''); - const user = mentioned_users.find( - ({ id, name }) => name === usernameOrId || id === usernameOrId, + const mentionedUsersRegex = new RegExp( + mentioned_usernames.map((username) => `@${username}`).join('|'), + 'g', ); - return u('element', { mentionedUser: user, properties: {}, tagName: 'mention' }, [ - u('text', match), - ]); - }; - const transform = (tree: Nodes) => { - if (!mentioned_usernames.length) return; + const replace: ReplaceFunction = (match) => { + const usernameOrId = match.replace('@', ''); + const user = mentioned_users.find( + ({ id, name }) => name === usernameOrId || id === usernameOrId, + ); + return u('element', { mentionedUser: user, properties: {}, tagName: 'mention' }, [ + u('text', match), + ]); + }; - // handles special cases of mentions where user.name is an e-mail - // Remark GFM translates all e-mail-like text nodes to links creating - // two separate child nodes "@" and "your.name@as.email" instead of - // keeping it as one text node with value "@your.name@as.email" - // this piece finds these two separated nodes and merges them together - // before "replace" function takes over - visit(tree, (node, index, parent) => { - if (typeof index === 'undefined') return; - if (!parent) return; + const transform = (tree: Nodes) => { + if (!mentioned_usernames.length) return; - const nextChild = parent.children.at(index + 1) as Element; - const nextChildHref = nextChild?.properties?.href as string | undefined; + // handles special cases of mentions where user.name is an e-mail + // Remark GFM translates all e-mail-like text nodes to links creating + // two separate child nodes "@" and "your.name@as.email" instead of + // keeping it as one text node with value "@your.name@as.email" + // this piece finds these two separated nodes and merges them together + // before "replace" function takes over + visit(tree, (node, index, parent) => { + if (typeof index === 'undefined') return; + if (!parent) return; - if ( - node.type === 'text' && - // text value has to have @ sign at the end of the string - // and no other characters except whitespace can precede it - // valid cases: "text @", "@", " @" - // invalid cases: "text@", "@text", - /.?\s?@$|^@$/.test(node.value) && - nextChildHref?.startsWith('mailto:') - ) { - const newTextValue = node.value.replace(/@$/, ''); - const username = nextChildHref.replace('mailto:', ''); - parent.children[index] = u('text', newTextValue); - parent.children[index + 1] = u('text', `@${username}`); - } - }); + const nextChild = parent.children.at(index + 1) as Element; + const nextChildHref = nextChild?.properties?.href as string | undefined; - findAndReplace(tree, [mentionedUsersRegex, replace]); - }; + if ( + node.type === 'text' && + // text value has to have @ sign at the end of the string + // and no other characters except whitespace can precede it + // valid cases: "text @", "@", " @" + // invalid cases: "text@", "@text", + /.?\s?@$|^@$/.test(node.value) && + nextChildHref?.startsWith('mailto:') + ) { + const newTextValue = node.value.replace(/@$/, ''); + const username = nextChildHref.replace('mailto:', ''); + parent.children[index] = u('text', newTextValue); + parent.children[index + 1] = u('text', `@${username}`); + } + }); - return transform; -}; + findAndReplace(tree, [mentionedUsersRegex, replace]); + }; + + return transform; + }; diff --git a/src/components/Message/renderText/renderText.tsx b/src/components/Message/renderText/renderText.tsx index 8e2e0ace5..396f62f2a 100644 --- a/src/components/Message/renderText/renderText.tsx +++ b/src/components/Message/renderText/renderText.tsx @@ -71,9 +71,8 @@ export const markDownRenderers: RenderTextOptions['customMarkDownRenderers'] = { }; export type RenderTextOptions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { - // eslint-disable-next-line @typescript-eslint/ban-types allowedTagNames?: Array; customMarkDownRenderers?: Options['components'] & Partial<{ @@ -85,7 +84,7 @@ export type RenderTextOptions< }; export const renderText = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( text?: string, mentionedUsers?: UserResponse[], diff --git a/src/components/Message/types.ts b/src/components/Message/types.ts index 961c92c19..9cc82632e 100644 --- a/src/components/Message/types.ts +++ b/src/components/Message/types.ts @@ -20,7 +20,7 @@ export type ReactEventHandler = (event: React.BaseSyntheticEvent) => Promise = { /** The message object */ message: StreamMessage; @@ -113,11 +113,11 @@ export type MessageProps< }; export type MessageUIComponentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial>; export type PinIndicatorProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { message?: StreamMessage; t?: TFunction; diff --git a/src/components/Message/utils.tsx b/src/components/Message/utils.tsx index 2a01bb31f..160596e91 100644 --- a/src/components/Message/utils.tsx +++ b/src/components/Message/utils.tsx @@ -21,13 +21,12 @@ export const validateAndGetMessage = ( func: (...args: T) => unknown, args: T, ) => { - if (!func || typeof func !== 'function') return null; + if (typeof func !== 'function') return null; // below is due to tests passing a single argument - // rather than an array. - if (!(args instanceof Array)) { - // @ts-expect-error - args = [args]; + // rather than an array + if (!Array.isArray(args)) { + args = [args] as unknown as T; } const returnValue = func(...args); @@ -41,7 +40,7 @@ export const validateAndGetMessage = ( * Tell if the owner of the current message is muted */ export const isUserMuted = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: StreamMessage, mutes?: Mute[], @@ -219,7 +218,7 @@ export const showMessageActionsBox = ( ) => shouldRenderMessageActions({ inThread, messageActions: actions }); export const shouldRenderMessageActions = < - SCG extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + SCG extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ customMessageActions, CustomMessageActionsList, @@ -266,7 +265,7 @@ export const shouldRenderMessageActions = < }; function areMessagesEqual< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( prevMessage: StreamMessage, nextMessage: StreamMessage, @@ -292,7 +291,7 @@ function areMessagesEqual< } export const areMessagePropsEqual = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( prevProps: MessageProps & { mutes?: Mute[]; @@ -336,7 +335,7 @@ export const areMessagePropsEqual = < }; export const areMessageUIPropsEqual = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( prevProps: MessageContextValue & { showDetailedReactions?: boolean; @@ -370,19 +369,19 @@ export const areMessageUIPropsEqual = < }; export const messageHasReactions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, ) => Object.values(message?.reaction_groups ?? {}).some(({ count }) => count > 0); export const messageHasAttachments = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: StreamMessage, ) => !!message?.attachments && !!message.attachments.length; export const getImages = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: MessageResponse, ) => { @@ -393,7 +392,7 @@ export const getImages = < }; export const getNonImageAttachments = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: MessageResponse, ) => { @@ -417,7 +416,7 @@ export interface TooltipUsernameMapper { export const mapToUserNameOrId: TooltipUsernameMapper = (user) => user.name || user.id; export const getReadByTooltipText = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( users: UserResponse[], t: TFunction, @@ -483,7 +482,7 @@ export const isOnlyEmojis = (text?: string) => { }; export const isMessageBounced = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: Pick, 'type' | 'moderation' | 'moderation_details'>, ) => @@ -492,7 +491,7 @@ export const isMessageBounced = < message.moderation?.action === 'bounce'); export const isMessageEdited = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: Pick, 'message_text_updated_at'>, ) => !!message.message_text_updated_at; diff --git a/src/components/MessageActions/CustomMessageActionsList.tsx b/src/components/MessageActions/CustomMessageActionsList.tsx index 258e346b7..15d4fd9c4 100644 --- a/src/components/MessageActions/CustomMessageActionsList.tsx +++ b/src/components/MessageActions/CustomMessageActionsList.tsx @@ -6,14 +6,14 @@ import type { StreamMessage } from '../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type CustomMessageActionsListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { message: StreamMessage; customMessageActions?: CustomMessageActions; }; export const CustomMessageActionsList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: CustomMessageActionsListProps, ) => { diff --git a/src/components/MessageActions/MessageActions.tsx b/src/components/MessageActions/MessageActions.tsx index b6ccbc6b5..df080286f 100644 --- a/src/components/MessageActions/MessageActions.tsx +++ b/src/components/MessageActions/MessageActions.tsx @@ -23,7 +23,7 @@ type MessageContextPropsToPick = | 'message'; export type MessageActionsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial, MessageContextPropsToPick>> & { /* Custom component rendering the icon used in message actions button. This button invokes the message actions menu. */ ActionsIcon?: React.ComponentType; @@ -36,7 +36,7 @@ export type MessageActionsProps< }; export const MessageActions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageActionsProps, ) => { diff --git a/src/components/MessageActions/MessageActionsBox.tsx b/src/components/MessageActions/MessageActionsBox.tsx index e7deb75ec..8d89f2e5c 100644 --- a/src/components/MessageActions/MessageActionsBox.tsx +++ b/src/components/MessageActions/MessageActionsBox.tsx @@ -25,7 +25,7 @@ type PropsDrilledToMessageActionsBox = | 'handlePin'; export type MessageActionsBoxProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Pick, PropsDrilledToMessageActionsBox> & { isUserMuted: () => boolean; mine: boolean; @@ -33,7 +33,7 @@ export type MessageActionsBoxProps< } & ComponentProps<'div'>; const UnMemoizedMessageActionsBox = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageActionsBoxProps, ) => { @@ -47,18 +47,17 @@ const UnMemoizedMessageActionsBox = < handleMute, handlePin, isUserMuted, + // eslint-disable-next-line @typescript-eslint/no-unused-vars mine, open, ...restDivProps } = props; - const { - CustomMessageActionsList = DefaultCustomMessageActionsList, - } = useComponentContext('MessageActionsBox'); + const { CustomMessageActionsList = DefaultCustomMessageActionsList } = + useComponentContext('MessageActionsBox'); const { setQuotedMessage } = useChannelActionContext('MessageActionsBox'); - const { customMessageActions, message, threadList } = useMessageContext( - 'MessageActionsBox', - ); + const { customMessageActions, message, threadList } = + useMessageContext('MessageActionsBox'); const { t } = useTranslationContext('MessageActionsBox'); diff --git a/src/components/MessageActions/__tests__/MessageActionsBox.test.js b/src/components/MessageActions/__tests__/MessageActionsBox.test.js index 6a62a5383..21fdf8add 100644 --- a/src/components/MessageActions/__tests__/MessageActionsBox.test.js +++ b/src/components/MessageActions/__tests__/MessageActionsBox.test.js @@ -408,13 +408,13 @@ describe('MessageActionsBox', () => { }); await toggleOpenMessageActions(0); let boxes = screen.getAllByTestId('message-actions-box'); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(boxes).toHaveLength(1); expect(boxes[0]).toHaveTextContent(ACTION_TEXT); await toggleOpenMessageActions(1); boxes = screen.getAllByTestId('message-actions-box'); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(boxes).toHaveLength(1); expect(boxes[0]).toHaveTextContent(ACTION_TEXT); }); diff --git a/src/components/MessageBounce/MessageBouncePrompt.tsx b/src/components/MessageBounce/MessageBouncePrompt.tsx index 805dcb156..efed01756 100644 --- a/src/components/MessageBounce/MessageBouncePrompt.tsx +++ b/src/components/MessageBounce/MessageBouncePrompt.tsx @@ -8,11 +8,10 @@ import type { ModalProps } from '../Modal'; export type MessageBouncePromptProps = PropsWithChildren>; export function MessageBouncePrompt< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, onClose }: MessageBouncePromptProps) { - const { handleDelete, handleEdit, handleRetry } = useMessageBounceContext( - 'MessageBouncePrompt', - ); + const { handleDelete, handleEdit, handleRetry } = + useMessageBounceContext('MessageBouncePrompt'); const { t } = useTranslationContext('MessageBouncePrompt'); function createHandler( diff --git a/src/components/MessageInput/AttachmentPreviewList/AttachmentPreviewList.tsx b/src/components/MessageInput/AttachmentPreviewList/AttachmentPreviewList.tsx index 682244973..8851c4b71 100644 --- a/src/components/MessageInput/AttachmentPreviewList/AttachmentPreviewList.tsx +++ b/src/components/MessageInput/AttachmentPreviewList/AttachmentPreviewList.tsx @@ -29,7 +29,7 @@ import { useMessageInputContext } from '../../../context'; import type { DefaultStreamChatGenerics } from '../../../types'; export type AttachmentPreviewListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { AudioAttachmentPreview?: ComponentType; FileAttachmentPreview?: ComponentType; @@ -42,7 +42,7 @@ export type AttachmentPreviewListProps< }; export const AttachmentPreviewList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ AudioAttachmentPreview = DefaultFilePreview, FileAttachmentPreview = DefaultFilePreview, @@ -51,11 +51,8 @@ export const AttachmentPreviewList = < VideoAttachmentPreview = DefaultFilePreview, VoiceRecordingPreview = DefaultVoiceRecordingPreview, }: AttachmentPreviewListProps) => { - const { - attachments, - removeAttachments, - uploadAttachment, - } = useMessageInputContext('AttachmentPreviewList'); + const { attachments, removeAttachments, uploadAttachment } = + useMessageInputContext('AttachmentPreviewList'); return (
diff --git a/src/components/MessageInput/AttachmentPreviewList/FileAttachmentPreview.tsx b/src/components/MessageInput/AttachmentPreviewList/FileAttachmentPreview.tsx index 3f7853bbd..cb0f5d1ee 100644 --- a/src/components/MessageInput/AttachmentPreviewList/FileAttachmentPreview.tsx +++ b/src/components/MessageInput/AttachmentPreviewList/FileAttachmentPreview.tsx @@ -16,14 +16,14 @@ type FileLikeAttachment = { export type FileAttachmentPreviewProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = AttachmentPreviewProps< LocalAttachmentCast, StreamChatGenerics >; export const FileAttachmentPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, handleRetry, diff --git a/src/components/MessageInput/AttachmentPreviewList/ImageAttachmentPreview.tsx b/src/components/MessageInput/AttachmentPreviewList/ImageAttachmentPreview.tsx index 6c7186933..758b976d5 100644 --- a/src/components/MessageInput/AttachmentPreviewList/ImageAttachmentPreview.tsx +++ b/src/components/MessageInput/AttachmentPreviewList/ImageAttachmentPreview.tsx @@ -9,14 +9,14 @@ import type { DefaultStreamChatGenerics } from '../../../types'; export type ImageAttachmentPreviewProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = AttachmentPreviewProps< LocalImageAttachment, StreamChatGenerics >; export const ImageAttachmentPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, handleRetry, diff --git a/src/components/MessageInput/AttachmentPreviewList/UnsupportedAttachmentPreview.tsx b/src/components/MessageInput/AttachmentPreviewList/UnsupportedAttachmentPreview.tsx index 1f7f12a4d..dd2635fb8 100644 --- a/src/components/MessageInput/AttachmentPreviewList/UnsupportedAttachmentPreview.tsx +++ b/src/components/MessageInput/AttachmentPreviewList/UnsupportedAttachmentPreview.tsx @@ -8,14 +8,14 @@ import type { DefaultStreamChatGenerics } from '../../../types'; export type UnsupportedAttachmentPreviewProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = AttachmentPreviewProps< AnyLocalAttachment, StreamChatGenerics >; export const UnsupportedAttachmentPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, handleRetry, diff --git a/src/components/MessageInput/AttachmentPreviewList/VoiceRecordingPreview.tsx b/src/components/MessageInput/AttachmentPreviewList/VoiceRecordingPreview.tsx index 1a4773d4e..03e1a9b13 100644 --- a/src/components/MessageInput/AttachmentPreviewList/VoiceRecordingPreview.tsx +++ b/src/components/MessageInput/AttachmentPreviewList/VoiceRecordingPreview.tsx @@ -10,14 +10,14 @@ import type { DefaultStreamChatGenerics } from '../../../types'; export type VoiceRecordingPreviewProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = AttachmentPreviewProps< LocalVoiceRecordingAttachment, StreamChatGenerics >; export const VoiceRecordingPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachment, handleRetry, diff --git a/src/components/MessageInput/AttachmentPreviewList/types.ts b/src/components/MessageInput/AttachmentPreviewList/types.ts index 86ea32514..f5c398325 100644 --- a/src/components/MessageInput/AttachmentPreviewList/types.ts +++ b/src/components/MessageInput/AttachmentPreviewList/types.ts @@ -3,7 +3,7 @@ import type { DefaultStreamChatGenerics } from '../../../types'; export type AttachmentPreviewProps< A extends LocalAttachment, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachment: A; handleRetry: ( diff --git a/src/components/MessageInput/AttachmentSelector.tsx b/src/components/MessageInput/AttachmentSelector.tsx index 1fc7a935c..8d5e58931 100644 --- a/src/components/MessageInput/AttachmentSelector.tsx +++ b/src/components/MessageInput/AttachmentSelector.tsx @@ -21,10 +21,8 @@ import { import type { DefaultStreamChatGenerics } from '../../types'; export const SimpleAttachmentSelector = () => { - const { - AttachmentSelectorInitiationButtonContents, - FileUploadIcon = DefaultUploadIcon, - } = useComponentContext(); + const { AttachmentSelectorInitiationButtonContents, FileUploadIcon = DefaultUploadIcon } = + useComponentContext(); const inputRef = useRef>(null); const [labelElement, setLabelElement] = useState(null); const id = useMemo(() => nanoid(), []); @@ -80,7 +78,6 @@ export type AttachmentSelectorActionProps = { export type AttachmentSelectorAction = { ActionButton: React.ComponentType; - // eslint-disable-next-line @typescript-eslint/ban-types type: 'uploadFile' | 'createPoll' | (string & {}); ModalContent?: React.ComponentType; }; @@ -132,7 +129,7 @@ export type AttachmentSelectorProps = { }; const useAttachmentSelectorActionsFiltered = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( original: AttachmentSelectorAction[], ) => { @@ -159,7 +156,7 @@ const useAttachmentSelectorActionsFiltered = < }; export const AttachmentSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ attachmentSelectorActionSet = defaultAttachmentSelectorActionSet, getModalPortalDestination, diff --git a/src/components/MessageInput/DefaultTriggerProvider.tsx b/src/components/MessageInput/DefaultTriggerProvider.tsx index 71d6ea25c..25e6965d0 100644 --- a/src/components/MessageInput/DefaultTriggerProvider.tsx +++ b/src/components/MessageInput/DefaultTriggerProvider.tsx @@ -22,13 +22,13 @@ export type AutocompleteMinimalData = { } & ({ id: string } | { name: string }); export type CommandTriggerSetting< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = TriggerSetting>; export type EmojiTriggerSetting = TriggerSetting; export type UserTriggerSetting< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = TriggerSetting>; export type TriggerSetting = { @@ -38,9 +38,7 @@ export type TriggerSetting text: string, onReady: (data: (U & AutocompleteMinimalData)[], token: string) => void, ) => U[] | PromiseLike | void; - output: ( - entity: U, - ) => + output: (entity: U) => | { caretPosition: 'start' | 'end' | 'next' | number; text: string; @@ -53,7 +51,7 @@ export type TriggerSetting export type TriggerSettings< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = | { [key in keyof V]: TriggerSetting; @@ -66,7 +64,7 @@ export type TriggerSettings< export const DefaultTriggerProvider = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >({ children, }: PropsWithChildren>) => { diff --git a/src/components/MessageInput/DropzoneProvider.tsx b/src/components/MessageInput/DropzoneProvider.tsx index 236cdf44e..7ff2d9d8a 100644 --- a/src/components/MessageInput/DropzoneProvider.tsx +++ b/src/components/MessageInput/DropzoneProvider.tsx @@ -17,20 +17,15 @@ import type { CustomTrigger, DefaultStreamChatGenerics, UnknownType } from '../. const DropzoneInner = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >({ children, }: PropsWithChildren) => { - const { acceptedFiles, multipleUploads } = useChannelStateContext( - 'DropzoneProvider', - ); + const { acceptedFiles, multipleUploads } = + useChannelStateContext('DropzoneProvider'); - const { - cooldownRemaining, - isUploadEnabled, - maxFilesLeft, - uploadNewFiles, - } = useMessageInputContext('DropzoneProvider'); + const { cooldownRemaining, isUploadEnabled, maxFilesLeft, uploadNewFiles } = + useMessageInputContext('DropzoneProvider'); return ( ( props: PropsWithChildren>, ) => { diff --git a/src/components/MessageInput/EditMessageForm.tsx b/src/components/MessageInput/EditMessageForm.tsx index 34ad16fee..c9a093e8c 100644 --- a/src/components/MessageInput/EditMessageForm.tsx +++ b/src/components/MessageInput/EditMessageForm.tsx @@ -7,7 +7,7 @@ import type { CustomTrigger, DefaultStreamChatGenerics } from '../../types/types export const EditMessageForm = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >() => { const { t } = useTranslationContext('EditMessageForm'); diff --git a/src/components/MessageInput/MessageInput.tsx b/src/components/MessageInput/MessageInput.tsx index ce6a92f2d..9f456dcc0 100644 --- a/src/components/MessageInput/MessageInput.tsx +++ b/src/components/MessageInput/MessageInput.tsx @@ -40,7 +40,7 @@ export interface EmojiSearchIndex { export type MessageInputProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = { /** Additional props to be passed to the underlying `AutoCompleteTextarea` component, [available props](https://www.npmjs.com/package/react-textarea-autosize) */ additionalTextareaProps?: React.TextareaHTMLAttributes; @@ -130,7 +130,7 @@ export type MessageInputProps< const MessageInputProvider = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: PropsWithChildren>, ) => { @@ -154,7 +154,7 @@ const MessageInputProvider = < const UnMemoizedMessageInput = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: MessageInputProps, ) => { diff --git a/src/components/MessageInput/MessageInputFlat.tsx b/src/components/MessageInput/MessageInputFlat.tsx index 334298936..08fcb6aeb 100644 --- a/src/components/MessageInput/MessageInputFlat.tsx +++ b/src/components/MessageInput/MessageInputFlat.tsx @@ -36,7 +36,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import { AIStates, useAIState } from '../AIStateIndicator'; export const MessageInputFlat = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { t } = useTranslationContext('MessageInputFlat'); const { @@ -59,17 +59,17 @@ export const MessageInputFlat = < } = useMessageInputContext('MessageInputFlat'); const { - AudioRecorder = DefaultAudioRecorder, AttachmentPreviewList = DefaultAttachmentPreviewList, AttachmentSelector = message ? SimpleAttachmentSelector : DefaultAttachmentSelector, + AudioRecorder = DefaultAudioRecorder, CooldownTimer = DefaultCooldownTimer, + EmojiPicker, LinkPreviewList = DefaultLinkPreviewList, QuotedMessagePreview = DefaultQuotedMessagePreview, RecordingPermissionDeniedNotification = DefaultRecordingPermissionDeniedNotification, SendButton = DefaultSendButton, StartRecordingAudioButton = DefaultStartRecordingAudioButton, StopAIGenerationButton: StopAIGenerationButtonOverride, - EmojiPicker, } = useComponentContext('MessageInputFlat'); const { acceptedFiles = [], @@ -83,10 +83,8 @@ export const MessageInputFlat = < const stopGenerating = useCallback(() => channel?.stopAIResponse(), [channel]); - const [ - showRecordingPermissionDeniedNotification, - setShowRecordingPermissionDeniedNotification, - ] = useState(false); + const [showRecordingPermissionDeniedNotification, setShowRecordingPermissionDeniedNotification] = + useState(false); const closePermissionDeniedNotification = useCallback(() => { setShowRecordingPermissionDeniedNotification(false); }, []); diff --git a/src/components/MessageInput/QuotedMessagePreview.tsx b/src/components/MessageInput/QuotedMessagePreview.tsx index 6f45849fb..34c66c91c 100644 --- a/src/components/MessageInput/QuotedMessagePreview.tsx +++ b/src/components/MessageInput/QuotedMessagePreview.tsx @@ -15,7 +15,7 @@ import type { StreamMessage } from '../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export const QuotedMessagePreviewHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { setQuotedMessage } = useChannelActionContext('QuotedMessagePreview'); const { t } = useTranslationContext('QuotedMessagePreview'); @@ -37,21 +37,19 @@ export const QuotedMessagePreviewHeader = < }; export type QuotedMessagePreviewProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { quotedMessage: StreamMessage; }; export const QuotedMessagePreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ quotedMessage, }: QuotedMessagePreviewProps) => { const { client } = useChatContext(); - const { - Attachment = DefaultAttachment, - Avatar = DefaultAvatar, - } = useComponentContext('QuotedMessagePreview'); + const { Attachment = DefaultAttachment, Avatar = DefaultAvatar } = + useComponentContext('QuotedMessagePreview'); const { userLanguage } = useTranslationContext('QuotedMessagePreview'); const quotedMessageText = diff --git a/src/components/MessageInput/SendButton.tsx b/src/components/MessageInput/SendButton.tsx index 38aae95fb..535587565 100644 --- a/src/components/MessageInput/SendButton.tsx +++ b/src/components/MessageInput/SendButton.tsx @@ -4,7 +4,7 @@ import { SendIcon } from './icons'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type SendButtonProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { sendMessage: ( event: React.BaseSyntheticEvent, @@ -12,7 +12,7 @@ export type SendButtonProps< ) => void; } & React.ComponentProps<'button'>; export const SendButton = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ sendMessage, ...rest diff --git a/src/components/MessageInput/__tests__/AttachmentPreviewList.test.js b/src/components/MessageInput/__tests__/AttachmentPreviewList.test.js index 003d7ae35..53e03b714 100644 --- a/src/components/MessageInput/__tests__/AttachmentPreviewList.test.js +++ b/src/components/MessageInput/__tests__/AttachmentPreviewList.test.js @@ -1,5 +1,3 @@ -/* eslint-disable jest-dom/prefer-in-document */ - import React from 'react'; import { fireEvent, render, screen } from '@testing-library/react'; diff --git a/src/components/MessageInput/__tests__/LinkPreviewList.test.js b/src/components/MessageInput/__tests__/LinkPreviewList.test.js index dc22bca02..fabbce6a9 100644 --- a/src/components/MessageInput/__tests__/LinkPreviewList.test.js +++ b/src/components/MessageInput/__tests__/LinkPreviewList.test.js @@ -94,40 +94,44 @@ const ChatContextOverrider = ({ children, contextOverrides }) => { return {children}; }; -const makeRenderFn = (InputComponent) => async ({ - messageInputProps = {}, - channelProps = {}, - chatContextOverrides = {}, - client = chatClient, - messageContextOverrides = {}, - messageActionsBoxProps = {}, -} = {}) => { - let renderResult; - await act(() => { - renderResult = render( - - - - - - - - - - - , - ); - }); - const submit = async () => { - const submitButton = renderResult.findByText('Send') || renderResult.findByTitle('Send'); - fireEvent.click(await submitButton); - }; +const makeRenderFn = + (InputComponent) => + async ({ + channelProps = {}, + chatContextOverrides = {}, + client = chatClient, + messageActionsBoxProps = {}, + messageContextOverrides = {}, + messageInputProps = {}, + } = {}) => { + let renderResult; + await act(() => { + renderResult = render( + + + + + + + + + + + , + ); + }); + const submit = async () => { + const submitButton = renderResult.findByText('Send') || renderResult.findByTitle('Send'); + fireEvent.click(await submitButton); + }; - return { submit, ...renderResult }; -}; + return { submit, ...renderResult }; + }; const tearDown = () => { cleanup(); @@ -341,7 +345,7 @@ describe('Link preview', () => { }); }); const linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData.og_scrape_url); }); @@ -384,7 +388,7 @@ describe('Link preview', () => { }); }); let linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData1.og_scrape_url); @@ -396,7 +400,7 @@ describe('Link preview', () => { }); }); linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(2); expect(linkPreviews[0]).toHaveTextContent(scrapedData1.og_scrape_url); expect(linkPreviews[1]).toHaveTextContent(scrapedData2.og_scrape_url); @@ -409,7 +413,7 @@ describe('Link preview', () => { }); }); linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(3); expect(linkPreviews[0]).toHaveTextContent(scrapedData1.og_scrape_url); expect(linkPreviews[1]).toHaveTextContent(scrapedData2.og_scrape_url); @@ -451,7 +455,7 @@ describe('Link preview', () => { await waitFor(() => { const linkPreviews = screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(3); expect(linkPreviews[0]).toHaveTextContent(scrapedData1.og_scrape_url); expect(linkPreviews[1]).toHaveTextContent(scrapedData2.og_scrape_url); @@ -473,7 +477,7 @@ describe('Link preview', () => { }); }); let linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData.og_scrape_url); @@ -485,7 +489,7 @@ describe('Link preview', () => { }); }); linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData.og_scrape_url); }); @@ -562,7 +566,7 @@ describe('Link preview', () => { }); }); let linkPreviews = screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData.og_scrape_url); @@ -574,7 +578,7 @@ describe('Link preview', () => { }); }); linkPreviews = screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(0); }); @@ -593,7 +597,7 @@ describe('Link preview', () => { }); }); let linkPreviews = screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData.og_scrape_url); @@ -601,7 +605,7 @@ describe('Link preview', () => { fireEvent.click(await screen.findByTestId(LINK_PREVIEW_DISMISS_BTN_TEST_ID)); }); linkPreviews = screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(0); await act(async () => { @@ -830,7 +834,7 @@ describe('Link preview', () => { }); const linkPreviews = await screen.queryAllByTestId(LINK_PREVIEW_TEST_ID); - // eslint-disable-next-line + expect(linkPreviews).toHaveLength(1); expect(linkPreviews[0]).toHaveTextContent(scrapedData1.og_scrape_url); }); @@ -950,10 +954,11 @@ describe('Link preview', () => { it('submit new message with skip_url_enrich:false if no link previews managed to get loaded', async () => { const channel = chatClient.channel('messaging', mockedChannelData.channel.id); const sendMessageSpy = jest.spyOn(channel, 'sendMessage').mockImplementation(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars let resolveEnrichURLPromise; jest .spyOn(chatClient, 'enrichURL') - // eslint-disable-next-line no-unused-vars + .mockImplementationOnce(() => new Promise((res) => (resolveEnrichURLPromise = res))); const { submit } = await renderComponent({ @@ -987,10 +992,11 @@ describe('Link preview', () => { const sendMessageSpy = jest.spyOn(channel, 'sendMessage').mockImplementation(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars let resolveEnrichURLPromise; jest .spyOn(chatClient, 'enrichURL') - // eslint-disable-next-line no-unused-vars + .mockImplementationOnce(() => new Promise((res) => (resolveEnrichURLPromise = res))); const { submit } = await renderComponent({ diff --git a/src/components/MessageInput/__tests__/MessageInput.test.js b/src/components/MessageInput/__tests__/MessageInput.test.js index cac2baeca..ca5d5fc8d 100644 --- a/src/components/MessageInput/__tests__/MessageInput.test.js +++ b/src/components/MessageInput/__tests__/MessageInput.test.js @@ -111,64 +111,66 @@ function dropFile(file, formElement) { }); } -const makeRenderFn = (InputComponent) => async ({ - channelProps = {}, - channelData = [], - chatContextOverrides = {}, - customChannel, - customClient, - customUser, - messageInputProps = {}, - messageContextOverrides = {}, - messageActionsBoxProps = {}, -} = {}) => { - let channel = customChannel; - let client = customClient; - if (!(channel || client)) { - const result = await initClientWithChannels({ - channelsData: [{ ...mockedChannelData, ...channelData }], - customUser: customUser || user, - }); - channel = result.channels[0]; - client = result.client; - } - let renderResult; - - const defaultMessageInputProps = - InputComponent.name === 'EditMessageForm' ? { message: mainListMessage } : {}; - await act(() => { - renderResult = render( - - - - + async ({ + channelData = [], + channelProps = {}, + chatContextOverrides = {}, + customChannel, + customClient, + customUser, + messageActionsBoxProps = {}, + messageContextOverrides = {}, + messageInputProps = {}, + } = {}) => { + let channel = customChannel; + let client = customClient; + if (!(channel || client)) { + const result = await initClientWithChannels({ + channelsData: [{ ...mockedChannelData, ...channelData }], + customUser: customUser || user, + }); + channel = result.channels[0]; + client = result.client; + } + let renderResult; + + const defaultMessageInputProps = + InputComponent.name === 'EditMessageForm' ? { message: mainListMessage } : {}; + await act(() => { + renderResult = render( + + + + + + - - - - , - ); - }); + + , + ); + }); - const submit = async () => { - const submitButton = - renderResult.queryByTestId(SEND_BTN_EDIT_FORM_TEST_ID) || - renderResult.findByText('Send') || - renderResult.findByTitle('Send'); - fireEvent.click(await submitButton); - }; + const submit = async () => { + const submitButton = + renderResult.queryByTestId(SEND_BTN_EDIT_FORM_TEST_ID) || + renderResult.findByText('Send') || + renderResult.findByTitle('Send'); + fireEvent.click(await submitButton); + }; - return { channel, client, submit, ...renderResult }; -}; + return { channel, client, submit, ...renderResult }; + }; const tearDown = () => { cleanup(); @@ -957,7 +959,7 @@ function axeNoViolations(container) { act(() => dropFile(file, formElement)); // wait for image uploading to complete before trying to send the message - // eslint-disable-next-line jest/prefer-called-with + await waitFor(() => expect(doImageUploadRequest).toHaveBeenCalled()); await act(() => submit()); @@ -1001,7 +1003,7 @@ function axeNoViolations(container) { act(() => dropFile(file, formElement)); // wait for file uploading to complete before trying to send the message - // eslint-disable-next-line jest/prefer-called-with + await waitFor(() => expect(doFileUploadRequest).toHaveBeenCalled()); await act(() => submit()); @@ -1047,7 +1049,7 @@ function axeNoViolations(container) { act(() => dropFile(file, formElement)); // wait for file uploading to complete before trying to send the message - // eslint-disable-next-line jest/prefer-called-with + await waitFor(() => expect(doFileUploadRequest).toHaveBeenCalled()); await act(() => submit()); @@ -1395,9 +1397,7 @@ function axeNoViolations(container) { }); if (componentName !== 'EditMessageForm') { - await waitFor( - () => expect(screen.getByTestId('suggestion-list')).toBeInTheDocument(), // eslint-disable-line - ); + await waitFor(() => expect(screen.getByTestId('suggestion-list')).toBeInTheDocument()); const results = await axe(container); expect(results).toHaveNoViolations(); } diff --git a/src/components/MessageInput/hooks/__tests__/useMessageInputState.test.js b/src/components/MessageInput/hooks/__tests__/useMessageInputState.test.js index eea7c66a9..7245683e6 100644 --- a/src/components/MessageInput/hooks/__tests__/useMessageInputState.test.js +++ b/src/components/MessageInput/hooks/__tests__/useMessageInputState.test.js @@ -205,7 +205,7 @@ describe('useMessageInputState', () => { file: { name: type === 'image' ? data.fallback : data.title, type: - type === 'image' ? 'image/' + data.fallback.split('.')[1] : data.mime_type ?? '', + type === 'image' ? 'image/' + data.fallback.split('.')[1] : (data.mime_type ?? ''), }, }; const attachment = { @@ -433,9 +433,8 @@ describe('useMessageInputState', () => { props: scenario === 'custom' ? { - [type === 'image' - ? 'doImageUploadRequest' - : 'doFileUploadRequest']: customSendSpy, + [type === 'image' ? 'doImageUploadRequest' : 'doFileUploadRequest']: + customSendSpy, } : {}, }); diff --git a/src/components/MessageInput/hooks/useAttachments.ts b/src/components/MessageInput/hooks/useAttachments.ts index a9e279fb7..0c9576b5d 100644 --- a/src/components/MessageInput/hooks/useAttachments.ts +++ b/src/components/MessageInput/hooks/useAttachments.ts @@ -38,7 +38,7 @@ const getAttachmentTypeFromMime = (mimeType: string) => { }; const ensureIsLocalAttachment = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( attachment: Attachment | LocalAttachment, ): LocalAttachment => { @@ -57,7 +57,7 @@ const ensureIsLocalAttachment = < export const useAttachments = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: MessageInputProps, state: MessageInputState, @@ -68,9 +68,8 @@ export const useAttachments = < const { getAppSettings } = useChatContext('useAttachments'); const { t } = useTranslationContext('useAttachments'); const { addNotification } = useChannelActionContext('useAttachments'); - const { channel, maxNumberOfFiles, multipleUploads } = useChannelStateContext( - 'useAttachments', - ); + const { channel, maxNumberOfFiles, multipleUploads } = + useChannelStateContext('useAttachments'); // Number of files that the user can still add. Should never be more than the amount allowed by the API. // If multipleUploads is false, we only want to allow a single upload. diff --git a/src/components/MessageInput/hooks/useCommandTrigger.ts b/src/components/MessageInput/hooks/useCommandTrigger.ts index c87eff808..3f0ed4789 100644 --- a/src/components/MessageInput/hooks/useCommandTrigger.ts +++ b/src/components/MessageInput/hooks/useCommandTrigger.ts @@ -10,12 +10,12 @@ import type { CommandTriggerSetting } from '../DefaultTriggerProvider'; import type { DefaultStreamChatGenerics } from '../../../types/types'; type ValidCommand< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Required, 'name'>> & Omit, 'name'>; export const useCommandTrigger = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(): CommandTriggerSetting => { const { channelConfig } = useChannelStateContext('useCommandTrigger'); const { t } = useTranslationContext('useCommandTrigger'); diff --git a/src/components/MessageInput/hooks/useCooldownTimer.tsx b/src/components/MessageInput/hooks/useCooldownTimer.tsx index a86207ee3..728e50d52 100644 --- a/src/components/MessageInput/hooks/useCooldownTimer.tsx +++ b/src/components/MessageInput/hooks/useCooldownTimer.tsx @@ -12,11 +12,10 @@ export type CooldownTimerState = { }; export const useCooldownTimer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(): CooldownTimerState => { - const { client, latestMessageDatesByChannels } = useChatContext( - 'useCooldownTimer', - ); + const { client, latestMessageDatesByChannels } = + useChatContext('useCooldownTimer'); const { channel, messages = [] } = useChannelStateContext('useCooldownTimer'); const [cooldownRemaining, setCooldownRemaining] = useState(); diff --git a/src/components/MessageInput/hooks/useCreateMessageInputContext.ts b/src/components/MessageInput/hooks/useCreateMessageInputContext.ts index 60f09df24..8fa3576ba 100644 --- a/src/components/MessageInput/hooks/useCreateMessageInputContext.ts +++ b/src/components/MessageInput/hooks/useCreateMessageInputContext.ts @@ -5,7 +5,7 @@ import type { CustomTrigger, DefaultStreamChatGenerics } from '../../../types/ty export const useCreateMessageInputContext = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( value: MessageInputContextValue, ) => { diff --git a/src/components/MessageInput/hooks/useLinkPreviews.ts b/src/components/MessageInput/hooks/useLinkPreviews.ts index 5f37dd2d6..b507ce2f6 100644 --- a/src/components/MessageInput/hooks/useLinkPreviews.ts +++ b/src/components/MessageInput/hooks/useLinkPreviews.ts @@ -20,7 +20,7 @@ export type URLEnrichmentConfig = { }; type UseEnrichURLsParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = URLEnrichmentConfig & { dispatch: Dispatch>; linkPreviews: MessageInputState['linkPreviews']; @@ -36,7 +36,7 @@ export type EnrichURLsController = { }; export const useLinkPreviews = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ debounceURLEnrichmentMs: debounceURLEnrichmentMsInputContext, dispatch, diff --git a/src/components/MessageInput/hooks/useMessageInputState.ts b/src/components/MessageInput/hooks/useMessageInputState.ts index 5c95f6c77..49730ef89 100644 --- a/src/components/MessageInput/hooks/useMessageInputState.ts +++ b/src/components/MessageInput/hooks/useMessageInputState.ts @@ -23,7 +23,7 @@ import type { import { mergeDeep } from '../../../utils/mergeDeep'; export type MessageInputState< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachments: LocalAttachment[]; linkPreviews: LinkPreviewMap; @@ -33,7 +33,7 @@ export type MessageInputState< }; type UpsertAttachmentsAction< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachments: LocalAttachment[]; type: 'upsertAttachments'; @@ -60,14 +60,14 @@ type SetLinkPreviewsAction = { }; type AddMentionedUserAction< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { type: 'addMentionedUser'; user: UserResponse; }; export type MessageInputReducerAction< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = | SetTextAction | ClearAction @@ -77,7 +77,7 @@ export type MessageInputReducerAction< | RemoveAttachmentsAction; export type MessageInputHookProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = EnrichURLsController & { handleChange: React.ChangeEventHandler; handleSubmit: ( @@ -104,7 +104,7 @@ export type MessageInputHookProps< }; const makeEmptyMessageInputState = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(): MessageInputState => ({ attachments: [], linkPreviews: new Map(), @@ -117,7 +117,7 @@ const makeEmptyMessageInputState = < * Initializes the state. Empty if the message prop is falsy. */ const initState = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message?: Pick, 'attachments' | 'mentioned_users' | 'text'>, ): MessageInputState => { @@ -143,7 +143,7 @@ const initState = < ({ ...att, localMetadata: { id: nanoid() }, - } as LocalAttachment), + }) as LocalAttachment, ) || []; const mentioned_users: StreamMessage['mentioned_users'] = message.mentioned_users || []; @@ -161,7 +161,7 @@ const initState = < * MessageInput state reducer */ const messageInputReducer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( state: MessageInputState, action: MessageInputReducerAction, @@ -265,7 +265,7 @@ export type MentionsListState = { */ export const useMessageInputState = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: MessageInputProps, ): MessageInputState & @@ -282,10 +282,8 @@ export const useMessageInputState = < urlEnrichmentConfig, } = props; - const { - channelCapabilities = {}, - enrichURLForPreview: enrichURLForPreviewChannelContext, - } = useChannelStateContext('useMessageInputState'); + const { channelCapabilities = {}, enrichURLForPreview: enrichURLForPreviewChannelContext } = + useChannelStateContext('useMessageInputState'); const defaultValue = getDefaultValue?.() || additionalTextareaProps?.defaultValue; const initialStateValue = diff --git a/src/components/MessageInput/hooks/useMessageInputText.ts b/src/components/MessageInput/hooks/useMessageInputText.ts index e39842e03..abd9258f3 100644 --- a/src/components/MessageInput/hooks/useMessageInputText.ts +++ b/src/components/MessageInput/hooks/useMessageInputText.ts @@ -9,7 +9,7 @@ import type { EnrichURLsController } from './useLinkPreviews'; export const useMessageInputText = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: MessageInputProps, state: MessageInputState, diff --git a/src/components/MessageInput/hooks/useSubmitHandler.ts b/src/components/MessageInput/hooks/useSubmitHandler.ts index 5df169afd..320b37cab 100644 --- a/src/components/MessageInput/hooks/useSubmitHandler.ts +++ b/src/components/MessageInput/hooks/useSubmitHandler.ts @@ -18,7 +18,7 @@ import type { EnrichURLsController } from './useLinkPreviews'; export const useSubmitHandler = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: MessageInputProps, state: MessageInputState, @@ -32,9 +32,8 @@ export const useSubmitHandler = < const { cancelURLEnrichment, findAndEnqueueURLsToEnrich } = enrichURLsController; const { channel } = useChannelStateContext('useSubmitHandler'); - const { addNotification, editMessage, sendMessage } = useChannelActionContext( - 'useSubmitHandler', - ); + const { addNotification, editMessage, sendMessage } = + useChannelActionContext('useSubmitHandler'); const { t } = useTranslationContext('useSubmitHandler'); const textReference = useRef({ hasChanged: false, initialText: text }); @@ -87,6 +86,7 @@ export const useSubmitHandler = < (findAndEnqueueURLsToEnrich && !att.og_scrape_url), // filter out all the attachments scraped before the message was edited ) .map((localAttachment) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { localMetadata: _, ...attachment } = localAttachment; return attachment as Attachment; }); @@ -146,11 +146,11 @@ export const useSubmitHandler = < try { await editMessage( - ({ + { ...message, ...updatedMessage, ...customMessageData, - } as unknown) as UpdatedMessage, + } as unknown as UpdatedMessage, sendOptions, ); diff --git a/src/components/MessageInput/hooks/useUserTrigger.ts b/src/components/MessageInput/hooks/useUserTrigger.ts index e02b190f3..ffdd7d38d 100644 --- a/src/components/MessageInput/hooks/useUserTrigger.ts +++ b/src/components/MessageInput/hooks/useUserTrigger.ts @@ -16,7 +16,7 @@ import type { UserTriggerSetting } from '../../MessageInput/DefaultTriggerProvid import type { DefaultStreamChatGenerics } from '../../../types/types'; export type UserTriggerParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { onSelectUser: (item: UserResponse) => void; disableMentions?: boolean; @@ -26,7 +26,7 @@ export type UserTriggerParams< }; export const useUserTrigger = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: UserTriggerParams, ): UserTriggerSetting => { @@ -68,7 +68,7 @@ export const useUserTrigger = < throttle( async (query: string, onReady: (users: UserResponse[]) => void) => { try { - // @ts-expect-error + // @ts-expect-error valid query const response = await channel.queryMembers({ name: { $autocomplete: query }, }); @@ -100,7 +100,7 @@ export const useUserTrigger = < try { const { users } = await client.queryUsers( - // @ts-expect-error + // @ts-expect-error valid query { $or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }], ...(typeof mentionQueryParams.filters === 'function' diff --git a/src/components/MessageInput/hooks/utils.ts b/src/components/MessageInput/hooks/utils.ts index e73c212a4..56567fc10 100644 --- a/src/components/MessageInput/hooks/utils.ts +++ b/src/components/MessageInput/hooks/utils.ts @@ -60,7 +60,7 @@ export const calculateLevenshtein = (query: string, name: string) => { }; export type SearchLocalUserParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { ownUserId: string | undefined; query: string; @@ -70,7 +70,7 @@ export type SearchLocalUserParams< }; export const searchLocalUsers = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: SearchLocalUserParams, ): UserResponse[] => { @@ -86,6 +86,7 @@ export const searchLocalUsers = < if (useMentionsTransliteration) { (async () => { + // eslint-disable-next-line import/no-extraneous-dependencies const { default: transliterate } = await import('@stream-io/transliterate'); updatedName = transliterate(user.name || '').toLowerCase(); updatedQuery = transliterate(query).toLowerCase(); @@ -112,7 +113,7 @@ export const searchLocalUsers = < }; type CheckUploadPermissionsParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { addNotification: ChannelActionContextValue['addNotification']; file: File; @@ -122,7 +123,7 @@ type CheckUploadPermissionsParams< }; export const checkUploadPermissions = async < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: CheckUploadPermissionsParams, ) => { diff --git a/src/components/MessageInput/types.ts b/src/components/MessageInput/types.ts index b9b2a77f2..f332e06b1 100644 --- a/src/components/MessageInput/types.ts +++ b/src/components/MessageInput/types.ts @@ -31,7 +31,7 @@ export enum SetLinkPreviewMode { export type LinkPreviewMap = Map; export type VoiceRecordingAttachment< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics + StreamChatGenerics extends ExtendableGenerics = DefaultGenerics, > = Attachment & { asset_url: string; type: 'voiceRecording'; @@ -42,45 +42,41 @@ export type VoiceRecordingAttachment< waveform_data?: Array; }; -type FileAttachment< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics -> = Attachment & { - type: 'file'; - asset_url?: string; - file_size?: number; - mime_type?: string; - title?: string; -}; - -export type AudioAttachment< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics -> = Attachment & { - type: 'audio'; - asset_url?: string; - file_size?: number; - mime_type?: string; - title?: string; -}; - -export type VideoAttachment< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics -> = Attachment & { - type: 'video'; - asset_url?: string; - mime_type?: string; - thumb_url?: string; - title?: string; -}; - -type ImageAttachment< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics -> = Attachment & { - type: 'image'; - fallback?: string; - image_url?: string; - original_height?: number; - original_width?: number; -}; +type FileAttachment = + Attachment & { + type: 'file'; + asset_url?: string; + file_size?: number; + mime_type?: string; + title?: string; + }; + +export type AudioAttachment = + Attachment & { + type: 'audio'; + asset_url?: string; + file_size?: number; + mime_type?: string; + title?: string; + }; + +export type VideoAttachment = + Attachment & { + type: 'video'; + asset_url?: string; + mime_type?: string; + thumb_url?: string; + title?: string; + }; + +type ImageAttachment = + Attachment & { + type: 'image'; + fallback?: string; + image_url?: string; + original_height?: number; + original_width?: number; + }; export type BaseLocalAttachmentMetadata = { id: string; @@ -99,13 +95,12 @@ export type LocalAttachmentCast> = A & { localMetadata: L & BaseLocalAttachmentMetadata; }; -export type LocalAttachmentMetadata< - CustomLocalMetadata = Record -> = CustomLocalMetadata & BaseLocalAttachmentMetadata & LocalImageAttachmentUploadMetadata; +export type LocalAttachmentMetadata> = + CustomLocalMetadata & BaseLocalAttachmentMetadata & LocalImageAttachmentUploadMetadata; export type LocalVoiceRecordingAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< VoiceRecordingAttachment, LocalAttachmentUploadMetadata & CustomLocalMetadata @@ -113,7 +108,7 @@ export type LocalVoiceRecordingAttachment< export type LocalAudioAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< AudioAttachment, LocalAttachmentUploadMetadata & CustomLocalMetadata @@ -121,7 +116,7 @@ export type LocalAudioAttachment< export type LocalVideoAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< VideoAttachment, LocalAttachmentUploadMetadata & CustomLocalMetadata @@ -129,7 +124,7 @@ export type LocalVideoAttachment< export type LocalImageAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< ImageAttachment, LocalImageAttachmentUploadMetadata & CustomLocalMetadata @@ -137,7 +132,7 @@ export type LocalImageAttachment< export type LocalFileAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< FileAttachment, LocalAttachmentUploadMetadata & CustomLocalMetadata @@ -145,14 +140,14 @@ export type LocalFileAttachment< export type AnyLocalAttachment< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = LocalAttachmentCast< Attachment, LocalAttachmentMetadata >; export type LocalAttachment< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = | AnyLocalAttachment | LocalFileAttachment @@ -163,7 +158,7 @@ export type LocalAttachment< export type LocalAttachmentToUpload< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - CustomLocalMetadata = Record + CustomLocalMetadata = Record, > = Partial> & { localMetadata: Partial & LocalAttachmentUploadMetadata & diff --git a/src/components/MessageList/ConnectionStatus.tsx b/src/components/MessageList/ConnectionStatus.tsx index 8099baa62..c2746951a 100644 --- a/src/components/MessageList/ConnectionStatus.tsx +++ b/src/components/MessageList/ConnectionStatus.tsx @@ -7,7 +7,7 @@ import { useChatContext, useTranslationContext } from '../../context'; import type { DefaultStreamChatGenerics } from '../../types/types'; const UnMemoizedConnectionStatus = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { client } = useChatContext('ConnectionStatus'); const { t } = useTranslationContext('ConnectionStatus'); diff --git a/src/components/MessageList/GiphyPreviewMessage.tsx b/src/components/MessageList/GiphyPreviewMessage.tsx index 66ae87b34..91f0ad4b5 100644 --- a/src/components/MessageList/GiphyPreviewMessage.tsx +++ b/src/components/MessageList/GiphyPreviewMessage.tsx @@ -6,13 +6,13 @@ import type { StreamMessage } from '../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type GiphyPreviewMessageProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { message: StreamMessage; }; export const GiphyPreviewMessage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: GiphyPreviewMessageProps, ) => { diff --git a/src/components/MessageList/MessageList.tsx b/src/components/MessageList/MessageList.tsx index 21a9fcd88..f67afb5d6 100644 --- a/src/components/MessageList/MessageList.tsx +++ b/src/components/MessageList/MessageList.tsx @@ -46,12 +46,12 @@ import { } from '../../constants/limits'; type MessageListWithContextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, 'members' | 'mutes' | 'watchers'> & MessageListProps; const MessageListWithContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageListWithContextProps, ) => { @@ -60,36 +60,36 @@ const MessageListWithContext = < channelUnreadUiState, disableDateSeparator = false, groupStyles, + hasMoreNewer = false, + headerPosition, hideDeletedMessages = false, hideNewMessageSeparator = false, + highlightedMessageId, internalInfiniteScrollProps: { threshold: loadMoreScrollThreshold = DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD, ...restInternalInfiniteScrollProps } = {}, + jumpToLatestMessage = () => Promise.resolve(), + loadMore: loadMoreCallback, + loadMoreNewer: loadMoreNewerCallback, // @deprecated in favor of `channelCapabilities` - TODO: remove in next major release maxTimeBetweenGroupedMessages, messageActions = Object.keys(MESSAGE_ACTIONS), + messageLimit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE, messages = [], - notifications, noGroupByUser = false, - pinPermissions = defaultPinPermissions, // @deprecated in favor of `channelCapabilities` - TODO: remove in next major release - returnAllReadData = false, - threadList = false, - unsafeHTML = false, - headerPosition, + notifications, + pinPermissions = defaultPinPermissions, + reactionDetailsSort, read, renderMessages = defaultRenderMessages, + returnAllReadData = false, reviewProcessedMessage, - messageLimit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE, - loadMore: loadMoreCallback, - loadMoreNewer: loadMoreNewerCallback, - hasMoreNewer = false, - reactionDetailsSort, showUnreadNotificationAlways, sortReactionDetails, sortReactions, suppressAutoscroll, - highlightedMessageId, - jumpToLatestMessage = () => Promise.resolve(), + threadList = false, + unsafeHTML = false, } = props; const [listElement, setListElement] = React.useState(null); @@ -100,27 +100,22 @@ const MessageListWithContext = < const { EmptyStateIndicator = DefaultEmptyStateIndicator, LoadingIndicator = DefaultLoadingIndicator, + MessageListMainPanel = DefaultMessageListMainPanel, MessageListNotifications = DefaultMessageListNotifications, MessageNotification = DefaultMessageNotification, TypingIndicator = DefaultTypingIndicator, UnreadMessagesNotification = DefaultUnreadMessagesNotification, - MessageListMainPanel = DefaultMessageListMainPanel, } = useComponentContext('MessageList'); - const { - hasNewMessages, - isMessageListScrolledToBottom, - onScroll, - scrollToBottom, - wrapperRect, - } = useScrollLocationLogic({ - hasMoreNewer, - listElement, - loadMoreScrollThreshold, - messages, - scrolledUpThreshold: props.scrolledUpThreshold, - suppressAutoscroll, - }); + const { hasNewMessages, isMessageListScrolledToBottom, onScroll, scrollToBottom, wrapperRect } = + useScrollLocationLogic({ + hasMoreNewer, + listElement, + loadMoreScrollThreshold, + messages, + scrolledUpThreshold: props.scrolledUpThreshold, + suppressAutoscroll, + }); const { show: showUnreadMessagesNotification } = useUnreadMessagesNotification({ isMessageListScrolledToBottom, @@ -313,7 +308,7 @@ type PropsDrilledToMessage = | 'unsafeHTML'; export type MessageListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial, PropsDrilledToMessage>> & { /** Disables the injection of date separator components in MessageList, defaults to `false` */ disableDateSeparator?: boolean; @@ -389,15 +384,12 @@ export type MessageListProps< * - [TypingContext](https://getstream.io/chat/docs/sdk/react/contexts/typing_context/) */ export const MessageList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageListProps, ) => { - const { - jumpToLatestMessage, - loadMore, - loadMoreNewer, - } = useChannelActionContext('MessageList'); + const { jumpToLatestMessage, loadMore, loadMoreNewer } = + useChannelActionContext('MessageList'); const { members: membersPropToNotPass, // eslint-disable-line @typescript-eslint/no-unused-vars diff --git a/src/components/MessageList/MessageListMainPanel.tsx b/src/components/MessageList/MessageListMainPanel.tsx index 8dd72069a..3c2635ac1 100644 --- a/src/components/MessageList/MessageListMainPanel.tsx +++ b/src/components/MessageList/MessageListMainPanel.tsx @@ -1,7 +1,8 @@ import React from 'react'; import type { PropsWithChildrenOnly } from '../../types/types'; -export const MESSAGE_LIST_MAIN_PANEL_CLASS = 'str-chat__main-panel-inner str-chat__message-list-main-panel' as const; +export const MESSAGE_LIST_MAIN_PANEL_CLASS = + 'str-chat__main-panel-inner str-chat__message-list-main-panel' as const; export const MessageListMainPanel = ({ children }: PropsWithChildrenOnly) => (
{children}
diff --git a/src/components/MessageList/VirtualizedMessageList.tsx b/src/components/MessageList/VirtualizedMessageList.tsx index 897819525..9169d518a 100644 --- a/src/components/MessageList/VirtualizedMessageList.tsx +++ b/src/components/MessageList/VirtualizedMessageList.tsx @@ -89,7 +89,7 @@ type VirtualizedMessageListPropsForContext = * Context object provided to some Virtuoso props that are functions (components rendered by Virtuoso and other functions) */ export type VirtuosoContext< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Required< Pick< ComponentContextValue, @@ -123,7 +123,7 @@ export type VirtuosoContext< }; type VirtualizedMessageListWithContextProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = VirtualizedMessageListProps & { channel: Channel; hasMore: boolean; @@ -175,7 +175,7 @@ function calculateInitialTopMostItemIndex( } const VirtualizedMessageListWithContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: VirtualizedMessageListWithContextProps, ) => { @@ -209,6 +209,7 @@ const VirtualizedMessageListWithContext = < openThread, // TODO: refactor to scrollSeekPlaceHolderConfiguration and components.ScrollSeekPlaceholder, like the Virtuoso Component overscan = 0, + reactionDetailsSort, read, returnAllReadData = false, reviewProcessedMessage, @@ -217,7 +218,6 @@ const VirtualizedMessageListWithContext = < separateGiphyPreview = false, shouldGroupByUser = false, showUnreadNotificationAlways, - reactionDetailsSort, sortReactionDetails, sortReactions, stickToBottomScrollBehavior = 'smooth', @@ -225,10 +225,8 @@ const VirtualizedMessageListWithContext = < threadList, } = props; - const { - components: virtuosoComponentsFromProps, - ...overridingVirtuosoProps - } = additionalVirtuosoProps; + const { components: virtuosoComponentsFromProps, ...overridingVirtuosoProps } = + additionalVirtuosoProps; // Stops errors generated from react-virtuoso to bubble up // to Sentry or other tracking tools. @@ -237,14 +235,14 @@ const VirtualizedMessageListWithContext = < const { DateSeparator = DefaultDateSeparator, GiphyPreviewMessage = DefaultGiphyPreviewMessage, + MessageListMainPanel = DefaultMessageListMainPanel, MessageListNotifications = DefaultMessageListNotifications, MessageNotification = DefaultMessageNotification, MessageSystem = DefaultMessageSystem, - MessageListMainPanel = DefaultMessageListMainPanel, + TypingIndicator, UnreadMessagesNotification = DefaultUnreadMessagesNotification, UnreadMessagesSeparator = DefaultUnreadMessagesSeparator, VirtualMessage: MessageUIComponentFromContext = MessageSimple, - TypingIndicator, } = useComponentContext('VirtualizedMessageList'); const MessageUIComponent = MessageUIComponentFromProps || MessageUIComponentFromContext; @@ -254,18 +252,15 @@ const VirtualizedMessageListWithContext = < const lastRead = useMemo(() => channel.lastRead?.(), [channel]); - const { - show: showUnreadMessagesNotification, - toggleShowUnreadMessagesNotification, - } = useUnreadMessagesNotificationVirtualized({ - lastRead: channelUnreadUiState?.last_read, - showAlways: !!showUnreadNotificationAlways, - unreadCount: channelUnreadUiState?.unread_messages ?? 0, - }); + const { show: showUnreadMessagesNotification, toggleShowUnreadMessagesNotification } = + useUnreadMessagesNotificationVirtualized({ + lastRead: channelUnreadUiState?.last_read, + showAlways: !!showUnreadNotificationAlways, + unreadCount: channelUnreadUiState?.unread_messages ?? 0, + }); - const { giphyPreviewMessage, setGiphyPreviewMessage } = useGiphyPreview( - separateGiphyPreview, - ); + const { giphyPreviewMessage, setGiphyPreviewMessage } = + useGiphyPreview(separateGiphyPreview); const processedMessages = useMemo(() => { if (typeof messages === 'undefined') { @@ -310,9 +305,10 @@ const VirtualizedMessageListWithContext = < userID: client.userID, }); - const lastReceivedMessageId = useMemo(() => getLastReceived(processedMessages), [ - processedMessages, - ]); + const lastReceivedMessageId = useMemo( + () => getLastReceived(processedMessages), + [processedMessages], + ); const groupStylesFn = groupStyles || getGroupStyles; const messageGroupStyles = useMemo( @@ -529,7 +525,7 @@ const VirtualizedMessageListWithContext = < }; export type VirtualizedMessageListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial, PropsDrilledToMessage>> & { /** Additional props to be passed the underlying [`react-virtuoso` virtualized list dependency](https://virtuoso.dev/virtuoso-api-reference/) */ additionalVirtuosoProps?: VirtuosoProps>; @@ -639,13 +635,10 @@ export type VirtualizedMessageListProps< * It is a consumer of the React contexts set in [Channel](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Channel/Channel.tsx). */ export function VirtualizedMessageList< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(props: VirtualizedMessageListProps) { - const { - jumpToLatestMessage, - loadMore, - loadMoreNewer, - } = useChannelActionContext('VirtualizedMessageList'); + const { jumpToLatestMessage, loadMore, loadMoreNewer } = + useChannelActionContext('VirtualizedMessageList'); const { channel, channelUnreadUiState, diff --git a/src/components/MessageList/VirtualizedMessageListComponents.tsx b/src/components/MessageList/VirtualizedMessageListComponents.tsx index 6a4615b0d..81df52cc2 100644 --- a/src/components/MessageList/VirtualizedMessageListComponents.tsx +++ b/src/components/MessageList/VirtualizedMessageListComponents.tsx @@ -25,7 +25,7 @@ export function calculateFirstItemIndex(numItemsPrepended: number) { } export const makeItemsRenderedHandler = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( renderedItemsActions: Array<(msg: StreamMessage[]) => void>, processedMessages: StreamMessage[], @@ -43,14 +43,14 @@ export const makeItemsRenderedHandler = < }, 200); type CommonVirtuosoComponentProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { context?: VirtuosoContext; }; // using 'display: inline-block' // traps CSS margins of the item elements, preventing incorrect item measurements export const Item = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ context, ...props @@ -76,7 +76,7 @@ export const Item = < ); }; export const Header = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ context, }: CommonVirtuosoComponentProps) => { @@ -96,13 +96,12 @@ export const Header = < ); }; export const EmptyPlaceholder = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ context, }: CommonVirtuosoComponentProps) => { - const { - EmptyStateIndicator = DefaultEmptyStateIndicator, - } = useComponentContext('VirtualizedMessageList'); + const { EmptyStateIndicator = DefaultEmptyStateIndicator } = + useComponentContext('VirtualizedMessageList'); return ( <> {EmptyStateIndicator && ( @@ -113,7 +112,7 @@ export const EmptyPlaceholder = < }; export const messageRenderer = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( virtuosoIndex: number, _data: UnknownType, diff --git a/src/components/MessageList/__tests__/CustomNotification.test.js b/src/components/MessageList/__tests__/CustomNotification.test.js index a174675ee..8b59fbf80 100644 --- a/src/components/MessageList/__tests__/CustomNotification.test.js +++ b/src/components/MessageList/__tests__/CustomNotification.test.js @@ -6,7 +6,7 @@ import { cleanup, render } from '@testing-library/react'; import { CustomNotification } from '../CustomNotification'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('CustomNotification', () => { it('should render nothing if active is false', () => { diff --git a/src/components/MessageList/__tests__/MessageList.test.js b/src/components/MessageList/__tests__/MessageList.test.js index 8cf6deaa2..000dddc9f 100644 --- a/src/components/MessageList/__tests__/MessageList.test.js +++ b/src/components/MessageList/__tests__/MessageList.test.js @@ -364,7 +364,7 @@ describe('MessageList', () => { return null; } } - // eslint-disable-next-line jest/prefer-spy-on + window.IntersectionObserver = IntersectionObserverMock; }); afterEach(jest.clearAllMocks); diff --git a/src/components/MessageList/__tests__/MessageNotification.test.js b/src/components/MessageList/__tests__/MessageNotification.test.js index 02eef9cf9..067aa735f 100644 --- a/src/components/MessageList/__tests__/MessageNotification.test.js +++ b/src/components/MessageList/__tests__/MessageNotification.test.js @@ -7,7 +7,7 @@ expect.extend(toHaveNoViolations); import { MessageNotification } from '../MessageNotification'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('MessageNotification', () => { it('should render nothing if showNotification is false', () => { diff --git a/src/components/MessageList/__tests__/ScrollToBottomButton.test.js b/src/components/MessageList/__tests__/ScrollToBottomButton.test.js index 8901acce9..fe581f0c6 100644 --- a/src/components/MessageList/__tests__/ScrollToBottomButton.test.js +++ b/src/components/MessageList/__tests__/ScrollToBottomButton.test.js @@ -94,7 +94,6 @@ describe.each([ }); await waitFor(() => { - // eslint-disable-next-line jest/prefer-called-with expect(onClick).toHaveBeenCalled(); }); }); diff --git a/src/components/MessageList/hooks/MessageList/useEnrichedMessages.ts b/src/components/MessageList/hooks/MessageList/useEnrichedMessages.ts index f85af4c10..7a344c7bc 100644 --- a/src/components/MessageList/hooks/MessageList/useEnrichedMessages.ts +++ b/src/components/MessageList/hooks/MessageList/useEnrichedMessages.ts @@ -18,7 +18,7 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export const useEnrichedMessages = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(args: { channel: Channel; disableDateSeparator: boolean; diff --git a/src/components/MessageList/hooks/MessageList/useMessageListElements.tsx b/src/components/MessageList/hooks/MessageList/useMessageListElements.tsx index c7c77be12..6b9c84a20 100644 --- a/src/components/MessageList/hooks/MessageList/useMessageListElements.tsx +++ b/src/components/MessageList/hooks/MessageList/useMessageListElements.tsx @@ -13,7 +13,7 @@ import type { ChannelUnreadUiState, DefaultStreamChatGenerics } from '../../../. import { MessageRenderer, SharedMessageProps } from '../../renderMessages'; type UseMessageListElementsProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { enrichedMessages: StreamMessage[]; internalMessageProps: SharedMessageProps; @@ -26,7 +26,7 @@ type UseMessageListElementsProps< }; export const useMessageListElements = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: UseMessageListElementsProps, ) => { @@ -52,9 +52,10 @@ export const useMessageListElements = < userID: client.userID, }); - const lastReceivedMessageId = useMemo(() => getLastReceived(enrichedMessages), [ - enrichedMessages, - ]); + const lastReceivedMessageId = useMemo( + () => getLastReceived(enrichedMessages), + [enrichedMessages], + ); const elements: React.ReactNode[] = useMemo( () => diff --git a/src/components/MessageList/hooks/MessageList/useMessageListScrollManager.ts b/src/components/MessageList/hooks/MessageList/useMessageListScrollManager.ts index c4c7d74ed..73cf082a8 100644 --- a/src/components/MessageList/hooks/MessageList/useMessageListScrollManager.ts +++ b/src/components/MessageList/hooks/MessageList/useMessageListScrollManager.ts @@ -12,7 +12,7 @@ export type ContainerMeasures = { }; export type UseMessageListScrollManagerParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { loadMoreScrollThreshold: number; messages: StreamMessage[]; @@ -25,7 +25,7 @@ export type UseMessageListScrollManagerParams< // FIXME: change this generic name to something like useAdjustScrollPositionToListSize export function useMessageListScrollManager< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(params: UseMessageListScrollManagerParams) { const { loadMoreScrollThreshold, diff --git a/src/components/MessageList/hooks/MessageList/useScrollLocationLogic.tsx b/src/components/MessageList/hooks/MessageList/useScrollLocationLogic.tsx index ab4b18a40..9e25b0164 100644 --- a/src/components/MessageList/hooks/MessageList/useScrollLocationLogic.tsx +++ b/src/components/MessageList/hooks/MessageList/useScrollLocationLogic.tsx @@ -7,7 +7,7 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export type UseScrollLocationLogicParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { hasMoreNewer: boolean; listElement: HTMLDivElement | null; @@ -18,17 +18,17 @@ export type UseScrollLocationLogicParams< }; export const useScrollLocationLogic = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: UseScrollLocationLogicParams, ) => { const { + hasMoreNewer, + listElement, loadMoreScrollThreshold, messages = [], scrolledUpThreshold = 200, - hasMoreNewer, suppressAutoscroll, - listElement, } = params; const [hasNewMessages, setHasNewMessages] = useState(false); diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useGiphyPreview.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useGiphyPreview.ts index 6e67f1890..8566e800d 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useGiphyPreview.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useGiphyPreview.ts @@ -9,13 +9,12 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export const useGiphyPreview = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( separateGiphyPreview: boolean, ) => { - const [giphyPreviewMessage, setGiphyPreviewMessage] = useState< - StreamMessage - >(); + const [giphyPreviewMessage, setGiphyPreviewMessage] = + useState>(); const { client } = useChatContext('useGiphyPreview'); diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useMessageSetKey.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useMessageSetKey.ts index 584ba1a18..8aa006835 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useMessageSetKey.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useMessageSetKey.ts @@ -3,13 +3,13 @@ import { StreamMessage } from '../../../../context'; import { DefaultStreamChatGenerics } from '../../../../types/types'; type UseMessageSetKeyParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { messages?: StreamMessage[]; }; export const useMessageSetKey = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ messages, }: UseMessageSetKeyParams) => { diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useNewMessageNotification.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useNewMessageNotification.ts index ad4fda0f3..8441ac9d1 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useNewMessageNotification.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useNewMessageNotification.ts @@ -5,7 +5,7 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export function useNewMessageNotification< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( messages: StreamMessage[], currentUserId: string | undefined, diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts b/src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts index f2bff5eed..3cea71347 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts @@ -4,13 +4,13 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; -const STATUSES_EXCLUDED_FROM_PREPEND = ({ +const STATUSES_EXCLUDED_FROM_PREPEND = { failed: true, sending: true, -} as const) as Record; +} as const as Record; export function usePrependedMessagesCount< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(messages: StreamMessage[], hasDateSeparator: boolean) { const firstRealMessageIndex = hasDateSeparator ? 1 : 0; const firstMessageOnFirstLoadedPage = useRef>(); diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useScrollToBottomOnNewMessage.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useScrollToBottomOnNewMessage.ts index 712040a2e..fa20a250e 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useScrollToBottomOnNewMessage.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useScrollToBottomOnNewMessage.ts @@ -3,7 +3,7 @@ import { StreamMessage } from '../../../../context'; import { DefaultStreamChatGenerics } from '../../../../types/types'; type UseScrollToBottomOnNewMessageParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { scrollToBottom: () => void; messages?: StreamMessage[]; @@ -12,7 +12,7 @@ type UseScrollToBottomOnNewMessageParams< }; export const useScrollToBottomOnNewMessage = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ messages, scrollToBottom, diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useShouldForceScrollToBottom.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useShouldForceScrollToBottom.ts index 11103b60f..fb18dd24a 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useShouldForceScrollToBottom.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useShouldForceScrollToBottom.ts @@ -5,7 +5,7 @@ import type { StreamMessage } from '../../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../../types/types'; export function useShouldForceScrollToBottom< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(messages: StreamMessage[], currentUserId?: string) { const lastFocusedOwnMessage = useRef(''); const initialFocusRegistered = useRef(false); diff --git a/src/components/MessageList/hooks/VirtualizedMessageList/useUnreadMessagesNotificationVirtualized.ts b/src/components/MessageList/hooks/VirtualizedMessageList/useUnreadMessagesNotificationVirtualized.ts index f86f9395e..c5c280bd3 100644 --- a/src/components/MessageList/hooks/VirtualizedMessageList/useUnreadMessagesNotificationVirtualized.ts +++ b/src/components/MessageList/hooks/VirtualizedMessageList/useUnreadMessagesNotificationVirtualized.ts @@ -21,7 +21,7 @@ export type UseUnreadMessagesNotificationParams = { * @param unreadCount */ export const useUnreadMessagesNotificationVirtualized = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ lastRead, showAlways, diff --git a/src/components/MessageList/hooks/useLastReadData.ts b/src/components/MessageList/hooks/useLastReadData.ts index 814cd4596..f631f53a9 100644 --- a/src/components/MessageList/hooks/useLastReadData.ts +++ b/src/components/MessageList/hooks/useLastReadData.ts @@ -9,7 +9,7 @@ import type { StreamMessage } from '../../../context/ChannelStateContext'; import type { DefaultStreamChatGenerics } from '../../../types/types'; type UseLastReadDataParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { messages: StreamMessage[]; returnAllReadData: boolean; @@ -18,7 +18,7 @@ type UseLastReadDataParams< }; export const useLastReadData = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: UseLastReadDataParams, ) => { diff --git a/src/components/MessageList/hooks/useMarkRead.ts b/src/components/MessageList/hooks/useMarkRead.ts index 06a1bcf18..ad67170ce 100644 --- a/src/components/MessageList/hooks/useMarkRead.ts +++ b/src/components/MessageList/hooks/useMarkRead.ts @@ -26,7 +26,7 @@ type UseMarkReadParams = { * @param wasChannelMarkedUnread */ export const useMarkRead = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ isMessageListScrolledToBottom, messageListIsThread, @@ -103,7 +103,7 @@ export const useMarkRead = < }; function getPreviousLastMessage< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(messages: StreamMessage[], newMessage?: MessageResponse) { if (!newMessage) return; let previousLastMessage; diff --git a/src/components/MessageList/renderMessages.tsx b/src/components/MessageList/renderMessages.tsx index fb144a387..b4c74248f 100644 --- a/src/components/MessageList/renderMessages.tsx +++ b/src/components/MessageList/renderMessages.tsx @@ -15,7 +15,7 @@ import type { StreamMessage } from '../../context/ChannelStateContext'; import type { MessageProps } from '../Message'; export interface RenderMessagesOptions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > { components: ComponentContextValue; lastReceivedMessageId: string | null; @@ -39,11 +39,11 @@ export interface RenderMessagesOptions< } export type SharedMessageProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, MessagePropsToOmit>; export type MessageRenderer< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (options: RenderMessagesOptions) => Array; type MessagePropsToOmit = @@ -55,7 +55,7 @@ type MessagePropsToOmit = | 'readBy'; export function defaultRenderMessages< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ channelUnreadUiState, components, diff --git a/src/components/MessageList/utils.ts b/src/components/MessageList/utils.ts index dcf5bc94d..489536808 100644 --- a/src/components/MessageList/utils.ts +++ b/src/components/MessageList/utils.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-continue */ import { nanoid } from 'nanoid'; import { CUSTOM_MESSAGE_TYPE } from '../../constants/messageTypes'; @@ -23,7 +22,7 @@ type ProcessMessagesContext = { }; export type ProcessMessagesParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ProcessMessagesContext & { messages: StreamMessage[]; reviewProcessedMessage?: (params: { @@ -61,18 +60,13 @@ export type ProcessMessagesParams< * @return {StreamMessage[]} Transformed list of messages */ export const processMessages = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: ProcessMessagesParams, ) => { const { messages, reviewProcessedMessage, setGiphyPreviewMessage, ...context } = params; - const { - enableDateSeparator, - hideDeletedMessages, - hideNewMessageSeparator, - lastRead, - userId, - } = context; + const { enableDateSeparator, hideDeletedMessages, hideNewMessageSeparator, lastRead, userId } = + context; let unread = false; let ephemeralMessagePresent = false; @@ -171,7 +165,7 @@ export const makeDateMessageId = (date?: string | Date) => { // fast since it usually iterates just the last few messages export const getLastReceived = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( messages: StreamMessage[], ) => { @@ -185,7 +179,7 @@ export const getLastReceived = < }; export const getReadStates = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( messages: StreamMessage[], read: Record }> = {}, @@ -229,15 +223,15 @@ export const getReadStates = < }; export const insertIntro = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( messages: StreamMessage[], headerPosition?: number, ) => { const newMessages = messages; - const intro = ({ + const intro = { customType: CUSTOM_MESSAGE_TYPE.intro, - } as unknown) as StreamMessage; + } as unknown as StreamMessage; // if no headerPosition is set, HeaderComponent will go at the top if (!headerPosition) { @@ -285,7 +279,7 @@ export const insertIntro = < export type GroupStyle = '' | 'middle' | 'top' | 'bottom' | 'single'; export const getGroupStyles = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( message: StreamMessage, previousMessage: StreamMessage, @@ -368,8 +362,7 @@ type DateSeparatorMessage = { }; export function isDateSeparatorMessage< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics - // @ts-ignore + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(message: StreamMessage): message is DateSeparatorMessage { return message.customType === CUSTOM_MESSAGE_TYPE.date && !!message.date && isDate(message.date); } diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index f1e21c7ec..6faff0f26 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -34,7 +34,7 @@ export const Modal = ({ children, className, onClose, open }: PropsWithChildren< if (!open) return; const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') onClose?.((event as unknown) as React.KeyboardEvent); + if (event.key === 'Escape') onClose?.(event as unknown as React.KeyboardEvent); }; document.addEventListener('keydown', handleKeyDown); diff --git a/src/components/Modal/__tests__/Modal.test.js b/src/components/Modal/__tests__/Modal.test.js index 74227161b..5b177cd16 100644 --- a/src/components/Modal/__tests__/Modal.test.js +++ b/src/components/Modal/__tests__/Modal.test.js @@ -6,7 +6,7 @@ import '@testing-library/jest-dom'; import { Modal } from '../Modal'; describe('Modal', () => { - afterEach(cleanup); // eslint-disable-line + afterEach(cleanup); it('should be closed (null) if the `open` prop is set to false', () => { const { container } = render( {}} open={false} />); diff --git a/src/components/Poll/Poll.tsx b/src/components/Poll/Poll.tsx index 55dcbb058..016864244 100644 --- a/src/components/Poll/Poll.tsx +++ b/src/components/Poll/Poll.tsx @@ -6,7 +6,7 @@ import type { Poll as PollClass } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types'; export const Poll = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ isQuoted, poll, @@ -14,10 +14,8 @@ export const Poll = < poll: PollClass; isQuoted?: boolean; }) => { - const { - PollContent = DefaultPollContent, - QuotedPoll = DefaultQuotedPoll, - } = useComponentContext(); + const { PollContent = DefaultPollContent, QuotedPoll = DefaultQuotedPoll } = + useComponentContext(); return poll ? ( {isQuoted ? : } ) : null; diff --git a/src/components/Poll/PollActions/AddCommentForm.tsx b/src/components/Poll/PollActions/AddCommentForm.tsx index 71530f52a..ff3b0d51a 100644 --- a/src/components/Poll/PollActions/AddCommentForm.tsx +++ b/src/components/Poll/PollActions/AddCommentForm.tsx @@ -7,7 +7,7 @@ import type { DefaultStreamChatGenerics } from '../../../types'; type PollStateSelectorReturnValue = { ownAnswer: PollAnswer | undefined }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ ownAnswer: nextValue.ownAnswer }); @@ -18,7 +18,7 @@ export type AddCommentFormProps = { }; export const AddCommentForm = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, messageId, diff --git a/src/components/Poll/PollActions/EndPollDialog.tsx b/src/components/Poll/PollActions/EndPollDialog.tsx index a1b851e76..103243bda 100644 --- a/src/components/Poll/PollActions/EndPollDialog.tsx +++ b/src/components/Poll/PollActions/EndPollDialog.tsx @@ -8,7 +8,7 @@ export type EndPollDialogProps = { }; export const EndPollDialog = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, }: EndPollDialogProps) => { diff --git a/src/components/Poll/PollActions/PollActions.tsx b/src/components/Poll/PollActions/PollActions.tsx index 99fac20da..1cc184232 100644 --- a/src/components/Poll/PollActions/PollActions.tsx +++ b/src/components/Poll/PollActions/PollActions.tsx @@ -43,7 +43,7 @@ type PollStateSelectorReturnValue = { ownAnswer: PollAnswer | undefined; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -66,7 +66,7 @@ export type PollActionsProps = { }; export const PollActions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ AddCommentForm = DefaultAddCommentForm, EndPollDialog = DefaultEndPollDialog, diff --git a/src/components/Poll/PollActions/PollAnswerList.tsx b/src/components/Poll/PollActions/PollAnswerList.tsx index 78a6e59b8..c651d2e1f 100644 --- a/src/components/Poll/PollActions/PollAnswerList.tsx +++ b/src/components/Poll/PollActions/PollAnswerList.tsx @@ -15,7 +15,7 @@ type PollStateSelectorReturnValue = { ownAnswer: PollAnswer | undefined; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -29,7 +29,7 @@ export type PollAnswerListProps = { }; export const PollAnswerList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, onUpdateOwnAnswerClick, @@ -38,13 +38,8 @@ export const PollAnswerList = < const { poll } = usePollContext(); const { is_closed, ownAnswer } = useStateStore(poll.state, pollStateSelector); - const { - answers, - error, - hasNextPage, - loading, - loadMore, - } = usePollAnswerPagination(); + const { answers, error, hasNextPage, loading, loadMore } = + usePollAnswerPagination(); return (
diff --git a/src/components/Poll/PollActions/PollOptionsFullList.tsx b/src/components/Poll/PollActions/PollOptionsFullList.tsx index 505b56207..0fae91f8f 100644 --- a/src/components/Poll/PollActions/PollOptionsFullList.tsx +++ b/src/components/Poll/PollActions/PollOptionsFullList.tsx @@ -9,7 +9,7 @@ import type { DefaultStreamChatGenerics } from '../../../types'; type PollStateSelectorReturnValue = { name: string }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ name: nextValue.name }); @@ -19,7 +19,7 @@ export type FullPollOptionsListingProps = { }; export const PollOptionsFullList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, }: FullPollOptionsListingProps) => { diff --git a/src/components/Poll/PollActions/PollResults/PollOptionVotesList.tsx b/src/components/Poll/PollActions/PollResults/PollOptionVotesList.tsx index ffdeb740c..da98bbe6b 100644 --- a/src/components/Poll/PollActions/PollResults/PollOptionVotesList.tsx +++ b/src/components/Poll/PollActions/PollResults/PollOptionVotesList.tsx @@ -8,13 +8,13 @@ import type { PollOption, PollOptionVotesQueryParams } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../../types'; export type PollOptionVotesListingProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { option: PollOption; }; export const PollOptionVotesList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ option, }: PollOptionVotesListingProps) => { @@ -22,15 +22,10 @@ export const PollOptionVotesList = < () => ({ filter: { option_id: option.id } }), [option.id], ); - const { - error, - hasNextPage, - loading, - loadMore, - votes, - } = usePollOptionVotesPagination({ - paginationParams, - }); + const { error, hasNextPage, loading, loadMore, votes } = + usePollOptionVotesPagination({ + paginationParams, + }); return (
diff --git a/src/components/Poll/PollActions/PollResults/PollOptionWithLatestVotes.tsx b/src/components/Poll/PollActions/PollResults/PollOptionWithLatestVotes.tsx index 2eb867b8a..8b14459dc 100644 --- a/src/components/Poll/PollActions/PollResults/PollOptionWithLatestVotes.tsx +++ b/src/components/Poll/PollActions/PollResults/PollOptionWithLatestVotes.tsx @@ -7,17 +7,17 @@ import type { PollOption, PollState, PollVote } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../../types'; type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { latest_votes_by_option: Record[]> }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ latest_votes_by_option: nextValue.latest_votes_by_option }); export type PollOptionWithVotesProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { option: PollOption; countVotesPreview?: number; @@ -25,7 +25,7 @@ export type PollOptionWithVotesProps< }; export const PollOptionWithLatestVotes = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ countVotesPreview = 5, option, diff --git a/src/components/Poll/PollActions/PollResults/PollOptionWithVotesHeader.tsx b/src/components/Poll/PollActions/PollResults/PollOptionWithVotesHeader.tsx index 55febf958..8e5edb0f8 100644 --- a/src/components/Poll/PollActions/PollResults/PollOptionWithVotesHeader.tsx +++ b/src/components/Poll/PollActions/PollResults/PollOptionWithVotesHeader.tsx @@ -9,7 +9,7 @@ type PollStateSelectorReturnValue = { vote_counts_by_option: Record; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -22,7 +22,7 @@ export type PollResultOptionVoteCounterProps = { }; export const PollResultOptionVoteCounter = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ optionId, }: PollResultOptionVoteCounterProps) => { @@ -43,13 +43,13 @@ export const PollResultOptionVoteCounter = < }; export type PollOptionWithVotesHeaderProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { option: PollOption; }; export const PollOptionWithVotesHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ option, }: PollOptionWithVotesHeaderProps) => ( diff --git a/src/components/Poll/PollActions/PollResults/PollResults.tsx b/src/components/Poll/PollActions/PollResults/PollResults.tsx index c76b99871..3f2d64a3c 100644 --- a/src/components/Poll/PollActions/PollResults/PollResults.tsx +++ b/src/components/Poll/PollActions/PollResults/PollResults.tsx @@ -9,14 +9,14 @@ import type { PollOption, PollState } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../../types'; type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { name: string; options: PollOption[]; vote_counts_by_option: Record; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -30,7 +30,7 @@ export type PollResultsProps = { }; export const PollResults = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, }: PollResultsProps) => { diff --git a/src/components/Poll/PollActions/SuggestPollOptionForm.tsx b/src/components/Poll/PollActions/SuggestPollOptionForm.tsx index 3629450ff..f7baf8fcc 100644 --- a/src/components/Poll/PollActions/SuggestPollOptionForm.tsx +++ b/src/components/Poll/PollActions/SuggestPollOptionForm.tsx @@ -6,10 +6,10 @@ import type { PollOption, PollState } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types'; type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { options: PollOption[] }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ options: nextValue.options }); @@ -20,7 +20,7 @@ export type SuggestPollOptionFormProps = { }; export const SuggestPollOptionForm = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ close, messageId, diff --git a/src/components/Poll/PollContent.tsx b/src/components/Poll/PollContent.tsx index 96100a2fa..286ace28a 100644 --- a/src/components/Poll/PollContent.tsx +++ b/src/components/Poll/PollContent.tsx @@ -11,17 +11,15 @@ import type { DefaultStreamChatGenerics } from '../../types'; type PollStateSelectorPollContentReturnValue = { is_closed: boolean | undefined }; const pollStateSelectorPollContent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorPollContentReturnValue => ({ is_closed: nextValue.is_closed }); export const PollContent = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { - const { - PollHeader = DefaultPollHeader, - PollActions = DefaultPollActions, - } = useComponentContext(); + const { PollActions = DefaultPollActions, PollHeader = DefaultPollHeader } = + useComponentContext(); const { poll } = usePollContext(); const { is_closed } = useStateStore(poll.state, pollStateSelectorPollContent); diff --git a/src/components/Poll/PollCreationDialog/OptionFieldSet.tsx b/src/components/Poll/PollCreationDialog/OptionFieldSet.tsx index 0246c564c..8bc726569 100644 --- a/src/components/Poll/PollCreationDialog/OptionFieldSet.tsx +++ b/src/components/Poll/PollCreationDialog/OptionFieldSet.tsx @@ -7,7 +7,7 @@ import { DragAndDropContainer } from '../../DragAndDrop/DragAndDropContainer'; import { useTranslationContext } from '../../../context'; import type { OptionErrors, PollFormState, PollOptionFormData } from './types'; -const VALIDATION_ERRORS = ({ 'Option already exists': true } as const) as Record; +const VALIDATION_ERRORS = { 'Option already exists': true } as const as Record; export type OptionFieldSetProps = { errors: OptionErrors; diff --git a/src/components/Poll/PollCreationDialog/PollCreationDialog.tsx b/src/components/Poll/PollCreationDialog/PollCreationDialog.tsx index 3750b2bef..0d222db80 100644 --- a/src/components/Poll/PollCreationDialog/PollCreationDialog.tsx +++ b/src/components/Poll/PollCreationDialog/PollCreationDialog.tsx @@ -36,7 +36,7 @@ export const PollCreationDialog = ({ close }: PollCreationDialogProps) => { options: [{ id: nanoid(), text: '' }], user_id: client.user?.id, voting_visibility: 'public', - } as PollFormState), + }) as PollFormState, ); return ( diff --git a/src/components/Poll/PollHeader.tsx b/src/components/Poll/PollHeader.tsx index 673da1767..939cb23f3 100644 --- a/src/components/Poll/PollHeader.tsx +++ b/src/components/Poll/PollHeader.tsx @@ -5,7 +5,7 @@ import type { PollOption, PollState } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types'; type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { enforce_unique_vote: boolean; is_closed: boolean | undefined; @@ -14,7 +14,7 @@ type PollStateSelectorReturnValue< options: PollOption[]; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -26,7 +26,7 @@ const pollStateSelector = < }); export const PollHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { t } = useTranslationContext('PollHeader'); diff --git a/src/components/Poll/PollOptionList.tsx b/src/components/Poll/PollOptionList.tsx index 16c816420..3de14f549 100644 --- a/src/components/Poll/PollOptionList.tsx +++ b/src/components/Poll/PollOptionList.tsx @@ -7,11 +7,11 @@ import type { PollOption, PollState } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../types'; type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { options: PollOption[] }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ options: nextValue.options }); @@ -21,13 +21,12 @@ export type PollOptionListProps = { }; export const PollOptionList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ optionsDisplayCount, }: PollOptionListProps) => { - const { - PollOptionSelector = DefaultPollOptionSelector, - } = useComponentContext(); + const { PollOptionSelector = DefaultPollOptionSelector } = + useComponentContext(); const { poll } = usePollContext(); const { options } = useStateStore(poll.state, pollStateSelector); diff --git a/src/components/Poll/PollOptionSelector.tsx b/src/components/Poll/PollOptionSelector.tsx index 4b253ab9b..3f228cb0d 100644 --- a/src/components/Poll/PollOptionSelector.tsx +++ b/src/components/Poll/PollOptionSelector.tsx @@ -38,7 +38,7 @@ export const Checkmark = ({ checked }: CheckmarkProps) => ( ); type PollStateSelectorReturnValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { is_closed: boolean | undefined; latest_votes_by_option: Record[]>; @@ -48,7 +48,7 @@ type PollStateSelectorReturnValue< voting_visibility: VotingVisibility | undefined; }; const pollStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorReturnValue => ({ @@ -61,7 +61,7 @@ const pollStateSelector = < }); export type PollOptionSelectorProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { option: PollOption; displayAvatarCount?: number; @@ -69,16 +69,15 @@ export type PollOptionSelectorProps< }; export const PollOptionSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ displayAvatarCount, option, voteCountVerbose, }: PollOptionSelectorProps) => { const { t } = useTranslationContext(); - const { channelCapabilities = {} } = useChannelStateContext( - 'PollOptionsShortlist', - ); + const { channelCapabilities = {} } = + useChannelStateContext('PollOptionsShortlist'); const { message } = useMessageContext(); const { poll } = usePollContext(); @@ -134,7 +133,7 @@ export const PollOptionSelector = <
{voteCountVerbose ? t('{{count}} votes', { count: vote_counts_by_option[option.id] ?? 0 }) - : vote_counts_by_option[option.id] ?? 0} + : (vote_counts_by_option[option.id] ?? 0)}
{ }; type PollVoteProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { vote: PollVoteType; }; const PollVoteAuthor = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ vote, }: PollVoteProps) => { @@ -81,7 +81,7 @@ const PollVoteAuthor = < }; export const PollVote = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ vote, }: PollVoteProps) => ( @@ -92,13 +92,13 @@ export const PollVote = < ); export type PollVoteListingProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { votes: PollVoteType[]; }; export const PollVoteListing = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ votes, }: PollVoteListingProps) => ( diff --git a/src/components/Poll/QuotedPoll.tsx b/src/components/Poll/QuotedPoll.tsx index e995c6fa0..b77d05e45 100644 --- a/src/components/Poll/QuotedPoll.tsx +++ b/src/components/Poll/QuotedPoll.tsx @@ -7,7 +7,7 @@ import type { DefaultStreamChatGenerics } from '../../types'; type PollStateSelectorQuotedPollReturnValue = { is_closed: boolean | undefined; name: string }; const pollStateSelectorQuotedPoll = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( nextValue: PollState, ): PollStateSelectorQuotedPollReturnValue => ({ @@ -16,7 +16,7 @@ const pollStateSelectorQuotedPoll = < }); export const QuotedPoll = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const { poll } = usePollContext(); const { is_closed, name } = useStateStore(poll.state, pollStateSelectorQuotedPoll); diff --git a/src/components/Poll/__tests__/PollCreationDialog.test.js b/src/components/Poll/__tests__/PollCreationDialog.test.js index ac1c03dcd..d75c40432 100644 --- a/src/components/Poll/__tests__/PollCreationDialog.test.js +++ b/src/components/Poll/__tests__/PollCreationDialog.test.js @@ -166,7 +166,7 @@ describe('PollCreationDialog', () => { await fireEvent.blur(optionFields[1]); }); const optionErrors = screen.getAllByTestId(OPTION_INPUT_FIELD_ERROR_TEST_ID); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(optionErrors).toHaveLength(3); expect(optionErrors[1]).toHaveTextContent(DUPLICATE_OPTION_FIELD_ERROR_TEXT); expect(screen.getByText(CANCEL_BUTTON_TEXT)).toBeEnabled(); @@ -196,7 +196,7 @@ describe('PollCreationDialog', () => { expect(optionFields[1]).toHaveValue(text); expect(optionFields[2]).toHaveValue(''); const optionErrors = screen.getAllByTestId(OPTION_INPUT_FIELD_ERROR_TEST_ID); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(optionErrors).toHaveLength(3); expect(optionErrors[0]).not.toHaveTextContent(); expect(optionErrors[1]).not.toHaveTextContent(); @@ -221,7 +221,7 @@ describe('PollCreationDialog', () => { await fireEvent.change(optionFields[0], { target: { value: '' } }); }); optionFields = screen.getAllByPlaceholderText(OPTION_FIELD_PLACEHOLDER); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(optionFields).toHaveLength(1); expect(screen.getByText(CANCEL_BUTTON_TEXT)).toBeEnabled(); expect(screen.getByText(CREATE_BUTTON_TEXT)).toBeDisabled(); @@ -284,7 +284,7 @@ describe('PollCreationDialog', () => { }); const maxVoteCountErrors = screen.getAllByTestId(MAX_VOTE_COUT_INPUT_FIELD_ERROR_TEST_ID); - // eslint-disable-next-line jest-dom/prefer-in-document + expect(maxVoteCountErrors).toHaveLength(1); expect(maxVoteCountErrors[0]).toHaveTextContent(MAX_VOTE_COUNT_FIELD_ERROR_TEXT); expect(screen.getByPlaceholderText(MAX_VOTES_FIELD_PLACEHOLDER).value).toBe('1'); diff --git a/src/components/Poll/hooks/useManagePollVotesRealtime.ts b/src/components/Poll/hooks/useManagePollVotesRealtime.ts index 8682a1174..f2b102f6c 100644 --- a/src/components/Poll/hooks/useManagePollVotesRealtime.ts +++ b/src/components/Poll/hooks/useManagePollVotesRealtime.ts @@ -9,7 +9,7 @@ export function useManagePollVotesRealtime< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, T extends | PollVote - | PollAnswer = PollVote + | PollAnswer = PollVote, >( managedVoteType: 'answer' | 'vote', cursorPaginatorState?: CursorPaginatorStateStore, diff --git a/src/components/Poll/hooks/usePollAnswerPagination.ts b/src/components/Poll/hooks/usePollAnswerPagination.ts index 5c7a8b876..059382433 100644 --- a/src/components/Poll/hooks/usePollAnswerPagination.ts +++ b/src/components/Poll/hooks/usePollAnswerPagination.ts @@ -12,7 +12,7 @@ import type { PollAnswer, PollAnswersQueryParams, PollVote } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../../../types'; const paginationStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( state: CursorPaginatorState>, ): [Error | undefined, boolean, boolean] => [state.error, state.hasNextPage, state.loading]; @@ -22,7 +22,7 @@ type UsePollAnswerPaginationParams = { }; export const usePollAnswerPagination = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ paginationParams }: UsePollAnswerPaginationParams = {}) => { const { poll } = usePollContext(); diff --git a/src/components/Poll/hooks/usePollOptionVotesPagination.ts b/src/components/Poll/hooks/usePollOptionVotesPagination.ts index bde1627d0..d94b2f479 100644 --- a/src/components/Poll/hooks/usePollOptionVotesPagination.ts +++ b/src/components/Poll/hooks/usePollOptionVotesPagination.ts @@ -12,7 +12,7 @@ import type { DefaultStreamChatGenerics } from '../../../types'; import type { PollOptionVotesQueryParams, PollVote } from 'stream-chat'; const paginationStateSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( state: CursorPaginatorState>, ): [Error | undefined, boolean, boolean] => [state.error, state.hasNextPage, state.loading]; @@ -22,7 +22,7 @@ type UsePollOptionVotesPaginationParams = { }; export const usePollOptionVotesPagination = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ paginationParams, }: UsePollOptionVotesPaginationParams) => { diff --git a/src/components/ReactFileUtilities/FileIcon/mimeTypes.ts b/src/components/ReactFileUtilities/FileIcon/mimeTypes.ts index 765636fb3..2a9623ee5 100644 --- a/src/components/ReactFileUtilities/FileIcon/mimeTypes.ts +++ b/src/components/ReactFileUtilities/FileIcon/mimeTypes.ts @@ -1,11 +1,11 @@ export type GeneralType = 'audio/' | 'video/' | 'image/' | 'text/'; export type SupportedMimeType = - | typeof wordMimeTypes[number] - | typeof excelMimeTypes[number] - | typeof powerpointMimeTypes[number] - | typeof archiveFileTypes[number] - | typeof codeFileTypes[number]; + | (typeof wordMimeTypes)[number] + | (typeof excelMimeTypes)[number] + | (typeof powerpointMimeTypes)[number] + | (typeof archiveFileTypes)[number] + | (typeof codeFileTypes)[number]; export const wordMimeTypes = [ // Microsoft Word diff --git a/src/components/ReactFileUtilities/UploadButton.tsx b/src/components/ReactFileUtilities/UploadButton.tsx index 31821699b..a06e06f90 100644 --- a/src/components/ReactFileUtilities/UploadButton.tsx +++ b/src/components/ReactFileUtilities/UploadButton.tsx @@ -37,7 +37,7 @@ export type FileInputProps = UploadButtonProps; export const FileInput = UploadButton; export const UploadFileInput = forwardRef(function UploadFileInput< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( { className, @@ -47,14 +47,10 @@ export const UploadFileInput = forwardRef(function UploadFileInput< ref: React.ForwardedRef, ) { const { t } = useTranslationContext('UploadFileInput'); - const { acceptedFiles = [], multipleUploads } = useChannelStateContext( - 'UploadFileInput', - ); - const { - isUploadEnabled, - maxFilesLeft, - uploadNewFiles, - } = useMessageInputContext('UploadFileInput'); + const { acceptedFiles = [], multipleUploads } = + useChannelStateContext('UploadFileInput'); + const { isUploadEnabled, maxFilesLeft, uploadNewFiles } = + useMessageInputContext('UploadFileInput'); const id = useMemo(() => nanoid(), []); const onFileChange = useCallback( diff --git a/src/components/Reactions/ReactionSelector.tsx b/src/components/Reactions/ReactionSelector.tsx index ceeea4c4b..c618306b5 100644 --- a/src/components/Reactions/ReactionSelector.tsx +++ b/src/components/Reactions/ReactionSelector.tsx @@ -15,7 +15,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types'; import type { ReactionOptions } from './reactionOptions'; export type ReactionSelectorProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Custom UI component to display user avatar, defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx) */ Avatar?: React.ElementType; @@ -44,7 +44,7 @@ export type ReactionSelectorProps< }; const UnMemoizedReactionSelector = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ReactionSelectorProps, ) => { @@ -179,9 +179,8 @@ const UnMemoizedReactionSelector = < className={clsx( 'str-chat__message-reactions-list-item str-chat__message-reactions-option', { - 'str-chat__message-reactions-option-selected': iHaveReactedWithReaction( - reactionType, - ), + 'str-chat__message-reactions-option-selected': + iHaveReactedWithReaction(reactionType), }, )} data-testid='select-reaction-button' diff --git a/src/components/Reactions/ReactionSelectorWithButton.tsx b/src/components/Reactions/ReactionSelectorWithButton.tsx index 07ad6b4a6..e434de8af 100644 --- a/src/components/Reactions/ReactionSelectorWithButton.tsx +++ b/src/components/Reactions/ReactionSelectorWithButton.tsx @@ -15,7 +15,7 @@ type ReactionSelectorWithButtonProps = { * cluttering the parent component. */ export const ReactionSelectorWithButton = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ ReactionIcon, }: ReactionSelectorWithButtonProps) => { diff --git a/src/components/Reactions/ReactionsList.tsx b/src/components/Reactions/ReactionsList.tsx index c03025e44..dd469cbc3 100644 --- a/src/components/Reactions/ReactionsList.tsx +++ b/src/components/Reactions/ReactionsList.tsx @@ -12,7 +12,7 @@ import { MessageContextValue, useTranslationContext } from '../../context'; import { MAX_MESSAGE_REACTIONS_TO_FETCH } from '../Message/hooks'; export type ReactionsListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial< Pick, 'handleFetchReactions' | 'reactionDetailsSort'> > & { @@ -43,22 +43,21 @@ export type ReactionsListProps< }; const UnMemoizedReactionsList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ReactionsListProps, ) => { const { handleFetchReactions, + // eslint-disable-next-line @typescript-eslint/no-unused-vars reactionDetailsSort, reverse = false, sortReactionDetails, ...rest } = props; const { existingReactions, hasReactions, totalReactionCount } = useProcessReactions(rest); - const [ - selectedReactionType, - setSelectedReactionType, - ] = useState | null>(null); + const [selectedReactionType, setSelectedReactionType] = + useState | null>(null); const { t } = useTranslationContext('ReactionsList'); const handleReactionButtonClick = (reactionType: string) => { diff --git a/src/components/Reactions/ReactionsListModal.tsx b/src/components/Reactions/ReactionsListModal.tsx index bdeb91c7e..20ee26019 100644 --- a/src/components/Reactions/ReactionsListModal.tsx +++ b/src/components/Reactions/ReactionsListModal.tsx @@ -12,7 +12,7 @@ import { DefaultStreamChatGenerics } from '../../types/types'; import { ReactionSort } from 'stream-chat'; type ReactionsListModalProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ModalProps & Partial< Pick, 'handleFetchReactions' | 'reactionDetailsSort'> @@ -28,7 +28,7 @@ type ReactionsListModalProps< const defaultReactionDetailsSort = { created_at: -1 } as const; export function ReactionsListModal< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ handleFetchReactions, onSelectedReactionTypeChange, @@ -49,15 +49,13 @@ export function ReactionsListModal< const legacySortReactionDetails = propSortReactionDetails ?? contextSortReactionDetails; const reactionDetailsSort = propReactionDetailsSort ?? contextReactionDetailsSort ?? defaultReactionDetailsSort; - const { - isLoading: areReactionsLoading, - reactions: reactionDetails, - } = useFetchReactions({ - handleFetchReactions, - reactionType: selectedReactionType, - shouldFetch: modalProps.open, - sort: reactionDetailsSort, - }); + const { isLoading: areReactionsLoading, reactions: reactionDetails } = + useFetchReactions({ + handleFetchReactions, + reactionType: selectedReactionType, + shouldFetch: modalProps.open, + sort: reactionDetailsSort, + }); const reactionDetailsWithLegacyFallback = useMemo( () => diff --git a/src/components/Reactions/SimpleReactionsList.tsx b/src/components/Reactions/SimpleReactionsList.tsx index c64e1fb34..7dbf6f9d0 100644 --- a/src/components/Reactions/SimpleReactionsList.tsx +++ b/src/components/Reactions/SimpleReactionsList.tsx @@ -41,7 +41,7 @@ const WithTooltip = ({ }; export type SimpleReactionsListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Partial> & { /** An array of the own reaction objects to distinguish own reactions visually */ own_reactions?: ReactionResponse[]; @@ -59,15 +59,14 @@ export type SimpleReactionsListProps< }; const UnMemoizedSimpleReactionsList = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: SimpleReactionsListProps, ) => { const { handleReaction: propHandleReaction, ...rest } = props; - const { handleReaction: contextHandleReaction } = useMessageContext( - 'SimpleReactionsList', - ); + const { handleReaction: contextHandleReaction } = + useMessageContext('SimpleReactionsList'); const { existingReactions, hasReactions, totalReactionCount } = useProcessReactions(rest); diff --git a/src/components/Reactions/__tests__/ReactionsList.test.js b/src/components/Reactions/__tests__/ReactionsList.test.js index dfd7af012..b3e8bd006 100644 --- a/src/components/Reactions/__tests__/ReactionsList.test.js +++ b/src/components/Reactions/__tests__/ReactionsList.test.js @@ -1,4 +1,3 @@ -/* eslint-disable react/display-name */ import React from 'react'; import { render } from '@testing-library/react'; import '@testing-library/jest-dom'; diff --git a/src/components/Reactions/hooks/useFetchReactions.ts b/src/components/Reactions/hooks/useFetchReactions.ts index 0070ce91c..7e28f8567 100644 --- a/src/components/Reactions/hooks/useFetchReactions.ts +++ b/src/components/Reactions/hooks/useFetchReactions.ts @@ -5,7 +5,7 @@ import { DefaultStreamChatGenerics } from '../../../types/types'; import { ReactionType } from '../types'; export interface FetchReactionsOptions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > { reactionType: ReactionType; shouldFetch: boolean; @@ -14,11 +14,10 @@ export interface FetchReactionsOptions< } export function useFetchReactions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(options: FetchReactionsOptions) { - const { - handleFetchReactions: contextHandleFetchReactions, - } = useMessageContext('useFetchReactions'); + const { handleFetchReactions: contextHandleFetchReactions } = + useMessageContext('useFetchReactions'); const [reactions, setReactions] = useState[]>([]); const { handleFetchReactions: propHandleFetchReactions, diff --git a/src/components/Reactions/hooks/useProcessReactions.tsx b/src/components/Reactions/hooks/useProcessReactions.tsx index cded26fb5..9543ea908 100644 --- a/src/components/Reactions/hooks/useProcessReactions.tsx +++ b/src/components/Reactions/hooks/useProcessReactions.tsx @@ -27,7 +27,7 @@ export const defaultReactionsSort: ReactionsComparator = (a, b) => { }; export const useProcessReactions = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( params: UseProcessReactionsParams, ) => { @@ -38,12 +38,10 @@ export const useProcessReactions = < reactions: propReactions, sortReactions: propSortReactions, } = params; - const { message, sortReactions: contextSortReactions } = useMessageContext( - 'useProcessReactions', - ); - const { - reactionOptions: contextReactionOptions = defaultReactionOptions, - } = useComponentContext('useProcessReactions'); + const { message, sortReactions: contextSortReactions } = + useMessageContext('useProcessReactions'); + const { reactionOptions: contextReactionOptions = defaultReactionOptions } = + useComponentContext('useProcessReactions'); const reactionOptions = propReactionOptions ?? contextReactionOptions; const sortReactions = propSortReactions ?? contextSortReactions ?? defaultReactionsSort; diff --git a/src/components/Reactions/reactionOptions.tsx b/src/components/Reactions/reactionOptions.tsx index a0dc77735..37b2f02b3 100644 --- a/src/components/Reactions/reactionOptions.tsx +++ b/src/components/Reactions/reactionOptions.tsx @@ -1,5 +1,5 @@ /* eslint-disable sort-keys */ -/* eslint-disable react/display-name */ + import React from 'react'; import { StreamEmoji } from './StreamEmoji'; diff --git a/src/components/Reactions/types.ts b/src/components/Reactions/types.ts index 030bcc259..9e9d432e3 100644 --- a/src/components/Reactions/types.ts +++ b/src/components/Reactions/types.ts @@ -16,9 +16,9 @@ export interface ReactionSummary { export type ReactionsComparator = (a: ReactionSummary, b: ReactionSummary) => number; export type ReactionDetailsComparator< - StreamChatGenerics extends ExtendableGenerics = DefaultGenerics + StreamChatGenerics extends ExtendableGenerics = DefaultGenerics, > = (a: ReactionResponse, b: ReactionResponse) => number; export type ReactionType< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = ReactionResponse['type']; diff --git a/src/components/Thread/Thread.tsx b/src/components/Thread/Thread.tsx index 3f1bcb100..7902b5d74 100644 --- a/src/components/Thread/Thread.tsx +++ b/src/components/Thread/Thread.tsx @@ -29,7 +29,7 @@ import type { ThreadState } from 'stream-chat'; export type ThreadProps< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = { /** Additional props for `MessageInput` component: [available props](https://getstream.io/chat/docs/sdk/react/message-input-components/message_input/#props) */ additionalMessageInputProps?: MessageInputProps; @@ -58,7 +58,7 @@ export type ThreadProps< */ export const Thread = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: ThreadProps, ) => { @@ -83,7 +83,7 @@ const selector = (nextValue: ThreadState) => ({ const ThreadInner = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( props: ThreadProps & { key: string }, ) => { @@ -114,10 +114,10 @@ const ThreadInner = < const { closeThread, loadMoreThread } = useChannelActionContext('Thread'); const { customClasses } = useChatContext('Thread'); const { - ThreadInput: ContextInput, Message: ContextMessage, ThreadHead = DefaultThreadHead, ThreadHeader = DefaultThreadHeader, + ThreadInput: ContextInput, VirtualMessage, } = useComponentContext('Thread'); @@ -135,7 +135,6 @@ const ThreadInner = < // FIXME: integrators can customize channel query options but cannot customize channel.getReplies() options loadMoreThread(); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [thread, loadMoreThread]); const threadProps: Pick< diff --git a/src/components/Thread/ThreadHead.tsx b/src/components/Thread/ThreadHead.tsx index edb14884a..2ed96f30a 100644 --- a/src/components/Thread/ThreadHead.tsx +++ b/src/components/Thread/ThreadHead.tsx @@ -8,13 +8,12 @@ import { useComponentContext } from '../../context'; import type { DefaultStreamChatGenerics } from '../../types/types'; export const ThreadHead = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: MessageProps, ) => { - const { ThreadStart = DefaultThreadStart } = useComponentContext( - 'ThreadHead', - ); + const { ThreadStart = DefaultThreadStart } = + useComponentContext('ThreadHead'); return (
diff --git a/src/components/Thread/ThreadHeader.tsx b/src/components/Thread/ThreadHeader.tsx index 3afa67487..270330561 100644 --- a/src/components/Thread/ThreadHeader.tsx +++ b/src/components/Thread/ThreadHeader.tsx @@ -12,7 +12,7 @@ import { useTranslationContext } from '../../context/TranslationContext'; import type { DefaultStreamChatGenerics } from '../../types/types'; export type ThreadHeaderProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** Callback for closing the thread */ closeThread: (event?: React.BaseSyntheticEvent) => void; @@ -21,7 +21,7 @@ export type ThreadHeaderProps< }; export const ThreadHeader = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: ThreadHeaderProps & Pick, 'overrideImage' | 'overrideTitle'>, diff --git a/src/components/Thread/__tests__/Thread.test.js b/src/components/Thread/__tests__/Thread.test.js index 12306a576..731401681 100644 --- a/src/components/Thread/__tests__/Thread.test.js +++ b/src/components/Thread/__tests__/Thread.test.js @@ -71,11 +71,11 @@ const i18nMock = jest.fn((key, props) => { }); const renderComponent = ({ - chatClient, - threadProps = {}, - channelStateOverrides = {}, channelActionOverrides = {}, + channelStateOverrides = {}, + chatClient, componentOverrides = {}, + threadProps = {}, }) => render( diff --git a/src/components/Threads/ThreadList/ThreadList.tsx b/src/components/Threads/ThreadList/ThreadList.tsx index 0f4239c9e..3ad8458b9 100644 --- a/src/components/Threads/ThreadList/ThreadList.tsx +++ b/src/components/Threads/ThreadList/ThreadList.tsx @@ -44,8 +44,8 @@ export const useThreadList = () => { export const ThreadList = ({ virtuosoProps }: ThreadListProps) => { const { client } = useChatContext(); const { - ThreadListItem = DefaultThreadListItem, ThreadListEmptyPlaceholder = DefaultThreadListEmptyPlaceholder, + ThreadListItem = DefaultThreadListItem, ThreadListLoadingIndicator = DefaultThreadListLoadingIndicator, ThreadListUnseenThreadsBanner = DefaultThreadListUnseenThreadsBanner, } = useComponentContext(); diff --git a/src/components/Threads/icons.tsx b/src/components/Threads/icons.tsx index d67e41627..9c4f82f1a 100644 --- a/src/components/Threads/icons.tsx +++ b/src/components/Threads/icons.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/display-name */ import React from 'react'; import { ComponentPropsWithoutRef } from 'react'; diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index ae01ca588..a19039c09 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -21,8 +21,8 @@ export type PopperTooltipProps = React.PropsWithChildren< export const PopperTooltip = ({ children, offset = [0, 10], - referenceElement, placement = 'top', + referenceElement, visible = false, }: PopperTooltipProps) => { const [popperElement, setPopperElement] = useState(null); diff --git a/src/components/TypingIndicator/TypingIndicator.tsx b/src/components/TypingIndicator/TypingIndicator.tsx index 2b1e81744..db40e44f4 100644 --- a/src/components/TypingIndicator/TypingIndicator.tsx +++ b/src/components/TypingIndicator/TypingIndicator.tsx @@ -42,7 +42,7 @@ const useJoinTypingUsers = (names: string[]) => { * TypingIndicator lists users currently typing, it needs to be a child of Channel component */ const UnMemoizedTypingIndicator = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: TypingIndicatorProps, ) => { diff --git a/src/components/UserItem/__tests__/UserItem.test.js b/src/components/UserItem/__tests__/UserItem.test.js index 1e6461f27..671856f00 100644 --- a/src/components/UserItem/__tests__/UserItem.test.js +++ b/src/components/UserItem/__tests__/UserItem.test.js @@ -8,7 +8,7 @@ expect.extend(toHaveNoViolations); import { UserItem } from '../UserItem'; -afterEach(cleanup); // eslint-disable-line +afterEach(cleanup); describe('UserItem', () => { it('should render component with default props', () => { diff --git a/src/components/Window/Window.tsx b/src/components/Window/Window.tsx index 9485eb2c8..a39e54fbf 100644 --- a/src/components/Window/Window.tsx +++ b/src/components/Window/Window.tsx @@ -6,14 +6,14 @@ import { StreamMessage, useChannelStateContext } from '../../context/ChannelStat import type { DefaultStreamChatGenerics } from '../../types/types'; export type WindowProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** optional prop to force addition of class str-chat__main-panel---with-thread-opn to the Window root element */ thread?: StreamMessage; }; const UnMemoizedWindow = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( props: PropsWithChildren>, ) => { diff --git a/src/context/ChannelActionContext.tsx b/src/context/ChannelActionContext.tsx index 36acea39f..ca9a346f6 100644 --- a/src/context/ChannelActionContext.tsx +++ b/src/context/ChannelActionContext.tsx @@ -34,11 +34,11 @@ export type MarkReadWrapperOptions = { }; export type MessageAttachments< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Array>; export type MessageToSend< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { attachments?: MessageAttachments; error?: ErrorFromResponse; @@ -52,11 +52,11 @@ export type MessageToSend< }; export type RetrySendMessage< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = (message: StreamMessage) => Promise; export type ChannelActionContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { addNotification: (text: string, type: 'success' | 'error') => void; closeThread: (event?: React.BaseSyntheticEvent) => void; @@ -103,20 +103,20 @@ export const ChannelActionContext = React.createContext({ children, value, }: PropsWithChildren<{ value: ChannelActionContextValue; }>) => ( - + {children} ); export const useChannelActionContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( componentName?: string, ) => { @@ -130,7 +130,7 @@ export const useChannelActionContext = < return {} as ChannelActionContextValue; } - return (contextValue as unknown) as ChannelActionContextValue; + return contextValue as unknown as ChannelActionContextValue; }; /** @@ -140,7 +140,7 @@ export const useChannelActionContext = < */ export const withChannelActionContext = < P extends UnknownType, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( Component: React.ComponentType

, ) => { diff --git a/src/context/ChannelListContext.tsx b/src/context/ChannelListContext.tsx index fb8e96f00..dd9adf46d 100644 --- a/src/context/ChannelListContext.tsx +++ b/src/context/ChannelListContext.tsx @@ -11,7 +11,7 @@ import type { Channel } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../types/types'; export type ChannelListContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** * State representing the array of loaded channels. @@ -30,20 +30,20 @@ export const ChannelListContext = createContext({ children, value, }: PropsWithChildren<{ value: ChannelListContextValue; }>) => ( - + {children} ); export const useChannelListContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( componentName?: string, ) => { @@ -57,5 +57,5 @@ export const useChannelListContext = < return {} as ChannelListContextValue; } - return (contextValue as unknown) as ChannelListContextValue; + return contextValue as unknown as ChannelListContextValue; }; diff --git a/src/context/ChannelStateContext.tsx b/src/context/ChannelStateContext.tsx index fb12ffdc0..ad7c69701 100644 --- a/src/context/ChannelStateContext.tsx +++ b/src/context/ChannelStateContext.tsx @@ -25,13 +25,13 @@ export type ChannelNotifications = Array<{ }>; export type StreamMessage< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = | ReturnType['formatMessage']> | MessageResponse; export type ChannelState< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { suppressAutoscroll: boolean; error?: Error | null; @@ -57,7 +57,7 @@ export type ChannelState< }; export type ChannelStateContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit, 'typing'> & { channel: Channel; channelCapabilities: Record; @@ -85,20 +85,20 @@ export const ChannelStateContext = React.createContext({ children, value, }: PropsWithChildren<{ value: ChannelStateContextValue; }>) => ( - + {children} ); export const useChannelStateContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( componentName?: string, ) => { @@ -112,7 +112,7 @@ export const useChannelStateContext = < return {} as ChannelStateContextValue; } - return (contextValue as unknown) as ChannelStateContextValue; + return contextValue as unknown as ChannelStateContextValue; }; /** @@ -122,7 +122,7 @@ export const useChannelStateContext = < */ export const withChannelStateContext = < P extends UnknownType, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( Component: React.ComponentType

, ) => { diff --git a/src/context/ChatContext.tsx b/src/context/ChatContext.tsx index 514942a5d..2f6963f24 100644 --- a/src/context/ChatContext.tsx +++ b/src/context/ChatContext.tsx @@ -24,7 +24,7 @@ export type CustomClasses = Partial>; type ChannelCID = string; // e.g.: "messaging:general" export type ChatContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** * Indicates, whether a channels query has been triggered within ChannelList by its channels pagination controller. @@ -62,20 +62,20 @@ export type ChatContextValue< export const ChatContext = React.createContext(undefined); export const ChatProvider = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, value, }: PropsWithChildren<{ value: ChatContextValue; }>) => ( - + {children} ); export const useChatContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( componentName?: string, ) => { @@ -89,7 +89,7 @@ export const useChatContext = < return {} as ChatContextValue; } - return (contextValue as unknown) as ChatContextValue; + return contextValue as unknown as ChatContextValue; }; /** @@ -99,7 +99,7 @@ export const useChatContext = < */ export const withChatContext = < P extends UnknownType, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( Component: React.ComponentType

, ) => { diff --git a/src/context/ComponentContext.tsx b/src/context/ComponentContext.tsx index 51b15fe1c..3bdcad390 100644 --- a/src/context/ComponentContext.tsx +++ b/src/context/ComponentContext.tsx @@ -60,7 +60,7 @@ import type { StopAIGenerationButtonProps } from '../components/MessageInput/Sto export type ComponentContextValue< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = { /** Custom UI component to display a message attachment, defaults to and accepts same props as: [Attachment](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/Attachment.tsx) */ Attachment?: React.ComponentType>; @@ -203,28 +203,28 @@ export const ComponentContext = React.createContext({}); export const ComponentProvider = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >({ children, value, }: PropsWithChildren<{ value: Partial>; }>) => ( - + {children} ); export const useComponentContext = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( /** * @deprecated */ - // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars _componentName?: string, -) => (useContext(ComponentContext) as unknown) as ComponentContextValue; +) => useContext(ComponentContext) as unknown as ComponentContextValue; /** * Typescript currently does not support partial inference, so if ComponentContext @@ -234,7 +234,7 @@ export const useComponentContext = < export const withComponentContext = < P extends UnknownType, StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( Component: React.ComponentType

, ) => { diff --git a/src/context/MessageBounceContext.tsx b/src/context/MessageBounceContext.tsx index 7bd50e32e..e4ac68f62 100644 --- a/src/context/MessageBounceContext.tsx +++ b/src/context/MessageBounceContext.tsx @@ -6,7 +6,7 @@ import { useChannelActionContext } from './ChannelActionContext'; import { isMessageBounced } from '../components'; export interface MessageBounceContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > { handleDelete: ReactEventHandler; handleEdit: ReactEventHandler; @@ -17,7 +17,7 @@ export interface MessageBounceContextValue< const MessageBounceContext = createContext(undefined); export function useMessageBounceContext< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >(componentName?: string) { const contextValue = useContext(MessageBounceContext); @@ -33,7 +33,7 @@ export function useMessageBounceContext< } export function MessageBounceProvider< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children }: PropsWithChildrenOnly) { const { handleRetry: doHandleRetry, diff --git a/src/context/MessageContext.tsx b/src/context/MessageContext.tsx index 74e6d7a77..f0db2eea7 100644 --- a/src/context/MessageContext.tsx +++ b/src/context/MessageContext.tsx @@ -21,7 +21,7 @@ import type { RenderTextOptions } from '../components/Message/renderText'; import type { DefaultStreamChatGenerics, UnknownType } from '../types/types'; export type CustomMessageActions< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { [key: string]: ( message: StreamMessage, @@ -30,7 +30,7 @@ export type CustomMessageActions< }; export type MessageContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { /** If actions such as edit, delete, flag, mute are enabled on Message */ actionsEnabled: boolean; @@ -143,22 +143,22 @@ export type MessageContextValue< export const MessageContext = React.createContext(undefined); export const MessageProvider = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, value, }: PropsWithChildren<{ value: MessageContextValue; }>) => ( - + {children} ); export const useMessageContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( - // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars _componentName?: string, ) => { const contextValue = useContext(MessageContext); @@ -167,7 +167,7 @@ export const useMessageContext = < return {} as MessageContextValue; } - return (contextValue as unknown) as MessageContextValue; + return contextValue as unknown as MessageContextValue; }; /** @@ -177,7 +177,7 @@ export const useMessageContext = < */ export const withMessageContext = < P extends UnknownType, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( Component: React.ComponentType

, ) => { diff --git a/src/context/MessageInputContext.tsx b/src/context/MessageInputContext.tsx index 0869fd992..95228c9ec 100644 --- a/src/context/MessageInputContext.tsx +++ b/src/context/MessageInputContext.tsx @@ -13,7 +13,7 @@ import type { CustomTrigger, DefaultStreamChatGenerics } from '../types/types'; export type MessageInputContextValue< StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, > = MessageInputState & MessageInputHookProps & Omit, 'Input'> & @@ -28,7 +28,7 @@ export const MessageInputContext = createContext< export const MessageInputContextProvider = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >({ children, value, @@ -42,7 +42,7 @@ export const MessageInputContextProvider = < export const useMessageInputContext = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, - V extends CustomTrigger = CustomTrigger + V extends CustomTrigger = CustomTrigger, >( componentName?: string, ) => { diff --git a/src/context/PollContext.tsx b/src/context/PollContext.tsx index 229287611..9d67d19f0 100644 --- a/src/context/PollContext.tsx +++ b/src/context/PollContext.tsx @@ -3,7 +3,7 @@ import type { Poll } from 'stream-chat'; import type { DefaultStreamChatGenerics } from '../types'; export type PollContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { poll: Poll; }; @@ -11,7 +11,7 @@ export type PollContextValue< export const PollContext = React.createContext(undefined); export const PollProvider = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, poll, @@ -19,14 +19,14 @@ export const PollProvider = < poll: Poll; }>) => poll ? ( - + {children} ) : null; export const usePollContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >() => { const contextValue = useContext(PollContext); - return (contextValue as unknown) as PollContextValue; + return contextValue as unknown as PollContextValue; }; diff --git a/src/context/TypingContext.tsx b/src/context/TypingContext.tsx index 73d7b56fc..4028666cf 100644 --- a/src/context/TypingContext.tsx +++ b/src/context/TypingContext.tsx @@ -5,7 +5,7 @@ import type { ChannelState as StreamChannelState } from 'stream-chat'; import type { DefaultStreamChatGenerics, UnknownType } from '../types/types'; export type TypingContextValue< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { typing?: StreamChannelState['typing']; }; @@ -13,20 +13,20 @@ export type TypingContextValue< export const TypingContext = React.createContext(undefined); export const TypingProvider = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ children, value, }: PropsWithChildren<{ value: TypingContextValue; }>) => ( - + {children} ); export const useTypingContext = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( componentName?: string, ) => { @@ -50,7 +50,7 @@ export const useTypingContext = < */ export const withTypingContext = < P extends UnknownType, - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( Component: React.ComponentType

, ) => { diff --git a/src/experimental/MessageActions/MessageActions.tsx b/src/experimental/MessageActions/MessageActions.tsx index 47da9e86a..67cdeab64 100644 --- a/src/experimental/MessageActions/MessageActions.tsx +++ b/src/experimental/MessageActions/MessageActions.tsx @@ -1,4 +1,3 @@ -/* eslint-disable sort-keys */ import clsx from 'clsx'; import React, { PropsWithChildren, useState } from 'react'; @@ -14,10 +13,7 @@ import { defaultMessageActionSet } from './defaults'; export type MessageActionSetItem = { Component: React.ComponentType; placement: 'quick' | 'dropdown'; - type: - | keyof typeof MESSAGE_ACTIONS - // eslint-disable-next-line @typescript-eslint/ban-types - | (string & {}); + type: keyof typeof MESSAGE_ACTIONS | (string & {}); }; export type MessageActionsProps = { diff --git a/src/experimental/MessageActions/hooks/useBaseMessageActionSetFilter.ts b/src/experimental/MessageActions/hooks/useBaseMessageActionSetFilter.ts index 01fd92702..dbbd2df26 100644 --- a/src/experimental/MessageActions/hooks/useBaseMessageActionSetFilter.ts +++ b/src/experimental/MessageActions/hooks/useBaseMessageActionSetFilter.ts @@ -16,16 +16,8 @@ export const useBaseMessageActionSetFilter = ( disable = false, ) => { const { initialMessage: isInitialMessage, message } = useMessageContext(); - const { - canDelete, - canEdit, - canFlag, - canMarkUnread, - canMute, - canQuote, - canReact, - canReply, - } = useUserRole(message); + const { canDelete, canEdit, canFlag, canMarkUnread, canMute, canQuote, canReact, canReply } = + useUserRole(message); const isMessageThreadReply = typeof message.parent_id === 'string'; return useMemo(() => { diff --git a/src/i18n/__tests__/Streami18n.test.js b/src/i18n/__tests__/Streami18n.test.js index 99db652bd..11a76cca0 100644 --- a/src/i18n/__tests__/Streami18n.test.js +++ b/src/i18n/__tests__/Streami18n.test.js @@ -9,9 +9,8 @@ import localeData from 'dayjs/plugin/localeData'; Dayjs.extend(localeData); const customDayjsLocaleConfig = { - months: 'januar_februar_mars_apríl_mai_juni_juli_august_september_oktober_november_desember'.split( - '_', - ), + months: + 'januar_februar_mars_apríl_mai_juni_juli_august_september_oktober_november_desember'.split('_'), monthsShort: 'jan_feb_mar_apr_mai_jun_jul_aug_sep_okt_nov_des'.split('_'), weekdays: 'sunnudagur_mánadagur_týsdagur_mikudagur_hósdagur_fríggjadagur_leygardagur'.split('_'), weekdaysShort: 'sun_mán_týs_mik_hós_frí_ley'.split('_'), diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index 978fd09cd..5dc25177e 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -91,40 +91,42 @@ export function getDateString({ } export const predefinedFormatters: PredefinedFormatters = { - timestampFormatter: (streamI18n) => ( - value, - _, - { - calendarFormats, - ...options - }: Pick & { - calendarFormats?: Record | string; - }, - ) => { - let parsedCalendarFormats; - try { - if (!options.calendar) { - parsedCalendarFormats = {}; - } else if (typeof calendarFormats === 'string') { - parsedCalendarFormats = JSON.parse(calendarFormats); - } else if (typeof calendarFormats === 'object') { - parsedCalendarFormats = calendarFormats; + timestampFormatter: + (streamI18n) => + ( + value, + _, + { + calendarFormats, + ...options + }: Pick & { + calendarFormats?: Record | string; + }, + ) => { + let parsedCalendarFormats; + try { + if (!options.calendar) { + parsedCalendarFormats = {}; + } else if (typeof calendarFormats === 'string') { + parsedCalendarFormats = JSON.parse(calendarFormats); + } else if (typeof calendarFormats === 'object') { + parsedCalendarFormats = calendarFormats; + } + } catch (e) { + console.error('[TIMESTAMP FORMATTER]', e); } - } catch (e) { - console.error('[TIMESTAMP FORMATTER]', e); - } - const result = getDateString({ - ...options, - calendarFormats: parsedCalendarFormats, - messageCreatedAt: value, - tDateTimeParser: streamI18n.tDateTimeParser, - }); - if (!result || typeof result === 'number') { - return JSON.stringify(value); - } - return result; - }, + const result = getDateString({ + ...options, + calendarFormats: parsedCalendarFormats, + messageCreatedAt: value, + tDateTimeParser: streamI18n.tDateTimeParser, + }); + if (!result || typeof result === 'number') { + return JSON.stringify(value); + } + return result; + }, }; export const defaultTranslatorFunction: TFunction = (key: tResult) => key; diff --git a/src/mock-builders/browser/AudioContext.js b/src/mock-builders/browser/AudioContext.js index ae1b187ca..7ec5d4e5b 100644 --- a/src/mock-builders/browser/AudioContext.js +++ b/src/mock-builders/browser/AudioContext.js @@ -4,6 +4,7 @@ class Connectable { } export class AudioContextMock { + // eslint-disable-next-line @typescript-eslint/no-empty-function constructor() {} createAnalyser = jest.fn(() => new Connectable()); diff --git a/src/mock-builders/generator/attachment.js b/src/mock-builders/generator/attachment.js index 21611da0f..5d336dca3 100644 --- a/src/mock-builders/generator/attachment.js +++ b/src/mock-builders/generator/attachment.js @@ -45,7 +45,7 @@ export const generateLocalImageUploadAttachmentData = (overrides, attachmentData ...generateLocalFileUploadAttachmentData().localMetadata, previewUri: 'image-preview-uri', ...overrides, - // eslint-disable-next-line sort-keys + file: generateImageFile(overrides?.file ?? {}), }, type: 'image', @@ -96,106 +96,31 @@ export const generateVoiceRecordingAttachment = (a) => ({ title: 'audio_recording_Mon Feb 05 16:21:34 PST 2024.aac', type: 'voiceRecording', waveform_data: [ - 0.3139950633049011, - 0.24018539488315582, - 0.27728691697120667, - 0.2946733236312866, - 0.18365363776683807, - 0.4870237708091736, - 0.5902017951011658, - 0.43630164861679077, - 0.4746025502681732, - 0.2663217782974243, - 0.7870231866836548, - 0.6237155795097351, - 0.36374375224113464, - 0.2663217782974243, - 0.6613287329673767, - 0.8278987407684326, - 0.1516059935092926, - 0.37934044003486633, - 0.5281689167022705, - 0.47579875588417053, - 0.48600485920906067, - 0.6229274868965149, - 0.4964161813259125, - 0.4377916753292084, - 0.5569855570793152, - 0.5540405511856079, - 0.4095909595489502, - 0.747698187828064, - 0.8532787561416626, - 0.6344320178031921, - 0.5756412744522095, - 0.529367208480835, - 0.8330334424972534, - 0.8681668043136597, - 0.6670080423355103, - 0.7732296586036682, - 0.7542996406555176, - 0.6666833758354187, - 0.4648399353027344, - 0.4689463675022125, - 0.515621542930603, - 0.7782987952232361, - 0.6618493795394897, - 0.6291788220405579, - 0.7447969317436218, - 0.7329777479171753, - 0.7156173586845398, - 0.8810608386993408, - 0.07107513397932053, - 0.07438423484563828, - 0.08600494265556335, - 0.1429901123046875, - 0.059566497802734375, - 0.032375335693359375, - 0.14445610344409943, - 0.9534039497375488, - 0.8612125515937805, - 0.4861070513725281, - 0.5025619864463806, - 0.3678266108036041, - 0.5829864144325256, - 0.6209651231765747, - 0.6576777696609497, - 0.6046710014343262, - 0.08803673088550568, - 0.492523193359375, - 0.1947961449623108, - 0.09975242614746094, - 0.03940269351005554, - 0.372602641582489, - 0.4425804913043976, - 0.6269233226776123, - 0.7768490314483643, - 0.41689178347587585, - 0.18697471916675568, - 0.11767738312482834, - 0.049776915460824966, - 0.1377594769001007, - 0.08291183412075043, - 0.05717025697231293, - 0.01960846036672592, - 0.04073379561305046, - 0.2909153699874878, - 0.2615521252155304, - 0.1473514586687088, - 0.8678494095802307, - 0.9467474222183228, - 0.7687522768974304, - 0.8469597101211548, - 0.6312726736068726, - 0.5455475449562073, - 0.8171653747558594, - 0.7835009694099426, - 0.6183612942695618, - 0.7298175692558289, - 0.6681936383247375, - 0.815593957901001, - 0.7774609327316284, - 0.8033567070960999, - 0.8980446457862854, + 0.3139950633049011, 0.24018539488315582, 0.27728691697120667, 0.2946733236312866, + 0.18365363776683807, 0.4870237708091736, 0.5902017951011658, 0.43630164861679077, + 0.4746025502681732, 0.2663217782974243, 0.7870231866836548, 0.6237155795097351, + 0.36374375224113464, 0.2663217782974243, 0.6613287329673767, 0.8278987407684326, + 0.1516059935092926, 0.37934044003486633, 0.5281689167022705, 0.47579875588417053, + 0.48600485920906067, 0.6229274868965149, 0.4964161813259125, 0.4377916753292084, + 0.5569855570793152, 0.5540405511856079, 0.4095909595489502, 0.747698187828064, + 0.8532787561416626, 0.6344320178031921, 0.5756412744522095, 0.529367208480835, + 0.8330334424972534, 0.8681668043136597, 0.6670080423355103, 0.7732296586036682, + 0.7542996406555176, 0.6666833758354187, 0.4648399353027344, 0.4689463675022125, + 0.515621542930603, 0.7782987952232361, 0.6618493795394897, 0.6291788220405579, + 0.7447969317436218, 0.7329777479171753, 0.7156173586845398, 0.8810608386993408, + 0.07107513397932053, 0.07438423484563828, 0.08600494265556335, 0.1429901123046875, + 0.059566497802734375, 0.032375335693359375, 0.14445610344409943, 0.9534039497375488, + 0.8612125515937805, 0.4861070513725281, 0.5025619864463806, 0.3678266108036041, + 0.5829864144325256, 0.6209651231765747, 0.6576777696609497, 0.6046710014343262, + 0.08803673088550568, 0.492523193359375, 0.1947961449623108, 0.09975242614746094, + 0.03940269351005554, 0.372602641582489, 0.4425804913043976, 0.6269233226776123, + 0.7768490314483643, 0.41689178347587585, 0.18697471916675568, 0.11767738312482834, + 0.049776915460824966, 0.1377594769001007, 0.08291183412075043, 0.05717025697231293, + 0.01960846036672592, 0.04073379561305046, 0.2909153699874878, 0.2615521252155304, + 0.1473514586687088, 0.8678494095802307, 0.9467474222183228, 0.7687522768974304, + 0.8469597101211548, 0.6312726736068726, 0.5455475449562073, 0.8171653747558594, + 0.7835009694099426, 0.6183612942695618, 0.7298175692558289, 0.6681936383247375, + 0.815593957901001, 0.7774609327316284, 0.8033567070960999, 0.8980446457862854, ], ...a, }); @@ -251,56 +176,49 @@ export const generateGiphyAttachment = (a) => ({ frames: '', height: '200', size: '445149', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200.gif&ct=g', width: '200', }, fixed_height_downsampled: { frames: '', height: '200', size: '148168', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200_d.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200_d.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200_d.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200_d.gif&ct=g', width: '200', }, fixed_height_still: { frames: '', height: '200', size: '23240', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200_s.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200_s.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200_s.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200_s.gif&ct=g', width: '200', }, fixed_width: { frames: '', height: '200', size: '445149', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w.gif&ct=g', width: '200', }, fixed_width_downsampled: { frames: '', height: '200', size: '148168', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w_d.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w_d.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w_d.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w_d.gif&ct=g', width: '200', }, fixed_width_still: { frames: '', height: '200', size: '23240', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w_s.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w_s.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/200w_s.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=200w_s.gif&ct=g', width: '200', }, original: { frames: '20', height: '400', size: '1308571', - url: - 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/giphy.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=giphy.gif&ct=g', + url: 'https://media2.giphy.com/media/j5L4RHeV8Q5tmepRVb/giphy.gif?cid=c4b03675kgziudvt7s9990i28hp8zpffi4oyem1snvl7sfvl&rid=giphy.gif&ct=g', width: '400', }, }, diff --git a/src/mock-builders/generator/channel.js b/src/mock-builders/generator/channel.js index e19d01a5d..035c768e7 100644 --- a/src/mock-builders/generator/channel.js +++ b/src/mock-builders/generator/channel.js @@ -4,6 +4,7 @@ export const generateChannel = (options = { channel: {} }) => { const { channel: optionsChannel, config, ...optionsBesidesChannel } = options; const id = optionsChannel?.id ?? nanoid(); const type = optionsChannel?.type ?? 'messaging'; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { id: _, type: __, ...restOptionsChannel } = optionsChannel ?? {}; return { @@ -11,10 +12,10 @@ export const generateChannel = (options = { channel: {} }) => { messages: [], pinnedMessages: [], ...optionsBesidesChannel, - // eslint-disable-next-line sort-keys + channel: { cid: `${type}:${id}`, - // eslint-disable-next-line sort-keys + config: { automod: 'disabled', automod_behavior: 'flag', diff --git a/src/mock-builders/index.js b/src/mock-builders/index.js index ada1049fc..bad58123f 100644 --- a/src/mock-builders/index.js +++ b/src/mock-builders/index.js @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ /* eslint-disable no-underscore-dangle */ import { StreamChat } from 'stream-chat'; import { nanoid } from 'nanoid'; diff --git a/src/mock-builders/utils.js b/src/mock-builders/utils.js index 5cc6e61bb..0d8f943c5 100644 --- a/src/mock-builders/utils.js +++ b/src/mock-builders/utils.js @@ -45,7 +45,6 @@ export const initClientWithChannels = async ({ channelsData, customUser } = {}) ...channelData, }); - // eslint-disable-next-line react-hooks/rules-of-hooks useMockedApis(client, [getOrCreateChannelApi(mockedChannelData)]); const channel = client.channel(mockedChannelData.channel.type, mockedChannelData.channel.id); await channel.watch(); diff --git a/src/plugins/Emojis/EmojiPicker.tsx b/src/plugins/Emojis/EmojiPicker.tsx index 4146e0e91..bc928dac6 100644 --- a/src/plugins/Emojis/EmojiPicker.tsx +++ b/src/plugins/Emojis/EmojiPicker.tsx @@ -1,4 +1,3 @@ -/* eslint-disable typescript-sort-keys/interface */ import React, { useEffect, useState } from 'react'; import { usePopper } from 'react-popper'; import Picker from '@emoji-mart/react'; diff --git a/src/store/hooks/useStateStore.ts b/src/store/hooks/useStateStore.ts index 0e2b09c51..a74bfe9d1 100644 --- a/src/store/hooks/useStateStore.ts +++ b/src/store/hooks/useStateStore.ts @@ -4,15 +4,15 @@ import type { StateStore } from 'stream-chat'; export function useStateStore< T extends Record, - O extends Readonly | Readonly> + O extends Readonly | Readonly>, >(store: StateStore, selector: (v: T) => O): O; export function useStateStore< T extends Record, - O extends Readonly | Readonly> + O extends Readonly | Readonly>, >(store: StateStore | undefined, selector: (v: T) => O): O | undefined; export function useStateStore< T extends Record, - O extends Readonly | Readonly> + O extends Readonly | Readonly>, >(store: StateStore | undefined, selector: (v: T) => O) { const [state, setState] = useState(() => { if (!store) return undefined; diff --git a/src/stories/add-message.stories.tsx b/src/stories/add-message.stories.tsx index 8fa43a6db..082873d48 100644 --- a/src/stories/add-message.stories.tsx +++ b/src/stories/add-message.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import type { ChannelSort } from 'stream-chat'; import { diff --git a/src/stories/edit-message.stories.tsx b/src/stories/edit-message.stories.tsx index 88789916a..6ad131984 100644 --- a/src/stories/edit-message.stories.tsx +++ b/src/stories/edit-message.stories.tsx @@ -35,8 +35,7 @@ const Controls = () => { type: 'image', }, ], - text: - 'chat: https://getstream.io/chat/\nactivity-feeds: https://getstream.io/activity-feeds/', + text: 'chat: https://getstream.io/chat/\nactivity-feeds: https://getstream.io/activity-feeds/', }) } > diff --git a/src/stories/hello.stories.tsx b/src/stories/hello.stories.tsx index d818817a0..179025d8a 100644 --- a/src/stories/hello.stories.tsx +++ b/src/stories/hello.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import type { ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat'; import { diff --git a/src/stories/jump-to-message.stories.tsx b/src/stories/jump-to-message.stories.tsx index 2a06a4ee9..86d0094d9 100644 --- a/src/stories/jump-to-message.stories.tsx +++ b/src/stories/jump-to-message.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import { Channel, diff --git a/src/stories/mark-read.stories.tsx b/src/stories/mark-read.stories.tsx index a6349e3fd..5865e7ada 100644 --- a/src/stories/mark-read.stories.tsx +++ b/src/stories/mark-read.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import type { ChannelSort } from 'stream-chat'; import { nanoid } from 'nanoid'; diff --git a/src/stories/message-status-readby-tooltip.stories.tsx b/src/stories/message-status-readby-tooltip.stories.tsx index cc8878a63..d856ee705 100644 --- a/src/stories/message-status-readby-tooltip.stories.tsx +++ b/src/stories/message-status-readby-tooltip.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import React, { useCallback } from 'react'; import type { ChannelSort } from 'stream-chat'; import { diff --git a/src/stories/pin-message.stories.tsx b/src/stories/pin-message.stories.tsx index a41b5318e..fb7027a83 100644 --- a/src/stories/pin-message.stories.tsx +++ b/src/stories/pin-message.stories.tsx @@ -18,9 +18,7 @@ const PinnedMessagesList = () => { return (

    - {pinnedMessages?.map((pm) => ( -
  • {pm.text}
  • - ))} + {pinnedMessages?.map((pm) =>
  • {pm.text}
  • )}
); }; diff --git a/src/types/types.ts b/src/types/types.ts index 1b4beaf00..b25dac85c 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -41,7 +41,7 @@ export type DefaultChannelType = UnknownType & { }; export type DefaultMessageType< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = UnknownType & { customType?: CustomMessageType; date?: string | Date; @@ -57,7 +57,7 @@ export type DefaultUserTypeInternal = { }; export type DefaultUserType< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = UnknownType & DefaultUserTypeInternal & { mutes?: Array>; @@ -135,7 +135,7 @@ export type VideoAttachmentSizeHandler = ( ) => VideoAttachmentConfiguration; export type ChannelUnreadUiState< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = Omit['read']>, 'user'>; // todo: fix export from stream-chat - for some reason not exported @@ -156,7 +156,6 @@ export type UpdateMessageOptions = { export type Readable = { [key in keyof T]: T[key]; - // eslint-disable-next-line @typescript-eslint/ban-types } & {}; export type ValuesType = T[keyof T]; diff --git a/src/utils/getChannel.ts b/src/utils/getChannel.ts index d47784ada..8e71f80aa 100644 --- a/src/utils/getChannel.ts +++ b/src/utils/getChannel.ts @@ -16,7 +16,7 @@ const WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL: Record< > = {}; type GetChannelParams< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, > = { client: StreamChat; channel?: Channel; @@ -35,7 +35,7 @@ type GetChannelParams< * @param channel */ export const getChannel = async < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >({ channel, client, @@ -56,8 +56,8 @@ export const getChannel = async < const originalCid = theChannel?.id ? theChannel.cid : members && members.length - ? generateChannelTempCid(theChannel.type, members) - : undefined; + ? generateChannelTempCid(theChannel.type, members) + : undefined; if (!originalCid) { throw new Error('Channel ID or channel members array have to be provided to query a channel.');