From cd0a7edadc31889a2ff421c76d616062e367835f Mon Sep 17 00:00:00 2001 From: Francesco Sansalvadore Date: Wed, 2 Aug 2023 08:47:02 +0200 Subject: [PATCH] lw8: add meetups section --- .../components/LaunchWeek/8/LW8Meetups.tsx | 111 ++++++++++++++++++ apps/www/pages/launch-week/index.tsx | 14 ++- .../pages/launch-week/tickets/[username].tsx | 2 +- apps/www/pages/launch-week/tickets/index.tsx | 2 +- 4 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 apps/www/components/LaunchWeek/8/LW8Meetups.tsx diff --git a/apps/www/components/LaunchWeek/8/LW8Meetups.tsx b/apps/www/components/LaunchWeek/8/LW8Meetups.tsx new file mode 100644 index 00000000000..dbcce1ec01c --- /dev/null +++ b/apps/www/components/LaunchWeek/8/LW8Meetups.tsx @@ -0,0 +1,111 @@ +import Link from 'next/link' +import React, { useEffect, useState } from 'react' +import { Badge } from 'ui' +import useConfData from '../hooks/use-conf-data' + +export interface Meetup { + id?: any + title: string + isLive: boolean + link: string + display_info: string + start_at: string +} + +const LW8Meetups = ({ meetups }: { meetups?: Meetup[] }) => { + const { supabase } = useConfData() + const [meets, setMeets] = useState(meetups ?? []) + const [realtimeChannel, setRealtimeChannel] = useState | null>(null) + + useEffect(() => { + // Listen to realtime changes + if (supabase && !realtimeChannel) { + const channel = supabase + .channel('changes') + .on( + 'postgres_changes', + { + event: 'UPDATE', + schema: 'public', + table: 'lw8_meetups', + }, + async () => { + const { data: newMeets, error } = await supabase.from('lw8_meetups').select('*') + console.log('newMeets error', error) + console.log('newMeets', newMeets) + setMeets(newMeets) + } + ) + .subscribe() + setRealtimeChannel(channel) + } + + return () => { + // Cleanup realtime subscription on unmount + realtimeChannel?.unsubscribe() + } + }, []) + + useEffect(() => { + console.log('meetups', meets) + }, [meets]) + + return ( +
+
+

Join us live

+

+ Celebrate LW8 with us at our first-ever live meetups across various locations. Join the + fun, grab some swag, and be a part of the Supabase community. +

+
+
+ {meets && + meets + ?.sort((a, b) => (new Date(a.start_at) > new Date(b.start_at) ? 1 : -1)) + .map(({ display_info, link, isLive, title }: Meetup) => ( + + +
+ {title} + {isLive && Live now} + + + + + +
+ {display_info && ( + {display_info} + )} +
+ + ))} +
+
+ ) +} + +export default LW8Meetups diff --git a/apps/www/pages/launch-week/index.tsx b/apps/www/pages/launch-week/index.tsx index a44ac87bf85..4b41360d683 100644 --- a/apps/www/pages/launch-week/index.tsx +++ b/apps/www/pages/launch-week/index.tsx @@ -11,6 +11,7 @@ import { PageState, ConfDataContext, UserData } from '~/components/LaunchWeek/ho import DefaultLayout from '~/components/Layouts/Default' import SectionContainer from '~/components/Layouts/SectionContainer' import { LaunchWeekLogoHeader } from '~/components/LaunchWeek/8/LaunchWeekLogoHeader' +import { Meetup } from '~/components/LaunchWeek/8/LW8Meetups' import { useTheme } from 'common/Providers' @@ -21,6 +22,7 @@ const AnimatedParticles = dynamic( () => import('~/components/LaunchWeek/8/AnimatedParticles/ParticlesCanvas') ) const TicketContainer = dynamic(() => import('~/components/LaunchWeek/8/Ticket/TicketContainer')) +const LW8Meetups = dynamic(() => import('~/components/LaunchWeek/8/LW8Meetups')) const LaunchWeekPrizeSection = dynamic( () => import('~/components/LaunchWeek/8/LaunchWeekPrizeSection') ) @@ -29,6 +31,7 @@ const CTABanner = dynamic(() => import('~/components/CTABanner')) interface Props { users?: UserData[] + meetups?: Meetup[] } const supabaseAdmin = createClient( @@ -39,7 +42,7 @@ const supabaseAdmin = createClient( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9idWxkYW5ycHRsb2t0eGNmZnZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk3MjcwMTIsImV4cCI6MTk4NTMwMzAxMn0.SZLqryz_-stF8dgzeVXmzZWPOqdOrBwqJROlFES8v3I' ) -export default function TicketHome({ users }: Props) { +export default function TicketHome({ users, meetups }: Props) { const { query } = useRouter() const TITLE = 'Supabase LaunchWeek 8' @@ -149,7 +152,7 @@ export default function TicketHome({ users }: Props) { /> -
+
+ + + +
{supabase && (
@@ -191,9 +198,12 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { .from('lw8_tickets_golden') .select('username, golden', { count: 'exact' }) + const { data: meetups } = await supabaseAdmin!.from('lw8_meetups').select('*') + return { props: { users, + meetups, }, } } diff --git a/apps/www/pages/launch-week/tickets/[username].tsx b/apps/www/pages/launch-week/tickets/[username].tsx index 37808e679e4..0aa62979f24 100644 --- a/apps/www/pages/launch-week/tickets/[username].tsx +++ b/apps/www/pages/launch-week/tickets/[username].tsx @@ -114,7 +114,7 @@ export default function UsernamePage({ user, users, ogImageUrl }: Props) { )}
-
+
-
+