mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 19:45:40 +00:00
Updated views component and supabase client
This commit is contained in:
parent
ec833fbe22
commit
d5c320c88a
@ -16,6 +16,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView
|
|||||||
const [views, setViews] = useState(0)
|
const [views, setViews] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// subscribe to view updates at the row level
|
||||||
const sub = supabase
|
const sub = supabase
|
||||||
.channel('any')
|
.channel('any')
|
||||||
.on('postgres_changes', {
|
.on('postgres_changes', {
|
||||||
@ -26,7 +27,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView
|
|||||||
}, payload => {
|
}, payload => {
|
||||||
setViews(payload.new.views)
|
setViews(payload.new.views)
|
||||||
})
|
})
|
||||||
.subscribe();
|
.subscribe()
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
sub.unsubscribe()
|
sub.unsubscribe()
|
||||||
@ -51,7 +52,7 @@ export function Views({as: Component = 'span', slug, className, shouldUpdateView
|
|||||||
method: 'POST'
|
method: 'POST'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
registerView()
|
registerView()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import {createClient} from '@supabase/supabase-js'
|
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(
|
export const supabase = createClient(
|
||||||
process.env.NEXT_PUBLIC_SUPABASE_URL ?? "",
|
NEXT_PUBLIC_SUPABASE_URL,
|
||||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? ""
|
NEXT_PUBLIC_SUPABASE_ANON_KEY
|
||||||
)
|
)
|
Loading…
Reference in New Issue
Block a user