Skip to content

Commit

Permalink
Prettier + ESLint fixes (and some manual fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Jan 30, 2025
1 parent 9d8d5ac commit 67a302f
Show file tree
Hide file tree
Showing 385 changed files with 5,768 additions and 3,330 deletions.
2 changes: 1 addition & 1 deletion e2e/fixtures/data/attachment.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable sort-keys */
const smallImageAttachment = [
{
type: 'image',
Expand Down
5 changes: 1 addition & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ export default tseslint.config(
'object-shorthand': 'warn',
'prefer-const': 'warn',
'require-await': 'error',
"sort-destructure-keys/sort-destructure-keys": [
"error",
{ caseSensitive: false },
],
'sort-destructure-keys/sort-destructure-keys': ['error', { caseSensitive: false }],
'sort-imports': [
'error',
{
Expand Down
9 changes: 4 additions & 5 deletions src/components/AIStateIndicator/AIStateIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics>;
};

export const AIStateIndicator = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
channel: channelFromProps,
}: AIStateIndicatorProps<StreamChatGenerics>) => {
const { t } = useTranslationContext();
const { channel: channelFromContext } = useChannelStateContext<StreamChatGenerics>(
'AIStateIndicator',
);
const { channel: channelFromContext } =
useChannelStateContext<StreamChatGenerics>('AIStateIndicator');

Check warning on line 23 in src/components/AIStateIndicator/AIStateIndicator.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/AIStateIndicator/AIStateIndicator.tsx#L23

Added line #L23 was not covered by tests
const channel = channelFromProps || channelFromContext;
const { aiState } = useAIState(channel);
const allowedStates = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AIStateIndicator/hooks/useAIState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics>,
): { aiState: AIState } => {
Expand Down
19 changes: 11 additions & 8 deletions src/components/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics>[];
Expand Down Expand Up @@ -87,14 +87,17 @@ 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<StreamChatGenerics>,
) => {
const { attachments } = props;

// eslint-disable-next-line react-hooks/exhaustive-deps
const groupedAttachments = useMemo(() => renderGroupedAttachments(props), [attachments]);
const groupedAttachments = useMemo(
() => renderGroupedAttachments(props),
// eslint-disable-next-line react-hooks/exhaustive-deps
[attachments],
);

return (
<div className='str-chat__attachment-list'>
Expand All @@ -107,13 +110,13 @@ export const Attachment = <
};

const renderGroupedAttachments = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachments,
...rest
}: AttachmentProps<StreamChatGenerics>): GroupedRenderedAttachment => {
const uploadedImages: StreamAttachment<StreamChatGenerics>[] = attachments.filter((attachment) =>
isUploadedImage(attachment),
const uploadedImages: StreamAttachment<StreamChatGenerics>[] = attachments.filter(
(attachment) => isUploadedImage(attachment),
);

const containers = attachments
Expand Down Expand Up @@ -169,7 +172,7 @@ const renderGroupedAttachments = <
};

const getAttachmentType = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
attachment: AttachmentProps<StreamChatGenerics>['attachments'][number],
): keyof typeof CONTAINER_MAP => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Attachment/AttachmentActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics> & {
/** A list of actions */
actions: Action[];
Expand All @@ -20,7 +20,7 @@ export type AttachmentActionsProps<
};

const UnMemoizedAttachmentActions = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: AttachmentActionsProps<StreamChatGenerics>,
) => {
Expand Down
40 changes: 20 additions & 20 deletions src/components/Attachment/AttachmentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics> | GalleryAttachment<StreamChatGenerics>;
componentType: AttachmentComponentType;
};
export const AttachmentWithinContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
children,
Expand All @@ -50,16 +50,17 @@ export const AttachmentWithinContainer = <
componentType === 'card' && !attachment?.image_url && !attachment?.thumb_url
? 'no-image'
: attachment?.actions?.length
? 'actions'
: '';
? 'actions'
: '';
}

const classNames = clsx(
'str-chat__message-attachment str-chat__message-attachment-dynamic-size',
{
[`str-chat__message-attachment--${componentType}`]: componentType,
[`str-chat__message-attachment--${attachment?.type}`]: attachment?.type,
[`str-chat__message-attachment--${componentType}--${extra}`]: componentType && extra,
[`str-chat__message-attachment--${componentType}--${extra}`]:
componentType && extra,
'str-chat__message-attachment--svg-image': isSvgAttachment(attachment),
'str-chat__message-attachment-with-actions': extra === 'actions',
},
Expand All @@ -69,7 +70,7 @@ export const AttachmentWithinContainer = <
};

export const AttachmentActionsContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
actionHandler,
attachment,
Expand Down Expand Up @@ -108,7 +109,7 @@ function getCssDimensionsVariables(url: string) {
}

export const GalleryContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
Gallery = DefaultGallery,
Expand Down Expand Up @@ -150,7 +151,7 @@ export const GalleryContainer = <
};

export const ImageContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: RenderAttachmentProps<StreamChatGenerics>,
) => {
Expand Down Expand Up @@ -194,7 +195,7 @@ export const ImageContainer = <
};

export const CardContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: RenderAttachmentProps<StreamChatGenerics>,
) => {
Expand All @@ -220,7 +221,7 @@ export const CardContainer = <
};

export const FileContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
File = DefaultFile,
Expand All @@ -234,7 +235,7 @@ export const FileContainer = <
);
};
export const AudioContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
Audio = DefaultAudio,
Expand All @@ -247,11 +248,11 @@ export const AudioContainer = <
);

