From d5c320c88a6ad58cb50c4022c7867a001d5489f0 Mon Sep 17 00:00:00 2001 From: r-freeman Date: Mon, 10 Apr 2023 23:25:29 +0100 Subject: [PATCH] Updated views component and supabase client --- components/ui/Views.tsx | 5 +++-- lib/supabase.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/ui/Views.tsx b/components/ui/Views.tsx index 9394a99..8da7fed 100644 --- a/components/ui/Views.tsx +++ b/components/ui/Views.tsx @@ -16,6 +16,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView const [views, setViews] = useState(0) useEffect(() => { + // subscribe to view updates at the row level const sub = supabase .channel('any') .on('postgres_changes', { @@ -26,7 +27,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView }, payload => { setViews(payload.new.views) }) - .subscribe(); + .subscribe() return () => { sub.unsubscribe() @@ -51,7 +52,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView method: 'POST' } ) - }; + } registerView() } diff --git a/lib/supabase.ts b/lib/supabase.ts index c4fa992..d2492ae 100644 --- a/lib/supabase.ts +++ b/lib/supabase.ts @@ -1,6 +1,9 @@ import {createClient} from '@supabase/supabase-js' +const NEXT_PUBLIC_SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL ?? "" +const NEXT_PUBLIC_SUPABASE_ANON_KEY = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? "" + export const supabase = createClient( - process.env.NEXT_PUBLIC_SUPABASE_URL ?? "", - process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? "" + NEXT_PUBLIC_SUPABASE_URL, + NEXT_PUBLIC_SUPABASE_ANON_KEY ) \ No newline at end of file