Message / Web Page: Use full width for the preview (#1844)

This commit is contained in:
Alexander Zinchuk 2022-04-26 17:08:51 +02:00
parent d7bcf7a769
commit b409071edc
4 changed files with 29 additions and 6 deletions

View File

@ -41,6 +41,7 @@ export type OwnProps = {
nonInteractive?: boolean; nonInteractive?: boolean;
isDownloading: boolean; isDownloading: boolean;
isProtected?: boolean; isProtected?: boolean;
withAspectRatio?: boolean;
theme: ISettings['theme']; theme: ISettings['theme'];
onClick?: (id: number) => void; onClick?: (id: number) => void;
onCancelUpload?: (message: ApiMessage) => void; onCancelUpload?: (message: ApiMessage) => void;
@ -61,6 +62,7 @@ const Photo: FC<OwnProps> = ({
shouldAffectAppendix, shouldAffectAppendix,
isDownloading, isDownloading,
isProtected, isProtected,
withAspectRatio,
theme, theme,
onClick, onClick,
onCancelUpload, onCancelUpload,
@ -143,8 +145,9 @@ const Photo: FC<OwnProps> = ({
width === height && 'square-image', width === height && 'square-image',
); );
const aspectRatio = withAspectRatio ? `aspect-ratio: ${(width / height).toFixed(3)}/ 1` : '';
const style = dimensions const style = dimensions
? `width: ${width}px; height: ${height}px; left: ${dimensions.x}px; top: ${dimensions.y}px;` ? `width: ${width}px; height: ${height}px; left: ${dimensions.x}px; top: ${dimensions.y}px;${aspectRatio}`
: ''; : '';
return ( return (
@ -158,7 +161,7 @@ const Photo: FC<OwnProps> = ({
<canvas <canvas
ref={thumbRef} ref={thumbRef}
className="thumbnail" className="thumbnail"
style={`width: ${width}px; height: ${height}px`} style={`width: ${width}px; height: ${height}px;${aspectRatio}`}
/> />
<img <img
src={fullMediaData} src={fullMediaData}

View File

@ -43,6 +43,7 @@ export type OwnProps = {
lastSyncTime?: number; lastSyncTime?: number;
isDownloading: boolean; isDownloading: boolean;
isProtected?: boolean; isProtected?: boolean;
withAspectRatio?: boolean;
onClick?: (id: number) => void; onClick?: (id: number) => void;
onCancelUpload?: (message: ApiMessage) => void; onCancelUpload?: (message: ApiMessage) => void;
}; };
@ -61,6 +62,7 @@ const Video: FC<OwnProps> = ({
onCancelUpload, onCancelUpload,
isDownloading, isDownloading,
isProtected, isProtected,
withAspectRatio,
}) => { }) => {
// eslint-disable-next-line no-null/no-null // eslint-disable-next-line no-null/no-null
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
@ -150,10 +152,10 @@ const Video: FC<OwnProps> = ({
}, [isUploading, isDownloading, fullMediaData, isPlayAllowed, onClick, onCancelUpload, message]); }, [isUploading, isDownloading, fullMediaData, isPlayAllowed, onClick, onCancelUpload, message]);
const className = buildClassName('media-inner dark', !isUploading && 'interactive'); const className = buildClassName('media-inner dark', !isUploading && 'interactive');
const aspectRatio = withAspectRatio ? `aspect-ratio: ${(width / height).toFixed(3)}/ 1` : '';
const style = dimensions const style = dimensions
? `width: ${width}px; height: ${height}px; left: ${dimensions.x}px; top: ${dimensions.y}px;` ? `width: ${width}px; height: ${height}px; left: ${dimensions.x}px; top: ${dimensions.y}px;${aspectRatio}`
: ''; : '';
return ( return (
<div <div
ref={ref} ref={ref}
@ -165,12 +167,12 @@ const Video: FC<OwnProps> = ({
<canvas <canvas
ref={thumbRef} ref={thumbRef}
className="thumbnail" className="thumbnail"
style={`width: ${width}px; height: ${height}px;`} style={`width: ${width}px; height: ${height}px;${aspectRatio}`}
/> />
<img <img
src={previewBlobUrl} src={previewBlobUrl}
className={buildClassName('thumbnail', previewClassNames)} className={buildClassName('thumbnail', previewClassNames)}
style={`width: ${width}px; height: ${height}px;`} style={`width: ${width}px; height: ${height}px;${aspectRatio}`}
alt="" alt=""
draggable={!isProtected} draggable={!isProtected}
/> />
@ -188,6 +190,7 @@ const Video: FC<OwnProps> = ({
{...bufferingHandlers} {...bufferingHandlers}
draggable={!isProtected} draggable={!isProtected}
onTimeUpdate={handleTimeUpdate} onTimeUpdate={handleTimeUpdate}
style={aspectRatio}
> >
<source src={fullMediaData} /> <source src={fullMediaData} />
</video> </video>

View File

@ -123,4 +123,18 @@
right: 0; right: 0;
} }
} }
@media (min-width: 1921px) {
@supports (aspect-ratio: 1) {
&:not(.in-preview) {
max-width: none;
.thumbnail,
.full-media {
width: 100% !important;
height: auto !important;
}
}
}
}
} }

View File

@ -77,6 +77,7 @@ const WebPage: FC<OwnProps> = ({
const className = buildClassName( const className = buildClassName(
'WebPage', 'WebPage',
inPreview && 'in-preview',
isSquarePhoto && 'with-square-photo', isSquarePhoto && 'with-square-photo',
!photo && !video && !inPreview && 'without-media', !photo && !video && !inPreview && 'without-media',
video && 'with-video', video && 'with-video',
@ -100,6 +101,7 @@ const WebPage: FC<OwnProps> = ({
onCancelUpload={onCancelMediaTransfer} onCancelUpload={onCancelMediaTransfer}
isDownloading={isDownloading} isDownloading={isDownloading}
isProtected={isProtected} isProtected={isProtected}
withAspectRatio
theme={theme} theme={theme}
/> />
)} )}
@ -124,6 +126,7 @@ const WebPage: FC<OwnProps> = ({
onCancelUpload={onCancelMediaTransfer} onCancelUpload={onCancelMediaTransfer}
isDownloading={isDownloading} isDownloading={isDownloading}
isProtected={isProtected} isProtected={isProtected}
withAspectRatio
/> />
)} )}
</div> </div>