Skip to content

Commit 8c867d8

Browse files
realtime: Add footer channel to www application (supabase#36707)
Co-authored-by: Ivan Vasilov <[email protected]>
1 parent 9765a70 commit 8c867d8

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

apps/www/components/Footer/index.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { CheckIcon } from '@heroicons/react/outline'
2+
import { REALTIME_CHANNEL_STATES } from '@supabase/supabase-js'
23
import Image from 'next/image'
34
import Link from 'next/link'
45
import { useRouter } from 'next/router'
5-
import { Badge, IconDiscord, IconGitHubSolid, IconTwitterX, IconYoutubeSolid, cn } from 'ui'
6-
import SectionContainer from '../Layouts/SectionContainer'
6+
import { useEffect } from 'react'
77

88
import * as supabaseLogoWordmarkDark from 'common/assets/images/supabase-logo-wordmark--dark.png'
99
import * as supabaseLogoWordmarkLight from 'common/assets/images/supabase-logo-wordmark--light.png'
1010
import footerData from 'data/Footer'
11+
import { Badge, IconDiscord, IconGitHubSolid, IconTwitterX, IconYoutubeSolid, cn } from 'ui'
1112
import { ThemeToggle } from 'ui-patterns/ThemeToggle'
13+
import supabase from '~/lib/supabase'
1214
import useDarkLaunchWeeks from '../../hooks/useDarkLaunchWeeks'
15+
import SectionContainer from '../Layouts/SectionContainer'
1316

1417
interface Props {
1518
className?: string
@@ -23,6 +26,24 @@ const Footer = (props: Props) => {
2326
const isGAWeek = pathname.includes('/ga-week')
2427
const forceDark = isDarkLaunchWeek
2528

29+
useEffect(() => {
30+
const channel = supabase.channel('footer')
31+
if (channel.state === REALTIME_CHANNEL_STATES.closed) {
32+
channel.subscribe((status: string) => {
33+
if (status == 'SUBSCRIBED') {
34+
channel.send({
35+
type: 'broadcast',
36+
event: 'footer_subscribed',
37+
payload: { ts: Date.now() },
38+
})
39+
}
40+
})
41+
}
42+
return () => {
43+
channel.unsubscribe()
44+
}
45+
}, [])
46+
2647
if (props.hideFooter) {
2748
return null
2849
}

0 commit comments

Comments
 (0)