mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
migrate post_image.tsx to function component (#26395)
This commit is contained in:
parent
1021e51270
commit
ba2d11ff3d
@ -1,10 +1,13 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React from 'react';
|
import React, {useCallback} from 'react';
|
||||||
import type {KeyboardEvent, MouseEvent} from 'react';
|
import type {KeyboardEvent, MouseEvent} from 'react';
|
||||||
|
|
||||||
import type {Post, PostImage as PostImageMetadata} from '@mattermost/types/posts';
|
import type {
|
||||||
|
Post,
|
||||||
|
PostImage as PostImageMetadata,
|
||||||
|
} from '@mattermost/types/posts';
|
||||||
|
|
||||||
import ExternalImage from 'components/external_image';
|
import ExternalImage from 'components/external_image';
|
||||||
import FilePreviewModal from 'components/file_preview_modal';
|
import FilePreviewModal from 'components/file_preview_modal';
|
||||||
@ -14,7 +17,7 @@ import {ModalIdentifiers} from 'utils/constants';
|
|||||||
|
|
||||||
import type {ModalData} from 'types/actions';
|
import type {ModalData} from 'types/actions';
|
||||||
|
|
||||||
interface Props {
|
type PostImageProps = {
|
||||||
imageMetadata: PostImageMetadata;
|
imageMetadata: PostImageMetadata;
|
||||||
link: string;
|
link: string;
|
||||||
post: Post;
|
post: Post;
|
||||||
@ -23,46 +26,57 @@ interface Props {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PostImage extends React.PureComponent<Props> {
|
const PostImage = ({
|
||||||
showModal = (e: (KeyboardEvent<HTMLImageElement> | MouseEvent<HTMLElement>), link = '') => {
|
imageMetadata,
|
||||||
|
link,
|
||||||
|
post,
|
||||||
|
actions,
|
||||||
|
}: PostImageProps) => {
|
||||||
|
const {openModal} = actions;
|
||||||
|
const showModal = useCallback((
|
||||||
|
e: KeyboardEvent<HTMLImageElement> | MouseEvent<HTMLElement>,
|
||||||
|
link = '',
|
||||||
|
) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
this.props.actions.openModal({
|
openModal({
|
||||||
modalId: ModalIdentifiers.FILE_PREVIEW_MODAL,
|
modalId: ModalIdentifiers.FILE_PREVIEW_MODAL,
|
||||||
dialogType: FilePreviewModal,
|
dialogType: FilePreviewModal,
|
||||||
dialogProps: {
|
dialogProps: {
|
||||||
post: this.props.post,
|
post,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
fileInfos: [{
|
fileInfos: [
|
||||||
|
{
|
||||||
has_preview_image: false,
|
has_preview_image: false,
|
||||||
link,
|
link,
|
||||||
extension: this.props.imageMetadata.format,
|
extension: imageMetadata.format,
|
||||||
name: this.props.link,
|
name: link,
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}, [openModal, imageMetadata.format, post]);
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<div className='post__embed-container'>
|
<div className='post__embed-container'>
|
||||||
<ExternalImage
|
<ExternalImage
|
||||||
src={this.props.link}
|
src={link}
|
||||||
imageMetadata={this.props.imageMetadata}
|
imageMetadata={imageMetadata}
|
||||||
>
|
>
|
||||||
{(safeLink) => (
|
{(safeLink) => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<SizeAwareImage
|
<SizeAwareImage
|
||||||
className='img-div attachment__image cursor--pointer'
|
className='img-div attachment__image cursor--pointer'
|
||||||
src={safeLink}
|
src={safeLink}
|
||||||
dimensions={this.props.imageMetadata}
|
dimensions={imageMetadata}
|
||||||
showLoader={true}
|
showLoader={true}
|
||||||
onClick={this.showModal}
|
onClick={showModal}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
</ExternalImage>
|
</ExternalImage>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
export default PostImage;
|
||||||
|
Loading…
Reference in New Issue
Block a user