mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-07 11:20:12 +00:00
* Mattermost Blocks * Move block renderer to its own components folder * Sync translation layer * UX fixes * Refactor button to use the button component * Code review * Fix CI * Add animations to collapse blocks * Add unit tests * Add e2e tests and related fixes * Address coderabbit comments * Address UX comments * Address feedback * Address coderabbit comments * Fix snapshots * Sync with webapp translation * Add node limit to button markdown node * Address feedback * i18n-extract * Fix test * Move image utils to the utils folder * Remove unneeded style * Revert build script change --------- Co-authored-by: Mattermost Build <build@mattermost.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useMemo} from 'react';
|
|
|
|
import {useServerUrl} from '@context/server';
|
|
import NetworkManager from '@managers/network_manager';
|
|
|
|
import {getImageSrc} from './get_image_src';
|
|
import {isSVGImage} from './is_svg_image';
|
|
|
|
export type ExternalImageProps = {
|
|
children: (src: string) => React.ReactNode;
|
|
enableSVGs: boolean;
|
|
hasImageProxy: boolean;
|
|
imageMetadata?: PostImage;
|
|
src: string;
|
|
};
|
|
|
|
const ExternalImage = ({children, enableSVGs, hasImageProxy, imageMetadata, src}: ExternalImageProps) => {
|
|
const serverUrl = useServerUrl();
|
|
|
|
const baseRoute = useMemo(() => {
|
|
try {
|
|
return NetworkManager.getClient(serverUrl).getBaseRoute();
|
|
} catch {
|
|
return '';
|
|
}
|
|
}, [serverUrl]);
|
|
|
|
const shouldRenderImage = enableSVGs || !isSVGImage(imageMetadata, src);
|
|
let safeSrc = '';
|
|
if (shouldRenderImage) {
|
|
safeSrc = getImageSrc(src, baseRoute, hasImageProxy && Boolean(baseRoute));
|
|
}
|
|
return <>{children(safeSrc)}</>;
|
|
};
|
|
|
|
export default ExternalImage;
|