adding image popout

This commit is contained in:
Roland Osborne 2022-05-10 13:17:15 -07:00
parent 13a139f7e8
commit 3ab7cbcbff
4 changed files with 77 additions and 6 deletions

View File

@ -0,0 +1,42 @@
import React, { useRef, useEffect, useState } from 'react';
import { Button, Modal } from 'antd';
import ReactResizeDetector from 'react-resize-detector';
import { SelectOutlined, ExpandOutlined, MinusCircleOutlined, PlayCircleOutlined } from '@ant-design/icons';
import { ImageAssetWrapper } from './ImageAsset.styled';
export function ImageAsset({ thumbUrl, fullUrl }) {
const [state, setState] = useState({ width: 0, height: 0, popout: false });
const updateState = (value) => {
setState((s) => ({ ...s, ...value }));
}
const onPopOut = () => {
updateState({ popout: true });
}
return (
<ImageAssetWrapper>
<ReactResizeDetector handleWidth={true} handleHeight={true}>
{({ width, height }) => {
if (width != state.width || height != state.height) {
updateState({ width, height });
}
return <img style={{ height: '100%', objectFit: 'contain' }} src={thumbUrl} alt="" />
}}
</ReactResizeDetector>
<div class="viewer">
<div class="overlay" style={{ width: state.width, height: state.height }}>
<div class="expand" onClick={() => onPopOut()}>
<ExpandOutlined style={{ fontSize: 24, color: '#eeeeee', cursor: 'pointer' }} />
</div>
</div>
</div>
<Modal visible={state.popout} width={'80%'} bodyStyle={{ paddingBottom: 6, paddingTop: 6, paddingLeft: 6, paddingRight: 6, backgroundColor: '#dddddd' }} footer={null} destroyOnClose={true} closable={false} onCancel={() => { updateState({ popout: false })}}>
<img style={{ width: '100%', objectFit: 'contain' }} src={fullUrl} alt="" />
</Modal>
</ImageAssetWrapper>
)
}

View File

@ -0,0 +1,30 @@
import styled from 'styled-components';
export const ImageAssetWrapper = styled.div`
position: relative;
height: 100%;
.viewer {
top: 0;
position: absolute;
}
.viewer:hover .overlay {
visibility: visible;
}
.overlay {
visibility: hidden;
position: relative;
background-color: black;
opacity: 0.5;
}
.expand {
padding-right: 2px;
position: absolute;
bottom: 0;
right: 0;
}
`;

View File

@ -3,6 +3,7 @@ import { TopicItemWrapper } from './TopicItem.styled';
import { useTopicItem } from './useTopicItem.hook';
import { VideoAsset } from './VideoAsset/VideoAsset';
import { AudioAsset } from './AudioAsset/AudioAsset';
import { ImageAsset } from './ImageAsset/ImageAsset';
import { Avatar } from 'avatar/Avatar';
import { CommentOutlined } from '@ant-design/icons';
import { Carousel } from 'Carousel/Carousel';
@ -18,10 +19,8 @@ export function TopicItem({ topic }) {
const renderAsset = (asset) => {
if (asset.image) {
if (asset.image.thumb) {
return <img style={{ height: '100%', objectFit: 'contain' }} src={actions.getAssetUrl(asset.image.thumb)} alt="" />
}
return <img style={{ height: '100%', objectFit: 'contain' }} src={actions.getAssetUrl(asset.image.full)} alt="" />
return <ImageAsset thumbUrl={actions.getAssetUrl(asset.image.thumb)}
fullUrl={actions.getAssetUrl(asset.image.full)} />
}
if (asset.video) {
return <VideoAsset thumbUrl={actions.getAssetUrl(asset.video.thumb)}

View File

@ -17,7 +17,7 @@ export function VideoAsset({ thumbUrl, lqUrl, hdUrl }) {
useEffect(() => {
}, [thumbUrl, hdUrl, lqUrl]);
const onFullScreen = () => {
const onPopOut = () => {
updateState({ inline: false, popout: true, popoutUrl: hdUrl, playing: false, inlineUrl: null });
}
@ -51,7 +51,7 @@ export function VideoAsset({ thumbUrl, lqUrl, hdUrl }) {
<div class="control">
<CenterButton />
</div>
<div class="expand" onClick={() => onFullScreen()}>
<div class="expand" onClick={() => onPopOut()}>
<ExpandOutlined style={{ fontSize: 24, color: '#eeeeee', cursor: 'pointer' }} />
</div>
</div>