Skip to content

Commit

Permalink
feat: allowed collapsing gifs
Browse files Browse the repository at this point in the history
Changelog: added
  • Loading branch information
Tim DE WINTER committed Apr 29, 2024
1 parent a6aa92d commit ec4e339
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions webapp/channels/src/components/markdown_image/markdown_image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import FilePreviewModal from 'components/file_preview_modal';
import MarkdownImageExpand from 'components/markdown_image_expand';
import SizeAwareImage from 'components/size_aware_image';

import brokenImageIcon from 'images/icons/brokenimage.png';
import Constants, {ModalIdentifiers} from 'utils/constants';

Check failure on line 15 in webapp/channels/src/components/markdown_image/markdown_image.tsx

View workflow job for this annotation

GitHub Actions / pr-ci / check-lint

There should be no empty line within import group

import brokenImageIcon from 'images/icons/brokenimage.png';

Check failure on line 17 in webapp/channels/src/components/markdown_image/markdown_image.tsx

View workflow job for this annotation

GitHub Actions / pr-ci / check-lint

`images/icons/brokenimage.png` import should occur before import of `utils/constants`

import type {ModalData} from 'types/actions';

export type Props = {
Expand Down Expand Up @@ -42,6 +43,7 @@ export type Props = {
type State = {
loadFailed: boolean;
loaded: boolean;
height?: number;
};

export default class MarkdownImage extends PureComponent<Props, State> {
Expand All @@ -59,27 +61,27 @@ export default class MarkdownImage extends PureComponent<Props, State> {
}

getHeight = () => {
const {
height,
imageMetadata,
width,
} = this.props;
const {imageMetadata, width} = this.props;

if (this.state.height) {
return this.state.height;
}

if (!imageMetadata) {
return 0;
}

if (!height) {
if (!this.props.height) {
return imageMetadata.height;
}

if (height === 'auto') {
if (this.props.height === 'auto') {
const widthNumber = parseInt(width, 10);

return (imageMetadata.height / imageMetadata.width) * widthNumber;
}

return parseInt(height, 10);
return parseInt(this.props.height, 10);
};

getFileExtensionFromUrl = (url: string) => {
Expand Down Expand Up @@ -132,6 +134,7 @@ export default class MarkdownImage extends PureComponent<Props, State> {
handleImageLoaded = ({height, width}: {height: number; width: number}) => {
this.setState({
loaded: true,
height,
}, () => { // Call onImageLoaded prop only after state has already been set
if (this.props.onImageLoaded) {
this.props.onImageLoaded({height, width});
Expand Down

0 comments on commit ec4e339

Please sign in to comment.