Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions src/context/ChannelActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
import type { ChannelStateReducerAction } from '../components/Channel/channelState';
import type { CustomMentionHandler } from '../components/Message/hooks/useMentionsHandler';

import type { ChannelUnreadUiState, UnknownType } from '../types/types';
import type { ChannelUnreadUiState } from '../types/types';

export type MarkReadWrapperOptions = {
/**
Expand Down Expand Up @@ -97,28 +97,3 @@ export const useChannelActionContext = (componentName?: string) => {

return contextValue as unknown as ChannelActionContextValue;
};

/**
* Typescript currently does not support partial inference, so if ChannelActionContext
* typing is desired while using the HOC withChannelActionContext, the Props for the
* wrapped component must be provided as the first generic.
*/
export const withChannelActionContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithChannelActionContextComponent = (
props: Omit<P, keyof ChannelActionContextValue>,
) => {
const channelActionContext = useChannelActionContext();

return <Component {...(props as P)} {...channelActionContext} />;
};

WithChannelActionContextComponent.displayName = (
Component.displayName ||
Component.name ||
'Component'
).replace('Base', '');

return WithChannelActionContextComponent;
};
26 changes: 0 additions & 26 deletions src/context/ChannelStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
import type {
ChannelUnreadUiState,
ImageAttachmentSizeHandler,
UnknownType,
VideoAttachmentSizeHandler,
} from '../types/types';

Expand Down Expand Up @@ -87,28 +86,3 @@ export const useChannelStateContext = (componentName?: string) => {

return contextValue as unknown as ChannelStateContextValue;
};

/**
* Typescript currently does not support partial inference, so if ChannelStateContext
* typing is desired while using the HOC withChannelStateContext, the Props for the
* wrapped component must be provided as the first generic.
*/
export const withChannelStateContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithChannelStateContextComponent = (
props: Omit<P, keyof ChannelStateContextValue>,
) => {
const channelStateContext = useChannelStateContext();

return <Component {...(props as P)} {...channelStateContext} />;
};

WithChannelStateContextComponent.displayName = (
Component.displayName ||
Component.name ||
'Component'
).replace('Base', '');

return WithChannelStateContextComponent;
};
19 changes: 0 additions & 19 deletions src/context/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import type {
SearchController,
} from 'stream-chat';

import { getDisplayName } from './utils/getDisplayName';
import type { ChatProps } from '../components/Chat/Chat';
import type { UnknownType } from '../types/types';
import type { ChannelsQueryState } from '../components/Chat/hooks/useChannelsQueryState';

type CSSClasses =
Expand Down Expand Up @@ -90,20 +88,3 @@ export const useChatContext = (componentName?: string) => {

return contextValue as unknown as ChatContextValue;
};

/**
* Typescript currently does not support partial inference so if ChatContext
* typing is desired while using the HOC withChatContext the Props for the
* wrapped component must be provided as the first generic.
*/
export const withChatContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithChatContextComponent = (props: Omit<P, keyof ChatContextValue>) => {
const chatContext = useChatContext();

return <Component {...(props as P)} {...chatContext} />;
};
WithChatContextComponent.displayName = `WithChatContext${getDisplayName(Component)}`;
return WithChatContextComponent;
};
25 changes: 1 addition & 24 deletions src/context/ComponentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import type {
SearchSourceResultListProps,
} from '../experimental';

import type { PropsWithChildrenOnly, UnknownType } from '../types/types';
import type { PropsWithChildrenOnly } from '../types/types';
import type { StopAIGenerationButtonProps } from '../components/MessageInput/StopAIGenerationButton';
import type { ShareLocationDialogProps } from '../components/Location';
import type { VideoPlayerProps } from '../components/VideoPlayer';
Expand Down Expand Up @@ -276,26 +276,3 @@ export const useComponentContext = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_componentName?: string,
) => useContext(ComponentContext) as unknown as ComponentContextValue;

/**
* Typescript currently does not support partial inference, so if ComponentContext
* typing is desired while using the HOC withComponentContext, the Props for the
* wrapped component must be provided as the first generic.
*/
export const withComponentContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithComponentContextComponent = (props: Omit<P, keyof ComponentContextValue>) => {
const componentContext = useComponentContext();

return <Component {...(props as P)} {...componentContext} />;
};

WithComponentContextComponent.displayName = (
Component.displayName ||
Component.name ||
'Component'
).replace('Base', '');

return WithComponentContextComponent;
};
24 changes: 0 additions & 24 deletions src/context/MessageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type {
} from '../components/Reactions/types';

import type { RenderTextOptions } from '../components/Message/renderText';
import type { UnknownType } from '../types/types';

export type MessageContextValue = {
/** If actions such as edit, delete, flag, mute are enabled on Message */
Expand Down Expand Up @@ -171,26 +170,3 @@ export const useMessageContext = (

return contextValue as unknown as MessageContextValue;
};

/**
* Typescript currently does not support partial inference, so if MessageContext
* typing is desired while using the HOC withMessageContext, the Props for the
* wrapped component must be provided as the first generic.
*/
export const withMessageContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithMessageContextComponent = (props: Omit<P, keyof MessageContextValue>) => {
const messageContext = useMessageContext();

return <Component {...(props as P)} {...messageContext} />;
};

WithMessageContextComponent.displayName = (
Component.displayName ||
Component.name ||
'Component'
).replace('Base', '');

return WithMessageContextComponent;
};
20 changes: 0 additions & 20 deletions src/context/TranslationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import type { PropsWithChildren } from 'react';
import type { TFunction } from 'i18next';
import type { TranslationLanguages } from 'stream-chat';

import { getDisplayName } from './utils/getDisplayName';
import { defaultDateTimeParser, defaultTranslatorFunction } from '../i18n/utils';
import type { UnknownType } from '../types/types';
import type { TDateTimeParser } from '../i18n/types';

Dayjs.extend(calendar);
Expand Down Expand Up @@ -46,21 +44,3 @@ export const useTranslationContext = (componentName?: string) => {

return contextValue;
};

export const withTranslationContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithTranslationContextComponent = (
props: Omit<P, keyof TranslationContextValue>,
) => {
const translationContext = useTranslationContext();

return <Component {...(props as P)} {...translationContext} />;
};

WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(
Component,
)}`;

return WithTranslationContextComponent;
};
24 changes: 0 additions & 24 deletions src/context/TypingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext } from 'react';
import type { PropsWithChildren } from 'react';

import type { ChannelState as StreamChannelState } from 'stream-chat';
import type { UnknownType } from '../types/types';

export type TypingContextValue = {
typing?: StreamChannelState['typing'];
Expand Down Expand Up @@ -36,26 +35,3 @@ export const useTypingContext = (componentName?: string) => {

return contextValue as TypingContextValue;
};

/**
* Typescript currently does not support partial inference, so if TypingContext
* typing is desired while using the HOC withTypingContext, the Props for the
* wrapped component must be provided as the first generic.
*/
export const withTypingContext = <P extends UnknownType>(
Component: React.ComponentType<P>,
) => {
const WithTypingContextComponent = (props: Omit<P, keyof TypingContextValue>) => {
const typingContext = useTypingContext();

return <Component {...(props as P)} {...typingContext} />;
};

WithTypingContextComponent.displayName = (
Component.displayName ||
Component.name ||
'Component'
).replace('Base', '');

return WithTypingContextComponent;
};
5 changes: 0 additions & 5 deletions src/context/utils/getDisplayName.ts

This file was deleted.

Loading