refactored right panel to hook
parent
4ca5a4f093
commit
511adcf388
@ -1,67 +1,66 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { DocumentListItem } from './DocumentListItem';
|
import { DocumentListItem } from './DocumentListItem';
|
||||||
import { ItemClickEvent } from './types/ItemClickEvent';
|
|
||||||
import { MediaGridItem } from './MediaGridItem';
|
import { MediaGridItem } from './MediaGridItem';
|
||||||
import { MediaItemType } from '../../LightboxGallery';
|
import { MediaItemType } from '../../LightboxGallery';
|
||||||
import { missingCaseError } from '../../../util/missingCaseError';
|
import { missingCaseError } from '../../../util/missingCaseError';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
|
import { getSelectedConversationKey } from '../../../state/selectors/conversations';
|
||||||
|
|
||||||
interface Props {
|
type Props = {
|
||||||
type: 'media' | 'documents';
|
type: 'media' | 'documents';
|
||||||
mediaItems: Array<MediaItemType>;
|
mediaItems: Array<MediaItemType>;
|
||||||
onItemClick?: (event: ItemClickEvent) => void;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
export class AttachmentSection extends React.Component<Props> {
|
const Items = (props: Props): JSX.Element => {
|
||||||
public render() {
|
const { mediaItems, type } = props;
|
||||||
const { type } = this.props;
|
const selectedConversationKey = useSelector(getSelectedConversationKey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="module-attachment-section">
|
<>
|
||||||
<div className="module-attachment-section__items">
|
{mediaItems.map((mediaItem, position, array) => {
|
||||||
<div className={`module-attachment-section__items-${type}`}>{this.renderItems()}</div>
|
const shouldShowSeparator = position < array.length - 1;
|
||||||
</div>
|
const { index, attachment, messageTimestamp, messageId } = mediaItem;
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private renderItems() {
|
|
||||||
const { mediaItems, type } = this.props;
|
|
||||||
|
|
||||||
return mediaItems.map((mediaItem, position, array) => {
|
|
||||||
const shouldShowSeparator = position < array.length - 1;
|
|
||||||
const { index, attachment, messageTimestamp, messageId } = mediaItem;
|
|
||||||
|
|
||||||
const onClick = this.createClickHandler(mediaItem);
|
switch (type) {
|
||||||
switch (type) {
|
case 'media':
|
||||||
case 'media':
|
return (
|
||||||
return (
|
<MediaGridItem
|
||||||
<MediaGridItem key={`${messageId}-${index}`} mediaItem={mediaItem} onClick={onClick} />
|
key={`${messageId}-${index}`}
|
||||||
);
|
mediaItem={mediaItem}
|
||||||
case 'documents':
|
mediaItems={mediaItems}
|
||||||
return (
|
/>
|
||||||
<DocumentListItem
|
);
|
||||||
key={`${messageId}-${index}`}
|
case 'documents':
|
||||||
fileName={attachment.fileName}
|
return (
|
||||||
fileSize={attachment.size}
|
<DocumentListItem
|
||||||
shouldShowSeparator={shouldShowSeparator}
|
key={`${messageId}-${index}`}
|
||||||
onClick={onClick}
|
fileName={attachment.fileName}
|
||||||
timestamp={messageTimestamp}
|
fileSize={attachment.size}
|
||||||
/>
|
shouldShowSeparator={shouldShowSeparator}
|
||||||
);
|
timestamp={messageTimestamp}
|
||||||
default:
|
mediaItem={mediaItem}
|
||||||
return missingCaseError(type);
|
conversationId={selectedConversationKey as string}
|
||||||
}
|
/>
|
||||||
});
|
);
|
||||||
}
|
default:
|
||||||
|
return missingCaseError(type);
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
private readonly createClickHandler = (mediaItem: MediaItemType) => () => {
|
export const AttachmentSection = (props: Props) => {
|
||||||
const { onItemClick, type } = this.props;
|
const { type } = props;
|
||||||
|
|
||||||
if (!onItemClick) {
|
return (
|
||||||
return;
|
<div className="module-attachment-section">
|
||||||
}
|
<div className="module-attachment-section__items">
|
||||||
|
<div className={`module-attachment-section__items-${type}`}>
|
||||||
onItemClick({ mediaItem, type });
|
<Items {...props} />
|
||||||
};
|
</div>
|
||||||
}
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
import { MediaItemType } from '../../../LightboxGallery';
|
|
||||||
|
|
||||||
export interface ItemClickEvent {
|
|
||||||
mediaItem: MediaItemType;
|
|
||||||
type: 'media' | 'documents';
|
|
||||||
}
|
|
Loading…
Reference in New Issue