Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Blur video on nsfw labeled content #191

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/common/posts/PostsFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ export function PostEmbeds({ item }: { item: AppBskyFeedDefs.FeedViewPost }) {
? item.post.embed.media
: item.post.embed

const imageRequiresBlur = doesLabelNeedBlur(
const mediaRequiresBlur = doesLabelNeedBlur(
item.post.labels?.map(({ val }) => val),
)
const imageClassName = classNames(
`border border-gray-200 rounded`,
imageRequiresBlur ? 'blur-sm hover:blur-none' : '',
mediaRequiresBlur ? 'blur-sm hover:blur-none' : '',
)

if (AppBskyEmbedVideo.isView(embed)) {
Expand All @@ -240,6 +240,7 @@ export function PostEmbeds({ item }: { item: AppBskyFeedDefs.FeedViewPost }) {
source={embed.playlist}
thumbnail={embed.thumbnail}
alt={embed.alt}
shouldBlur={mediaRequiresBlur}
captions={captions ? (captions as AppBskyEmbedVideo.Caption[]) : []}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/common/posts/PostsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ function PostEmbeds({ item }: { item: AppBskyFeedDefs.FeedViewPost }) {
const embed = AppBskyEmbedRecordWithMedia.isView(item.post.embed)
? item.post.embed.media
: item.post.embed
const imageRequiresBlur = doesLabelNeedBlur(
const mediaRequiresBlur = doesLabelNeedBlur(
item.post.labels?.map(({ val }) => val),
)
const imageClassName = classNames(
`border border-gray-200 rounded`,
imageRequiresBlur ? 'blur-sm hover:blur-none' : '',
mediaRequiresBlur ? 'blur-sm hover:blur-none' : '',
)

if (AppBskyEmbedImages.isView(embed)) {
Expand Down
16 changes: 14 additions & 2 deletions components/common/video/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ export default function VideoPlayer({
alt,
thumbnail,
captions,
shouldBlur = false,
}: {
source: string
alt?: string
thumbnail?: string
captions: AppBskyEmbedVideo.Caption[]
shouldBlur?: boolean
}) {
const [hls] = useState(() => new Hls())
const [isUnsupported, setIsUnsupported] = useState(false)
const [isHovered, setIsHovered] = useState(false)
const figId = useId()
const ref = useRef<HTMLVideoElement>(null)

Expand All @@ -41,19 +44,28 @@ export default function VideoPlayer({
}, [source, hls])

return (
<figure>
<figure
className="flex-1"
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<video
poster={thumbnail}
ref={ref}
style={{ flex: 1 }}
playsInline
preload="none"
controls
loop
muted
crossOrigin="anonymous"
className={`w-full flex-1 transition-all duration-300 ease-in-out ${
isHovered || !shouldBlur ? 'blur-none' : 'blur-md'
}`}
aria-labelledby={alt ? figId : undefined}
>
{!isHovered && shouldBlur && (
<div className="absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 text-white text-xl font-bold"></div>
)}
{isUnsupported && (
<p>
Your browser does not seem to support HLS videos. Please switch to a
Expand Down
Loading