export const VoiceRecordingContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
VoiceRecording = DefaultVoiceRecording,
isQuoted,
VoiceRecording = DefaultVoiceRecording,
}: RenderAttachmentProps<StreamChatGenerics>) => (
<AttachmentWithinContainer attachment={attachment} componentType='voiceRecording'>
<div className='str-chat__attachment'>
Expand All @@ -261,18 +262,17 @@ export const VoiceRecordingContainer = <
);

export const MediaContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: RenderAttachmentProps<StreamChatGenerics>,
) => {
const { attachment, Media = ReactPlayer } = props;
const componentType = 'media';
const { shouldGenerateVideoThumbnail, videoAttachmentSizeHandler } = useChannelStateContext();
const { shouldGenerateVideoThumbnail, videoAttachmentSizeHandler } =
useChannelStateContext();
const videoElement = useRef<HTMLDivElement>(null);
const [
attachmentConfiguration,
setAttachmentConfiguration,
] = useState<VideoAttachmentConfiguration>();
const [attachmentConfiguration, setAttachmentConfiguration] =
useState<VideoAttachmentConfiguration>();

useLayoutEffect(() => {
if (videoElement.current && videoAttachmentSizeHandler) {
Expand Down Expand Up @@ -319,7 +319,7 @@ export const MediaContainer = <
};

export const UnsupportedAttachmentContainer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
UnsupportedAttachment = DefaultUnsupportedAttachment,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Attachment/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamChatGenerics>;
};

const UnMemoizedAudio = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: AudioProps<StreamChatGenerics>,
) => {
Expand Down
37 changes: 29 additions & 8 deletions src/components/Attachment/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ const UnableToRenderCard = ({ type }: { type?: CardProps['type'] }) => {
);
};

const SourceLink = ({ author_name, url }: Pick<CardProps, 'author_name'> & { url: string }) => (
<div className='str-chat__message-attachment-card--source-link' data-testid='card-source-link'>
const SourceLink = ({
author_name,
url,
}: Pick<CardProps, 'author_name'> & { url: string }) => (
<div
className='str-chat__message-attachment-card--source-link'
data-testid='card-source-link'
>
<SafeAnchor
className='str-chat__message-attachment-card--url'
href={url}
Expand All @@ -68,7 +74,13 @@ const CardHeader = (props: CardHeaderProps) => {
let visual = null;
if (asset_url && type === 'video') {
visual = (
<ReactPlayer className='react-player' controls height='100%' url={asset_url} width='100%' />
<ReactPlayer
className='react-player'
controls
height='100%'
url={asset_url}
width='100%'
/>
);
} else if (image) {
visual = (
Expand Down Expand Up @@ -104,7 +116,9 @@ const CardContent = (props: CardContentProps) => {
) : (
<div className='str-chat__message-attachment-card--flex'>
{url && <SourceLink author_name={author_name} url={url} />}
{title && <div className='str-chat__message-attachment-card--title'>{title}</div>}
{title && (
<div className='str-chat__message-attachment-card--title'>{title}</div>
)}
{text && <div className='str-chat__message-attachment-card--text'>{text}</div>}
</div>
)}
Expand Down Expand Up @@ -139,9 +153,13 @@ export const CardAudio = ({
)}
<div className='str-chat__message-attachment-audio-widget--second-row'>
{url && <SourceLink author_name={author_name} url={url} />}
{title && <div className='str-chat__message-attachment-audio-widget--title'>{title}</div>}
{title && (
<div className='str-chat__message-attachment-audio-widget--title'>{title}</div>
)}
{text && (
<div className='str-chat__message-attachment-audio-widget--description'>{text}</div>
<div className='str-chat__message-attachment-audio-widget--description'>
{text}
</div>
)}
</div>
</div>
Expand All @@ -158,7 +176,8 @@ const UnMemoizedCard = (props: CardProps) => {
const dimensions: { height?: string; width?: string } = {};

if (type === 'giphy' && typeof giphy !== 'undefined') {
const giphyVersion = giphy[giphyVersionName as keyof NonNullable<Attachment['giphy']>];
const giphyVersion =
giphy[giphyVersionName as keyof NonNullable<Attachment['giphy']>];

Check warning on line 180 in src/components/Attachment/Card.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Attachment/Card.tsx#L180

Added line #L180 was not covered by tests
image = giphyVersion.url;
dimensions.height = giphyVersion.height;
dimensions.width = giphyVersion.width;
Expand All @@ -169,7 +188,9 @@ const UnMemoizedCard = (props: CardProps) => {
}

return (
<div className={`str-chat__message-attachment-card str-chat__message-attachment-card--${type}`}>
<div
className={`str-chat__message-attachment-card str-chat__message-attachment-card--${type}`}
>
<CardHeader {...props} dimensions={dimensions} image={image} />
<CardContent {...props} />
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/components/Attachment/FileAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ import { DownloadButton, FileSizeIndicator } from './components';
import type { DefaultStreamChatGenerics } from '../../types/types';

export type FileAttachmentProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
attachment: Attachment<StreamChatGenerics>;
};

const UnMemoizedFileAttachment = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
attachment,
}: FileAttachmentProps<StreamChatGenerics>) => (
<div className='str-chat__message-attachment-file--item' data-testid='attachment-file'>
<FileIcon className='str-chat__file-icon' mimeType={attachment.mime_type} />
<div className='str-chat__message-attachment-file--item-text'>
<div className='str-chat__message-attachment-file--item-first-row'>
<div className='str-chat__message-attachment-file--item-name' data-testid='file-title'>
<div
className='str-chat__message-attachment-file--item-name'
data-testid='file-title'
>
{attachment.title}
</div>
<DownloadButton assetUrl={attachment.asset_url} />
Expand Down
Loading

0 comments on commit 67a302f

Please sign in to comment.