2024-09-14 18:05:59 -05:00
import Image from "next/image"
2024-09-30 12:59:19 -05:00
import { useState , useRef , useEffect } from "react"
2024-09-14 18:05:59 -05:00
import { useImageProxy } from "@/hooks/useImageProxy"
import GenericButton from "@/components/buttons/GenericButton"
import { useRouter } from "next/router"
import useWindowWidth from "@/hooks/useWindowWidth"
2024-10-03 14:03:18 -05:00
import NostrIcon from "../../../../public/images/nostr.png"
import { useToast } from "@/hooks/useToast" ;
2024-09-14 18:05:59 -05:00
// With current spacing the title can only be 1 line
const promotions = [
{
id : 1 ,
category : "PLEBDEVS" ,
2024-10-06 14:41:08 -05:00
title : "Content and Community platform" ,
description : "One of a kind Nostr / Lightning integrated Content and Community platform." ,
2024-09-14 18:05:59 -05:00
icon : "pi pi-code" ,
2024-10-05 17:13:01 -05:00
video : "https://plebdevs-bucket.nyc3.cdn.digitaloceanspaces.com/plebdevs-montage.mp4" ,
2024-09-14 18:05:59 -05:00
} ,
{
id : 2 ,
2024-09-30 12:59:19 -05:00
category : "CONTENT" ,
title : "Comprehensive Learning Resources" ,
2024-10-06 14:41:08 -05:00
description : "Access the PlebDevs library of courses, videos, and documents." ,
2024-09-14 18:05:59 -05:00
icon : "pi pi-book" ,
image : "https://media.istockphoto.com/id/1224500457/photo/programming-code-abstract-technology-background-of-software-developer-and-computer-script.jpg?s=612x612&w=0&k=20&c=nHMypkMTU1HUUW85Zt0Ff7MDbq17n0eVeXaoM9Knt4Q=" ,
} ,
{
id : 3 ,
category : "COMMUNITY" ,
2024-10-03 14:13:34 -05:00
title : "Join Our Community of learners / hackers" ,
2024-10-06 14:41:08 -05:00
description : "Learn and connect with other developers, share your projects, and level up together." ,
2024-09-14 18:05:59 -05:00
icon : "pi pi-users" ,
image : "https://pikwizard.com/pw/medium/50238b1cad4ff412fdafc1325efa1c9f.jpg" ,
} ,
{
2024-09-30 12:59:19 -05:00
id : 4 ,
2024-09-14 18:05:59 -05:00
category : "LIGHTNING / NOSTR" ,
2024-09-30 12:59:19 -05:00
title : "Lightning and Nostr integrated platform" ,
2024-10-06 14:41:08 -05:00
description : "All content is published to and pulled from nostr relays and is fully interoperable with comments, zaps, and other nostr clients. Premium content is available for sale with lightning or by subscribing to plebdevs via a lightning subscription." ,
2024-09-14 18:05:59 -05:00
icon : "pi pi-bolt" ,
image : "https://www.financemagnates.com/wp-content/uploads/2016/05/Bicoin-lightning.jpg" ,
} ,
]
const InteractivePromotionalCarousel = ( ) => {
const [ selectedPromotion , setSelectedPromotion ] = useState ( promotions [ 0 ] )
const { returnImageProxy } = useImageProxy ( ) ;
2024-10-03 14:03:18 -05:00
const { showToast } = useToast ( ) ;
2024-09-14 18:05:59 -05:00
const windowWidth = useWindowWidth ( ) ;
2024-10-03 16:37:08 -05:00
const isTabView = windowWidth <= 1360 ;
const isMobile = windowWidth <= 768 ;
2024-09-14 18:05:59 -05:00
const router = useRouter ( ) ;
2024-09-30 12:59:19 -05:00
const videoRef = useRef ( null ) ;
2024-10-03 14:03:18 -05:00
const copyToClipboard = async ( text ) => {
try {
await navigator . clipboard . writeText ( text ) ;
showToast ( "success" , "Copied" , "Copied Lightning Address to clipboard" ) ;
if ( window && window ? . webln && window ? . webln ? . lnurl ) {
await window . webln . enable ( ) ;
const result = await window . webln . lnurl ( "austin@bitcoinpleb.dev" ) ;
if ( result && result ? . preimage ) {
showToast ( "success" , "Payment Sent" , "Thank you for your donation!" ) ;
}
}
} catch ( err ) {
console . error ( 'Failed to copy:' , err ) ;
}
} ;
2024-09-30 12:59:19 -05:00
useEffect ( ( ) => {
if ( videoRef . current && selectedPromotion . video ) {
videoRef . current . play ( ) ;
}
} , [ selectedPromotion ] ) ;
2024-09-14 18:05:59 -05:00
return (
2024-10-03 16:37:08 -05:00
< div className = { ` flex ${ isTabView ? 'flex-col' : 'flex-row' } bg-gray-900 text-white m-4 mx-14 rounded-lg ${ isTabView ? 'h-auto' : 'h-[620px]' } ${ isTabView ? 'w-full mx-0 ml-0 mt-0' : null } ` } >
< div className = { isTabView ? 'w-full' : 'lg:w-2/3 relative' } >
2024-09-30 12:59:19 -05:00
{ selectedPromotion . video ? (
< video
ref = { videoRef }
src = { selectedPromotion . video }
2024-10-03 16:37:08 -05:00
className = { ` object-cover w-full ${ isTabView ? 'h-[300px]' : 'h-full' } rounded-lg ` }
2024-09-30 12:59:19 -05:00
loop
muted
playsInline
/ >
) : (
< Image
src = { returnImageProxy ( selectedPromotion . image ) }
alt = { selectedPromotion . title }
width = { 800 }
height = { 600 }
2024-10-03 16:37:08 -05:00
className = { ` object-cover w-full ${ isTabView ? 'h-[300px]' : 'h-full' } rounded-lg opacity-75 ` }
2024-09-30 12:59:19 -05:00
/ >
) }
2024-10-03 16:37:08 -05:00
{ isTabView ? (
2024-09-14 18:05:59 -05:00
< div className = "p-6 space-y-2" >
< div className = "uppercase text-sm font-bold text-[#f8f8ff]" > { selectedPromotion . category } < / d i v >
< h2 className = "text-4xl font-bold leading-tight text-white drop-shadow-lg" >
{ selectedPromotion . title }
< / h 2 >
< p className = "text-lg text-white drop-shadow-md" > { selectedPromotion . description } < / p >
2024-10-03 16:37:08 -05:00
< div className = { ` flex flex-row gap-2 mt-4 ${ isTabView ? 'flex-col' : '' } ` } >
2024-09-14 18:05:59 -05:00
{
( ( ) => {
switch ( selectedPromotion . category ) {
case "PLEBDEVS" :
return (
2024-09-16 16:10:28 -05:00
< div className = "flex flex-row gap-2" >
2024-09-14 18:36:46 -05:00
< GenericButton onClick = { ( ) => router . push ( '/subscribe' ) } severity = "warning" icon = { < i className = "pi pi-star pr-2 pb-1" / > } label = "Subscribe" className = "w-fit py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=all' ) } severity = "primary" icon = { < i className = "pi pi-eye pr-2" / > } label = "View all content" className = "w-fit py-2 font-semibold" size = "small" outlined / >
2024-09-16 16:10:28 -05:00
< / d i v >
2024-09-14 18:05:59 -05:00
) ;
2024-09-30 12:59:19 -05:00
case "CONTENT" :
2024-09-14 18:05:59 -05:00
return (
2024-09-30 12:59:19 -05:00
< >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=courses' ) } icon = { < i className = "pi pi-book pr-2 pb-1" / > } label = "Courses" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=videos' ) } icon = { < i className = "pi pi-video pr-2" / > } label = "Videos" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=documents' ) } icon = { < i className = "pi pi-file pr-2 pb-1" / > } label = "Documents" className = "py-2 font-semibold" size = "small" outlined / >
< / >
2024-09-14 18:05:59 -05:00
) ;
case "COMMUNITY" :
return (
2024-09-14 18:36:46 -05:00
< GenericButton onClick = { ( ) => router . push ( '/feed?channel=global' ) } icon = { < i className = "pi pi-users pr-2 pb-1" / > } label = "Open Community Feed" className = "w-fit py-2 font-semibold" size = "small" outlined / >
2024-09-14 18:05:59 -05:00
) ;
case "LIGHTNING / NOSTR" :
return (
2024-09-14 18:36:46 -05:00
< GenericButton onClick = { ( ) => router . push ( '/subscribe' ) } severity = "warning" icon = { < i className = "pi pi-star pr-2 pb-1" / > } label = "Subscribe" className = "w-fit py-2 font-semibold" size = "small" outlined / >
2024-09-14 18:05:59 -05:00
) ;
default :
return null ;
}
} ) ( )
}
< / d i v >
< / d i v >
) : (
< >
2024-10-06 14:41:08 -05:00
< div className = "absolute inset-0 from-black via-black/70 to-transparent rounded-lg" / >
< div className = { ` bg-gray-800/90 rounded-tr-lg absolute bottom-0 left-0 p-4 space-y-2 ${ isTabView ? 'pb-16' : 'max-w-[80%]' } ` } >
2024-09-14 18:05:59 -05:00
< div className = "uppercase text-sm font-bold text-[#f8f8ff]" > { selectedPromotion . category } < / d i v >
2024-10-06 14:41:08 -05:00
< h2 className = "font-bold leading-tight text-white drop-shadow-lg" >
2024-09-14 18:05:59 -05:00
{ selectedPromotion . title }
< / h 2 >
< p className = "text-lg text-white drop-shadow-md" > { selectedPromotion . description } < / p >
2024-10-06 14:41:08 -05:00
< div className = "flex flex-row gap-2" >
2024-09-14 18:05:59 -05:00
{
( ( ) => {
switch ( selectedPromotion . category ) {
case "PLEBDEVS" :
return (
2024-10-06 14:41:08 -05:00
< div className = "flex flex-row gap-4 mt-4" >
2024-09-14 18:05:59 -05:00
< GenericButton onClick = { ( ) => router . push ( '/about' ) } severity = "success" icon = { < i className = "pi pi-question-circle pr-2 pb-[2px]" / > } label = "Learn More" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/subscribe' ) } severity = "warning" icon = { < i className = "pi pi-star pr-2 pb-1" / > } label = "Subscribe" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=all' ) } severity = "primary" icon = { < i className = "pi pi-eye pr-2" / > } label = "View all content" className = "py-2 font-semibold" size = "small" outlined / >
2024-10-06 14:41:08 -05:00
< / d i v >
2024-09-14 18:05:59 -05:00
) ;
2024-09-30 12:59:19 -05:00
case "CONTENT" :
2024-09-14 18:05:59 -05:00
return (
2024-10-06 14:41:08 -05:00
< div className = "flex flex-row gap-4 mt-4" >
2024-09-30 12:59:19 -05:00
< GenericButton onClick = { ( ) => router . push ( '/content?tag=courses' ) } icon = { < i className = "pi pi-book pr-2 pb-1" / > } label = "Courses" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=videos' ) } icon = { < i className = "pi pi-video pr-2" / > } label = "Videos" className = "py-2 font-semibold" size = "small" outlined / >
< GenericButton onClick = { ( ) => router . push ( '/content?tag=documents' ) } icon = { < i className = "pi pi-file pr-2 pb-1" / > } label = "Documents" className = "py-2 font-semibold" size = "small" outlined / >
2024-10-06 14:41:08 -05:00
< / d i v >
2024-09-14 18:05:59 -05:00
) ;
case "COMMUNITY" :
return (
< GenericButton onClick = { ( ) => router . push ( '/feed?channel=global' ) } icon = { < i className = "pi pi-users pr-2 pb-1" / > } label = "Open Community Feed" className = "py-2 font-semibold" size = "small" outlined / >
) ;
case "LIGHTNING / NOSTR" :
return (
< GenericButton onClick = { ( ) => router . push ( '/subscribe' ) } severity = "warning" icon = { < i className = "pi pi-star pr-2 pb-1" / > } label = "Subscribe" className = "py-2 font-semibold" size = "small" outlined / >
) ;
default :
return null ;
}
} ) ( )
}
< / d i v >
< / d i v >
< / >
) }
< / d i v >
2024-10-03 16:37:08 -05:00
< div className = { isTabView ? 'w-full p-4' : 'lg:w-1/3 p-4 space-y-4' } >
{ isTabView ? (
2024-09-14 18:05:59 -05:00
< div className = "flex overflow-x-auto pb-4 space-x-4" >
{ promotions . map ( ( promo ) => (
< div
key = { promo . id }
2024-10-03 16:37:08 -05:00
className = { ` flex-shrink-0 w-64 space-y-4 cursor-pointer transition-colors duration-200 hover:bg-gray-700 ${ selectedPromotion . id === promo . id ? "bg-gray-700" : "bg-gray-800"
2024-09-30 12:59:19 -05:00
} p - 4 rounded - lg shadow - lg ` }
2024-09-14 18:05:59 -05:00
onClick = { ( ) => setSelectedPromotion ( promo ) } >
< div className = "flex items-center gap-2" >
< i className = { ` ${ promo . icon } text-2xl text-[#f8f8ff] ` } > < / i >
< div className = "text-sm font-bold text-[#f8f8ff]" > { promo . category } < / d i v >
< / d i v >
< h4 className = "text-white font-semibold" > { promo . title } < / h 4 >
< / d i v >
) ) }
< / d i v >
) : (
promotions . map ( ( promo ) => (
< div
key = { promo . id }
2024-10-03 15:21:22 -05:00
className = { ` space-evenly cursor-pointer transition-colors duration-200 hover:bg-gray-700 ${ selectedPromotion . id === promo . id ? "bg-gray-700" : "bg-gray-800"
2024-09-30 12:59:19 -05:00
} p - 4 rounded - lg shadow - lg ` }
2024-09-14 18:05:59 -05:00
onClick = { ( ) => setSelectedPromotion ( promo ) } >
< div className = "flex items-center gap-2" >
2024-10-03 14:03:18 -05:00
< i className = { ` ${ promo . icon } text-xl text-[#f8f8ff] ` } > < / i >
< div className = "font-semibold text-[#f8f8ff]" > { promo . category } < / d i v >
2024-09-14 18:05:59 -05:00
< / d i v >
2024-10-03 14:03:18 -05:00
< h4 className = "text-white" > { promo . title } < / h 4 >
2024-09-14 18:05:59 -05:00
< / d i v >
) )
) }
2024-10-03 16:37:08 -05:00
{ isTabView ? (
// todo: turn this into a stepper for multiple messages
< div className = { ` ${ isMobile ? "min-w-full" : "w-[529px]" } flex flex-col bg-gray-800 p-4 rounded-lg shadow-lg ` } >
2024-10-03 15:21:22 -05:00
< p > Welcome ! 👋 < / p >
< p > Plebdevs is open source software and is still in early development . If you have any questions drop an issue on the Github repo , or reach out to me in the Community tab , cheers ! - < span className = "italic" > Austin < / s p a n > < / p >
< div className = "flex flex-wrap gap-4 justify-center mt-2" >
< i
className = "pi pi-github text-gray-300 cursor-pointer text-xl hover:opacity-80"
2024-10-04 15:09:26 -05:00
onClick = { ( ) => window . open ( 'https://github.com/austinkelsay/plebdevs' , '_blank' ) }
2024-10-03 15:21:22 -05:00
title = "Github"
/ >
< i
className = "pi pi-twitter text-blue-400 rounded-full cursor-pointer text-xl hover:opacity-80"
onClick = { ( ) => window . open ( 'https://x.com/pleb_devs' , '_blank' ) }
title = "X"
/ >
< Image
src = { NostrIcon }
alt = "Nostr"
width = { 22 }
height = { 22 }
className = "cursor-pointer hover:opacity-80"
onClick = { ( ) => window . open ( 'https://nostr.com/plebdevs@plebdevs.com' , '_blank' ) }
title = "Nostr"
/ >
< i
className = "pi pi-bolt text-yellow-400 cursor-pointer text-xl hover:opacity-80"
onClick = { ( ) => copyToClipboard ( "austin@bitcoinpleb.dev" ) }
title = "Donate"
/ >
< / d i v >
< / d i v >
) : (
< div className = "flex flex-col bg-gray-800 p-4 rounded-lg shadow-lg" >
< p > Welcome ! 👋 < / p >
< p > Plebdevs is open source software and is still in early development . If you have any questions drop an issue on the Github repo , or reach out to me in the Community tab , cheers ! - < span className = "italic" > Austin < / s p a n > < / p >
< div className = "flex flex-wrap gap-4 justify-center mt-2" >
< i
className = "pi pi-github text-gray-300 cursor-pointer text-xl hover:opacity-80"
2024-10-04 15:09:26 -05:00
onClick = { ( ) => window . open ( 'https://github.com/austinkelsay/plebdevs' , '_blank' ) }
2024-10-03 15:21:22 -05:00
title = "Github"
/ >
< i
className = "pi pi-twitter text-blue-400 rounded-full cursor-pointer text-xl hover:opacity-80"
onClick = { ( ) => window . open ( 'https://x.com/pleb_devs' , '_blank' ) }
title = "X"
/ >
< Image
src = { NostrIcon }
alt = "Nostr"
width = { 22 }
height = { 22 }
className = "cursor-pointer hover:opacity-80"
onClick = { ( ) => window . open ( 'https://nostr.com/plebdevs@plebdevs.com' , '_blank' ) }
title = "Nostr"
/ >
< i
className = "pi pi-bolt text-yellow-400 cursor-pointer text-xl hover:opacity-80"
onClick = { ( ) => copyToClipboard ( "austin@bitcoinpleb.dev" ) }
title = "Donate"
/ >
< / d i v >
2024-10-03 14:03:18 -05:00
< / d i v >
2024-10-03 15:21:22 -05:00
) }
2024-09-14 18:05:59 -05:00
< / d i v >
< / d i v >
) ;
}
export default InteractivePromotionalCarousel ;