Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: sticky share on post

Francesco Sansalvadore6310b114abaf
diff --git a/apps/www/_blog/2023-04-04-infinite-scroll-with-nextjs-framer-motion.mdx b/apps/www/_blog/2023-04-04-infinite-scroll-with-nextjs-framer-motion.mdx
index 406cc058b93..a670abe9610 100644
--- a/apps/www/_blog/2023-04-04-infinite-scroll-with-nextjs-framer-motion.mdx
+++ b/apps/www/_blog/2023-04-04-infinite-scroll-with-nextjs-framer-motion.mdx
@@ -4,6 +4,7 @@ description: Lazy load and paginate data on scroll with Next.js and a sprinkle o
author: fsansalvadore
image: infinite-scroll-thumb.jpg
thumb: infinite-scroll-thumb.jpg
+launchweek: 7
tags:
- tutorial
- launch-week
diff --git a/apps/www/components/LaunchWeek/BlogLinks.tsx b/apps/www/components/LaunchWeek/BlogLinks.tsx
index 8e81b90978b..00ec35233ab 100644
--- a/apps/www/components/LaunchWeek/BlogLinks.tsx
+++ b/apps/www/components/LaunchWeek/BlogLinks.tsx
@@ -6,11 +6,11 @@ const BlogLinks = () => {
const SectionButtons = ({
blog,
docs,
- video,
+ youtube_id,
}: {
blog: string
docs?: string
- video?: string
+ youtube_id?: string
}) => {
return (
<div className="flex gap-2 z-10">
@@ -22,7 +22,7 @@ const BlogLinks = () => {
</div>
</div>
</a>
- {docs && (
+ {!!docs?.length && (
<a href={docs} target="_blank" rel="noopener">
<div className="flex items-center border border-slate-400 bg-gradient-to-r from-[#fcfcfc] to-[#f2f2f2] hover:to-[#d5d5d5] text-black dark:text-white dark:from-[#191919] dark:to-[#464444] dark:hover:to-[#4e4e4e] rounded-full text-sm py-2 pl-3 pr-2">
Docs
@@ -32,8 +32,12 @@ const BlogLinks = () => {
</div>
</a>
)}
- {video && (
- <a href={video} target="_blank" rel="noopener">
+ {!!youtube_id?.length && (
+ <a
+ href={`https://www.youtube.com/watch?v=${youtube_id}&ab_channel=Supabase`}
+ target="_blank"
+ rel="noopener"
+ >
<div className="flex items-center border border-slate-400 bg-gradient-to-r from-[#fcfcfc] to-[#f2f2f2] hover:to-[#d5d5d5] text-black dark:text-white dark:from-[#191919] dark:to-[#464444] dark:hover:to-[#4e4e4e] rounded-full text-sm py-2 pl-3 pr-2">
Video
<div className="bg-[#eeeeee] dark:bg-[#313131] rounded-full inline-block p-1 ml-2">
@@ -51,44 +55,45 @@ const BlogLinks = () => {
if (!activeDays.length) return null
return (
- <div className="flex flex-col items-center gap-4 lg:gap-6">
- <h3 className="text-white text-xl">More Launch Week 7</h3>
+ <div className="flex flex-col gap-3 lg:gap-4 border-t border-scale-400 py-4 lg:py-8 mt-4 lg:mt-8">
+ <h3 className="text-white text-xl mb-4">More Launch Week 7</h3>
{activeDays.map((day) => (
<div
- className={`h-[150px] w-full flex flex-col lg:flex-row group/day${day.d} relative overflow-hidden`}
+ className={`min-h-[150px] w-full flex flex-col lg:flex-row group/day${day.d} relative overflow-hidden`}
>
<div
className={`
flex flex-col flex-1 gap-3 items-start justify-center border rounded-xl h-full relative overflow-hidden
- px-6 lg:px-10 py-4 text-2xl
+ p-6 lg:p-10 text-2xl
before:absolute before:w-full before:h-full before:top-52 before:right-0 before:bottom-0 before:left-0
before:border-[#1f3536] before:-z-10
`}
>
<div className="flex items-center lg: justify-between flex-col-reverse lg:flex-row lg:justify-start gap-2 text-black dark:text-white">
- <div>{day.title}</div>
+ <div className="text-transparent bg-clip-text bg-gradient-to-r from-[#F4FFFA] to-[#B7B2C9]">
+ {day.title}
+ </div>
</div>
<SectionButtons
docs={day.steps[0].docs}
blog={day.steps[0].blog}
- video={'https://www.youtube.com/watch?v=Q1Amk6iDlF8&ab_channel=Supabase'}
+ youtube_id={day.steps[0].youtube_id}
/>
</div>
{day.steps[0].thumb && (
<Image
src={day.steps[0].thumb}
className={`
- absolute group-hover/day${day.d}:scale-105 opacity-90
- group-hover/day${day.d}:opacity-100
+ absolute opacity-90
w-full h-full -z-10 transition-all duration-300
`}
layout="fill"
objectPosition="100% 50%"
- objectFit="contain"
+ objectFit="cover"
/>
)}
<div
- className={`absolute group-hover/day${day.d}:scale-105 opacity-10 group-hover/day${day.d}:opacity-100 w-full h-full -z-10 transition-all duration-300`}
+ className={`absolute opacity-10 w-full h-full -z-10 transition-all duration-300`}
style={{
background: `radial-gradient(650px 150px at 50% 100%, #4635A730, transparent)`,
}}
diff --git a/apps/www/components/LaunchWeek/lw7_days.ts b/apps/www/components/LaunchWeek/lw7_days.ts
index cbd70b1c5ba..7d866942f0a 100644
--- a/apps/www/components/LaunchWeek/lw7_days.ts
+++ b/apps/www/components/LaunchWeek/lw7_days.ts
@@ -16,6 +16,7 @@ export interface WeekDayProps {
isNew: boolean
description: string
thumb?: string
+ youtube_id?: string
}[]
}
@@ -35,7 +36,7 @@ const days: WeekDayProps[] = [
{
title: 'AI generated OG images',
blog: '/blog/',
- docs: '/docs',
+ docs: '',
isNew: false,
description: '',
thumb: '/images/launchweek/seven/day0/ai-images-thumb.png',
diff --git a/apps/www/pages/blog/[slug].tsx b/apps/www/pages/blog/[slug].tsx
index 0ebe379a664..dff167d790d 100644
--- a/apps/www/pages/blog/[slug].tsx
+++ b/apps/www/pages/blog/[slug].tsx
@@ -6,6 +6,7 @@ import { NextSeo } from 'next-seo'
import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
+import { useInView } from 'react-intersection-observer'
import ReactMarkdown from 'react-markdown'
import CTABanner from '~/components/CTABanner'
import DefaultLayout from '~/components/Layouts/Default'
@@ -14,7 +15,8 @@ import mdxComponents from '~/lib/mdx/mdxComponents'
import { mdxSerialize } from '~/lib/mdx/mdxSerialize'
import { getAllPostSlugs, getPostdata, getSortedPosts } from '~/lib/posts'
import BlogLinks from '~/components/LaunchWeek/BlogLinks'
-import HackernewsShare from '~/components/LaunchWeek/HackernewsShare'
+import { useEffect, useRef, useState } from 'react'
+import { motion } from 'framer-motion'
// table of contents extractor
const toc = require('markdown-toc')
@@ -64,9 +66,11 @@ export async function getStaticProps({ params }: any) {
}
function BlogPostPage(props: any) {
+ const articleRef = useRef(null)
+ const [showStickyShare, setShowStickyShare] = useState(false)
const content = props.blog.content
const authorArray = props.blog.author.split(',')
- const isLaunchWeek7 = props.blog.launchWeek7
+ const isLaunchWeek7 = props.blog.launchweek === 7
const author = []
for (let i = 0; i < authorArray.length; i++) {
@@ -106,7 +110,7 @@ function BlogPostPage(props: any) {
const toc = props.blog.toc && (
<div className="space-y-8 py-8 lg:py-0">
<div>
- <div className="space-x-2">
+ <div className="flex flex-wrap gap-2">
{props.blog.tags.map((tag: string) => {
return (
<a href={`/blog/tags/${tag}`} key={`category-badge-${tag}`}>
@@ -188,6 +192,21 @@ function BlogPostPage(props: any) {
</div>
)
+ const handleScroll = () => {
+ const article = articleRef?.current
+ if (!article || typeof window === 'undefined') return null
+ const articleContainer = (article as any)?.getBoundingClientRect()
+ setShowStickyShare(articleContainer.top <= 65 && articleContainer.bottom >= 100)
+ }
+
+ useEffect(() => {
+ window.addEventListener('scroll', handleScroll)
+
+ return () => {
+ window.removeEventListener('scroll', handleScroll)
+ }
+ }, [])
+
return (
<>
<NextSeo
@@ -249,6 +268,18 @@ function BlogPostPage(props: any) {
Back
</a>
</p>
+ <motion.div
+ className="hidden lg:block lg:sticky lg:top-16"
+ animate={{ opacity: showStickyShare ? 1 : 0 }}
+ transition={{ duration: 0.2, ease: [0.6, 0, 0.2, 1] }}
+ >
+ <div className="py-4 lg:py-8">
+ <div className="text-scale-900 dark:text-scale-1000 text-sm">
+ Share this article
+ </div>
+ <ShareArticleActions />
+ </div>
+ </motion.div>
</div>
<div className="col-span-12 lg:col-span-12 xl:col-span-10">
{/* Title and description */}
@@ -296,14 +327,14 @@ function BlogPostPage(props: any) {
)
})}
</div>
- <ShareArticleActions />
+ {/* <ShareArticleActions /> */}
</div>
</div>
</div>
<div className="grid grid-cols-12 lg:gap-16 xl:gap-8">
{/* Content */}
<div className="col-span-12 lg:col-span-7 xl:col-span-7">
- <article>
+ <article ref={articleRef}>
<div className={['prose prose-docs'].join(' ')}>
{props.blog.youtubeHero ? (
<iframe
@@ -331,13 +362,13 @@ function BlogPostPage(props: any) {
<MDXRemote {...content} components={mdxComponents()} />
</div>
</article>
- <div className="py-16">
+ {isLaunchWeek7 && <BlogLinks />}
+ <div className="py-4 lg:py-8">
<div className="text-scale-900 dark:text-scale-1000 text-sm">
Share this article
</div>
<ShareArticleActions />
</div>
- {isLaunchWeek7 && <BlogLinks />}
<div className="grid gap-8 py-8 lg:grid-cols-1">
<div>
{props.prevPost && <NextCard post={props.prevPost} label="Last post" />}
@@ -351,7 +382,8 @@ function BlogPostPage(props: any) {
</div>
{/* Sidebar */}
<div className="col-span-12 space-y-8 lg:col-span-5 xl:col-span-3 xl:col-start-9">
- <div className="space-y-8 lg:sticky lg:top-24 lg:mb-24">
+ {/* <div className="space-y-8 lg:sticky lg:top-24 lg:mb-24"> */}
+ <div className="space-y-8 lg:mb-24">
<div className="hidden lg:block">{toc}</div>
<div>
<div className="mb-4">