feat: load quote images correctly on first render

pull/2757/head
William Grant 2 years ago
parent acdeabf306
commit 1da8fd9f96

@ -64,7 +64,7 @@ type QuoteIconProps = {
icon: QuoteIconTypes; icon: QuoteIconTypes;
}; };
const QuoteIcon = (props: QuoteIconProps) => { export const QuoteIcon = (props: QuoteIconProps) => {
const { icon } = props; const { icon } = props;
const iconProps = icons[icon]; const iconProps = icons[icon];
@ -104,30 +104,29 @@ export const QuoteIconContainer = (
} }
const objectUrl = getObjectUrl(thumbnail); const objectUrl = getObjectUrl(thumbnail);
if (objectUrl) {
if (GoogleChrome.isVideoTypeSupported(contentType)) { if (GoogleChrome.isVideoTypeSupported(contentType)) {
return objectUrl && !imageBroken ? ( return (
<QuoteImage <QuoteImage
url={objectUrl} url={objectUrl}
contentType={MIME.IMAGE_JPEG} contentType={MIME.IMAGE_JPEG}
handleImageErrorBound={noop} showPlayButton={true}
showPlayButton={true} imageBroken={imageBroken}
/> handleImageErrorBound={noop}
) : ( />
<QuoteIcon icon="movie" /> );
); }
}
if (GoogleChrome.isImageTypeSupported(contentType)) {
if (GoogleChrome.isImageTypeSupported(contentType)) { return (
return objectUrl && !imageBroken ? ( <QuoteImage
<QuoteImage url={objectUrl}
url={objectUrl} contentType={contentType}
contentType={contentType} imageBroken={imageBroken}
handleImageErrorBound={handleImageErrorBound} handleImageErrorBound={handleImageErrorBound}
/> />
) : ( );
<QuoteIcon icon="image" /> }
);
} }
if (MIME.isAudio(contentType)) { if (MIME.isAudio(contentType)) {

@ -3,6 +3,8 @@ import { useDisableDrag } from '../../../../../hooks/useDisableDrag';
import { useEncryptedFileFetch } from '../../../../../hooks/useEncryptedFileFetch'; import { useEncryptedFileFetch } from '../../../../../hooks/useEncryptedFileFetch';
import styled from 'styled-components'; import styled from 'styled-components';
import { icons } from '../../../../icon'; import { icons } from '../../../../icon';
import { isEmpty } from 'lodash';
import { QuoteIcon } from './QuoteIconContainer';
const StyledQuoteImage = styled.div` const StyledQuoteImage = styled.div`
flex: initial; flex: initial;
@ -56,18 +58,20 @@ const StyledPlayButton = styled.div`
`; `;
export const QuoteImage = (props: { export const QuoteImage = (props: {
handleImageErrorBound: () => void;
url: string; url: string;
contentType: string; contentType: string;
showPlayButton?: boolean; showPlayButton?: boolean;
imageBroken: boolean;
handleImageErrorBound: () => void;
}) => { }) => {
const { url, showPlayButton, contentType, handleImageErrorBound } = props; const { url, contentType, showPlayButton, imageBroken, handleImageErrorBound } = props;
const disableDrag = useDisableDrag(); const disableDrag = useDisableDrag();
const { loading, urlToLoad } = useEncryptedFileFetch(url, contentType, false); const { loading, urlToLoad } = useEncryptedFileFetch(url, contentType, false);
const srcData = !loading ? urlToLoad : ''; const srcData = !loading ? urlToLoad : '';
return ( return !isEmpty(srcData) && !imageBroken ? (
<StyledQuoteImage> <StyledQuoteImage>
<img <img
src={srcData} src={srcData}
@ -85,5 +89,7 @@ export const QuoteImage = (props: {
</StyledPlayButton> </StyledPlayButton>
)} )}
</StyledQuoteImage> </StyledQuoteImage>
) : (
<QuoteIcon icon={showPlayButton ? 'movie' : 'image'} />
); );
}; };

@ -404,7 +404,7 @@ async function getMessages({
} }
} }
window.log.debug(`WIP: duck quoteProps`, quotesProps); // window.log.debug(`WIP: duck quoteProps`, quotesProps);
return { messagesProps, quotesProps }; return { messagesProps, quotesProps };
} }

Loading…
Cancel
Save