mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add click to enlarge media on mobile with close button
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
width: var(--width);
|
width: var(--width);
|
||||||
height: var(--height);
|
height: var(--height);
|
||||||
margin: 3px 20px 5px 0;
|
margin: 3px 20px 5px 0;
|
||||||
float: left;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -14,12 +13,15 @@
|
|||||||
width: var(--width);
|
width: var(--width);
|
||||||
height: var(--height);
|
height: var(--height);
|
||||||
margin: 3px 10px 5px 5px;
|
margin: 3px 10px 5px 5px;
|
||||||
float: left;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thumbnail {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
.thumbnailBig img, .thumbnailBig video {
|
.thumbnailBig img, .thumbnailBig video {
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
max-height: 250px;
|
max-height: 250px;
|
||||||
@@ -48,6 +50,27 @@
|
|||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fileInfo {
|
||||||
|
padding-bottom: 5px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--post-mobile-file-info-text-color);
|
||||||
|
font-size: 9pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileInfo a {
|
||||||
|
color: var(--post-link-text-color);
|
||||||
|
text-decoration: var(--post-link-text-decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileInfo a:hover {
|
||||||
|
color: var(--post-link-text-color-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.closeButton {
|
||||||
|
text-align: center;
|
||||||
|
padding: 5px 0 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 640px) {
|
@media (min-width: 640px) {
|
||||||
.media img, .media iframe, .media video, .media audio {
|
.media img, .media iframe, .media video, .media audio {
|
||||||
margin: 3px 20px 5px 0;
|
margin: 3px 20px 5px 0;
|
||||||
@@ -56,6 +79,6 @@
|
|||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.media img, .media iframe, .media video, .media audio {
|
.media img, .media iframe, .media video, .media audio {
|
||||||
margin: 3px 10px 5px 5px;
|
padding: 3px 0 5px 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import styles from './media.module.css';
|
|||||||
import { CommentMediaInfo } from '../../lib/utils/media-utils';
|
import { CommentMediaInfo } from '../../lib/utils/media-utils';
|
||||||
import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
||||||
import Embed from '../embed';
|
import Embed from '../embed';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
interface MediaProps {
|
interface MediaProps {
|
||||||
commentMediaInfo?: CommentMediaInfo;
|
commentMediaInfo?: CommentMediaInfo;
|
||||||
@@ -15,13 +16,19 @@ interface MediaProps {
|
|||||||
toggleExpanded?: () => void;
|
toggleExpanded?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ThumbnailBig = ({ style, children }: { style: React.CSSProperties; children: React.ReactNode }) => (
|
interface ThumbnailProps {
|
||||||
|
style: React.CSSProperties;
|
||||||
|
children: React.ReactNode;
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ThumbnailBig = ({ style, children }: ThumbnailProps) => (
|
||||||
<span className={styles.thumbnailBig} style={style}>
|
<span className={styles.thumbnailBig} style={style}>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ThumbnailSmall = ({ style, children }: { style: React.CSSProperties; children: React.ReactNode }) => (
|
const ThumbnailSmall = ({ style, children, type }: ThumbnailProps) => (
|
||||||
<span className={styles.thumbnailSmall} style={style}>
|
<span className={styles.thumbnailSmall} style={style}>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
@@ -57,13 +64,16 @@ const Thumbnail = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth
|
|||||||
const thumbnailStyle = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
const thumbnailStyle = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
||||||
|
|
||||||
return isMobile || isReply ? (
|
return isMobile || isReply ? (
|
||||||
<ThumbnailSmall style={thumbnailStyle}>{mediaComponent}</ThumbnailSmall>
|
<ThumbnailSmall style={thumbnailStyle} type={commentMediaInfo?.type}>
|
||||||
|
{mediaComponent}
|
||||||
|
</ThumbnailSmall>
|
||||||
) : (
|
) : (
|
||||||
<ThumbnailBig style={thumbnailStyle}>{mediaComponent}</ThumbnailBig>
|
<ThumbnailBig style={thumbnailStyle}>{mediaComponent}</ThumbnailBig>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Media = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => {
|
const Media = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<span className={styles.content}>
|
<span className={styles.content}>
|
||||||
<span className={`${showThumbnail ? styles.show : styles.hide} ${styles.thumbnail}`} onClick={() => setShowThumbnail(false)}>
|
<span className={`${showThumbnail ? styles.show : styles.hide} ${styles.thumbnail}`} onClick={() => setShowThumbnail(false)}>
|
||||||
@@ -76,6 +86,7 @@ const Media = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth, sho
|
|||||||
showThumbnail={showThumbnail}
|
showThumbnail={showThumbnail}
|
||||||
setShowThumbnail={setShowThumbnail}
|
setShowThumbnail={setShowThumbnail}
|
||||||
/>
|
/>
|
||||||
|
{isMobile && commentMediaInfo?.type && <div className={styles.fileInfo}>{commentMediaInfo.type}</div>}
|
||||||
</span>
|
</span>
|
||||||
<span className={`${showThumbnail ? styles.hide : styles.show} ${styles.media}`}>
|
<span className={`${showThumbnail ? styles.hide : styles.show} ${styles.media}`}>
|
||||||
{commentMediaInfo?.type === 'iframe' ? (
|
{commentMediaInfo?.type === 'iframe' ? (
|
||||||
@@ -89,6 +100,21 @@ const Media = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth, sho
|
|||||||
) : commentMediaInfo?.type === 'webpage' ? (
|
) : commentMediaInfo?.type === 'webpage' ? (
|
||||||
<img src={commentMediaInfo.url} alt='' />
|
<img src={commentMediaInfo.url} alt='' />
|
||||||
) : null}
|
) : null}
|
||||||
|
{isMobile && commentMediaInfo?.type && (
|
||||||
|
<div className={styles.fileInfo}>
|
||||||
|
<a href={commentMediaInfo.url} target='_blank' rel='noopener noreferrer'>
|
||||||
|
{commentMediaInfo.url.length > 30 ? commentMediaInfo?.url.slice(0, 30) + '...' : commentMediaInfo?.url}
|
||||||
|
</a>{' '}
|
||||||
|
({commentMediaInfo?.type})
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isMobile && (commentMediaInfo?.type === 'iframe' || commentMediaInfo?.type === 'video') && (
|
||||||
|
<div className={styles.closeButton}>
|
||||||
|
<span className='button' onClick={() => setShowThumbnail(true)}>
|
||||||
|
{t('close')}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -217,14 +217,6 @@
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.postMobile .fileThumb .fileInfo {
|
|
||||||
padding-bottom: 5px;
|
|
||||||
text-align: center;
|
|
||||||
color: var(--post-mobile-file-info-text-color);
|
|
||||||
font-size: 9pt;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.postMobile .postMessage {
|
.postMobile .postMessage {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: var(--post-mobile-content-font-size);
|
font-size: var(--post-mobile-content-font-size);
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ const PostMobile = ({ post }: Comment) => {
|
|||||||
showThumbnail={showThumbnail}
|
showThumbnail={showThumbnail}
|
||||||
setShowThumbnail={setShowThumbnail}
|
setShowThumbnail={setShowThumbnail}
|
||||||
/>
|
/>
|
||||||
{commentMediaInfo?.type && <div className={styles.fileInfo}>{commentMediaInfo.type}</div>}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{content && (
|
{content && (
|
||||||
|
|||||||
Reference in New Issue
Block a user