mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(embed): add support for soundcloud embeds, show webpage links on mobile, adjust audio embeds
This commit is contained in:
@@ -22,6 +22,14 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thumbnailSmall span, .thumbnailSmall a {
|
||||||
|
width: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
word-wrap: break-word;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.thumbnail {
|
.thumbnail {
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styles from './comment-media.module.css';
|
import styles from './comment-media.module.css';
|
||||||
import { CommentMediaInfo } from '../../lib/utils/media-utils';
|
import { CommentMediaInfo, getHasThumbnail } 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, { canEmbed } from '../embed';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import useWindowWidth from '../../hooks/use-window-width';
|
import useWindowWidth from '../../hooks/use-window-width';
|
||||||
|
import { getHostname } from '../../lib/utils/url-utils';
|
||||||
|
|
||||||
interface MediaProps {
|
interface MediaProps {
|
||||||
commentMediaInfo?: CommentMediaInfo;
|
commentMediaInfo?: CommentMediaInfo;
|
||||||
@@ -52,8 +53,8 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'audio') {
|
if (type === 'audio') {
|
||||||
displayWidth = '250px';
|
displayWidth = '100%';
|
||||||
displayHeight = '75px';
|
displayHeight = '100%';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOutOfFeed) {
|
if (isOutOfFeed) {
|
||||||
@@ -64,6 +65,7 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
let thumbnailComponent: React.ReactNode = null;
|
let thumbnailComponent: React.ReactNode = null;
|
||||||
const iframeThumbnail = patternThumbnailUrl || thumbnail;
|
const iframeThumbnail = patternThumbnailUrl || thumbnail;
|
||||||
const gifFrameUrl = useFetchGifFirstFrame(type === 'gif' ? url : undefined);
|
const gifFrameUrl = useFetchGifFirstFrame(type === 'gif' ? url : undefined);
|
||||||
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, url);
|
||||||
|
|
||||||
if (type === 'image') {
|
if (type === 'image') {
|
||||||
thumbnailComponent = <img src={url} alt='' onClick={() => setShowThumbnail(false)} />;
|
thumbnailComponent = <img src={url} alt='' onClick={() => setShowThumbnail(false)} />;
|
||||||
@@ -82,9 +84,20 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
const thumbnailSmallPadding = isMobile ? styles.thumbnailMobile : styles.thumbnailReplyDesktop;
|
const thumbnailSmallPadding = isMobile ? styles.thumbnailMobile : styles.thumbnailReplyDesktop;
|
||||||
const thumbnailDimensions = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
const thumbnailDimensions = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
||||||
|
|
||||||
|
const linkWithoutThumbnail = url && new URL(url);
|
||||||
|
|
||||||
return isMobile || isReply ? (
|
return isMobile || isReply ? (
|
||||||
<ThumbnailSmall style={thumbnailDimensions} thumbnailSmallPadding={thumbnailSmallPadding}>
|
<ThumbnailSmall style={thumbnailDimensions} thumbnailSmallPadding={thumbnailSmallPadding}>
|
||||||
{thumbnailComponent}
|
{thumbnailComponent}
|
||||||
|
{isMobile && !hasThumbnail && linkWithoutThumbnail ? (
|
||||||
|
canEmbed(linkWithoutThumbnail) ? (
|
||||||
|
<span onClick={() => setShowThumbnail(false)}>{getHostname(url)}</span>
|
||||||
|
) : (
|
||||||
|
<a href={url} target='_blank' rel='noreferrer'>
|
||||||
|
{getHostname(url)}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
</ThumbnailSmall>
|
</ThumbnailSmall>
|
||||||
) : (
|
) : (
|
||||||
<ThumbnailBig style={thumbnailDimensions}>{thumbnailComponent}</ThumbnailBig>
|
<ThumbnailBig style={thumbnailDimensions}>{thumbnailComponent}</ThumbnailBig>
|
||||||
|
|||||||
@@ -68,3 +68,9 @@
|
|||||||
height: 50vh !important;
|
height: 50vh !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.soundcloudEmbed {
|
||||||
|
height: 166px; /* default height of soundcloud embeds */
|
||||||
|
width: 100%;
|
||||||
|
max-width: 640px;
|
||||||
|
}
|
||||||
@@ -37,6 +37,9 @@ const Embed = ({ url }: EmbedProps) => {
|
|||||||
if (spotifyHosts.has(parsedUrl.host)) {
|
if (spotifyHosts.has(parsedUrl.host)) {
|
||||||
return <SpotifyEmbed parsedUrl={parsedUrl} />;
|
return <SpotifyEmbed parsedUrl={parsedUrl} />;
|
||||||
}
|
}
|
||||||
|
if (soundcloudHosts.has(parsedUrl.host)) {
|
||||||
|
return <SoundcloudEmbed parsedUrl={parsedUrl} />;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
interface EmbedComponentProps {
|
interface EmbedComponentProps {
|
||||||
@@ -258,6 +261,24 @@ const SpotifyEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const soundcloudHosts = new Set(['soundcloud.com', 'www.soundcloud.com', 'on.soundcloud.com', 'api.soundcloud.com', 'w.soundcloud.com']);
|
||||||
|
|
||||||
|
// not officially documented https://stackoverflow.com/questions/20870270/how-to-get-soundcloud-embed-code-by-soundcloud-com-url
|
||||||
|
const SoundcloudEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
||||||
|
return (
|
||||||
|
<iframe
|
||||||
|
className={styles.soundcloudEmbed}
|
||||||
|
height='100%'
|
||||||
|
width='100%'
|
||||||
|
referrerPolicy='no-referrer'
|
||||||
|
allow='accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share'
|
||||||
|
allowFullScreen
|
||||||
|
title={parsedUrl.href}
|
||||||
|
src={`https://w.soundcloud.com/player/?url=${parsedUrl.href}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const canEmbedHosts = new Set<string>([
|
const canEmbedHosts = new Set<string>([
|
||||||
...youtubeHosts,
|
...youtubeHosts,
|
||||||
...xHosts,
|
...xHosts,
|
||||||
@@ -267,6 +288,7 @@ const canEmbedHosts = new Set<string>([
|
|||||||
...instagramHosts,
|
...instagramHosts,
|
||||||
...odyseeHosts,
|
...odyseeHosts,
|
||||||
...bitchuteHosts,
|
...bitchuteHosts,
|
||||||
|
...soundcloudHosts,
|
||||||
...streamableHosts,
|
...streamableHosts,
|
||||||
...spotifyHosts,
|
...spotifyHosts,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -74,8 +74,18 @@ const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => {
|
|||||||
]
|
]
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
{showThumbnail && !hasThumbnail && (
|
||||||
|
<span>
|
||||||
|
{' '}
|
||||||
|
[
|
||||||
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(false)}>
|
||||||
|
{t('open')}
|
||||||
|
</span>
|
||||||
|
]
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{hasThumbnail && (
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail)) && (
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
||||||
@@ -247,8 +257,18 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => {
|
|||||||
]
|
]
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
{showThumbnail && !hasThumbnail && (
|
||||||
|
<span>
|
||||||
|
{' '}
|
||||||
|
[
|
||||||
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(false)}>
|
||||||
|
{t('open')}
|
||||||
|
</span>
|
||||||
|
]
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{hasThumbnail && (
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail)) && (
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
isReply={true}
|
isReply={true}
|
||||||
@@ -342,7 +362,7 @@ const PostMobile = ({ post, roles, showAllReplies }: PostProps) => {
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{hasThumbnail && (
|
{(hasThumbnail || link) && (
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
||||||
@@ -424,7 +444,7 @@ const ReplyMobile = ({ reply, roles }: PostProps) => {
|
|||||||
<span className={styles.replyToPost}>{shortCid}</span>
|
<span className={styles.replyToPost}>{shortCid}</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{hasThumbnail && (
|
{(hasThumbnail || link) && (
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
isReply={false}
|
isReply={false}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subp
|
|||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
const _feed = [...feed];
|
const _feed = [...feed];
|
||||||
if (subplebbit?.description && subplebbit?.description.length > 0) {
|
if (description && description.length > 0) {
|
||||||
_feed.unshift({
|
_feed.unshift({
|
||||||
isDescription: true,
|
isDescription: true,
|
||||||
subplebbitAddress: address,
|
subplebbitAddress: address,
|
||||||
|
|||||||
Reference in New Issue
Block a user