Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Testing out supabase #50

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@mdx-js/react": "^1.6.18",
"@next/bundle-analyzer": "^9.5.3",
"@prefresh/next": "^1.3.0",
"@supabase/supabase-js": "^1.21.0",
"@tailwindcss/jit": "^0.1.1",
"autotrack": "^2.4.1",
"cross-env": "^7.0.3",
Expand Down
33 changes: 32 additions & 1 deletion src/components/Blog/Post/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect } from 'react';
import { useEffect, useLayoutEffect, useState } from 'react';
import { spring } from 'react-flip-toolkit';
import tinytime from 'tinytime';
import { useRouter } from 'next/router';
Expand All @@ -11,8 +11,10 @@ import { HorizontalDivider } from '@/components/Divider';
import { LazyWebmentionWidget } from '@/components/Webmention/LazyWebmentionWidget';
import { IOWrapper } from '@/components/IntersectionObserver/Wrapper';
import { useShouldAnimateNavigation } from '@/contexts/navigation';
import { supabase } from '@/utils/supabase';

import { PostHeader } from './PostHeader';
import { PostLikesCount, PostUserLikes } from '../../../../types/supabase';

const mdxComponents = {
pre: ({ className, ...props }: any) => (
Expand Down Expand Up @@ -40,6 +42,7 @@ interface Props {
export default function Post({ meta, children, posts }: Props) {
const router = useRouter();
const postIndex = posts.findIndex((post) => post.link === router.pathname);
const post = posts[postIndex]
const previous = posts[postIndex + 1];
const next = posts[postIndex - 1];
const fullUrl = `${publicUrl}${router.pathname}`;
Expand Down Expand Up @@ -67,6 +70,30 @@ export default function Post({ meta, children, posts }: Props) {
}
}, [shouldAnimateNavigation]);

const [likesCount, setLikesCount] = useState(0)

useEffect(() => {
(async () => {
const { data } = await supabase.from<PostLikesCount>('post_likes_count').select('likes_count').eq('post_slug', post.link)

console.log({ data })
})()
}, [])

const addLikesCount = async () => {
console.log(await supabase.from<PostLikesCount>('post_likes_count').upsert({
likes_count: 1,
post_slug: post.link
}))
console.log(await supabase.from<PostUserLikes>('post_user_likes').upsert({
id: 'testing-id',
likes_count: 1,
post_slug: post.link
}))

setLikesCount(prev => prev + 1)
}

return (
<article>
<PageMetaTags
Expand All @@ -91,6 +118,10 @@ export default function Post({ meta, children, posts }: Props) {
show ? <LazyWebmentionWidget url={fullUrl} meta={meta} /> : null
}
</IOWrapper>
<div>
<div>Likes: {likesCount}</div>
<button onClick={addLikesCount}>+1</button>
</div>
</div>
<footer className="text-sm font-medium leading-5 xl:col-start-1 xl:row-start-2">
{(next || previous) && (
Expand Down
6 changes: 6 additions & 0 deletions src/utils/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || ''
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || ''

export const supabase = createClient(supabaseUrl, supabaseAnonKey)
16 changes: 16 additions & 0 deletions types/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This file contains the types for data from supabase
*/

export type PostLikesCount = {
post_slug: string
likes_count: number
}

export type PostUserLikes = {
// `id` will be a generated id used to identify user's session
// Each `id` can only add a maximum of 10 likes
id: string
post_slug: string
likes_count: number
}
101 changes: 101 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,45 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@supabase/gotrue-js@^1.17.0":
version "1.17.0"
resolved "https://registry.yarnpkg.com/@supabase/gotrue-js/-/gotrue-js-1.17.0.tgz#0ff46f844ddd124543d2769da8eda58ab479b49b"
integrity sha512-c+GSSoW+PIT3/r7TnBdc4gPjtWDutO/2ROafSKUFl39Pb8aHIUbUvzK9sjuedaaLKH7bV8VefuRy2L8c0BUAzg==
dependencies:
cross-fetch "^3.0.6"

"@supabase/postgrest-js@^0.33.0":
version "0.33.0"
resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-0.33.0.tgz#36e0bfd0f79a0fa01a4bb7c7881ee463fd7d60a8"
integrity sha512-og6Evdkan7Qp6+tOch7Pyq+ZWMnrCQtPHWwPpsN5A3iYQSro2yn21Yvazs9qAFoWAeTGNkuTOVpShT5Mbc9WcQ==
dependencies:
cross-fetch "^3.0.6"

"@supabase/realtime-js@^1.1.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-1.1.2.tgz#6bdb0411df292c9d6a2d1a5a4e11c2673aec5f76"
integrity sha512-YNFiWF0T9+IuZZgswzHbGb7/O1eWJSwXvi0WlbARHTIcYBu4GQQXBdVWdFdG4bTLMS3L4K2qHpvMP91QYSasMw==
dependencies:
"@types/websocket" "^1.0.3"
websocket "^1.0.34"

"@supabase/storage-js@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@supabase/storage-js/-/storage-js-1.4.0.tgz#0692782ccaf10df27d539d9349031ed87c7ec426"
integrity sha512-7+SGyXOgdhtz8qHzXo64HiS66PT/y4F8YFNMtXqYOu1LjHh0YwtOgpPLDA8obiSsNVwZiKwpgBJkz4LHG1YvRQ==
dependencies:
cross-fetch "^3.1.0"

"@supabase/supabase-js@^1.21.0":
version "1.21.0"
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-1.21.0.tgz#7fe3575a41644048ecbe2ed6eba89e830959d47b"
integrity sha512-SJgRQCdHRpnnuXVCb7X8XA/u2S4oo1Jdn92eLBl0QaUKGhREFHk2x4XlJZA9bJNzAhby9eQZ56FCtBrUda2CRQ==
dependencies:
"@supabase/gotrue-js" "^1.17.0"
"@supabase/postgrest-js" "^0.33.0"
"@supabase/realtime-js" "^1.1.1"
"@supabase/storage-js" "^1.4.0"

"@surma/rollup-plugin-off-main-thread@^1.1.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.1.tgz#bf1343e5a926e5a1da55e3affd761dda4ce143ef"
Expand Down Expand Up @@ -1320,6 +1359,13 @@
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.3.tgz#fb602cd4c2f0b7c0fb857e922075fdf677d25d84"
integrity sha512-5oiXqR7kwDGZ6+gmzIO2lTC+QsriNuQXZDWNYRV3l2XRN/zmPgnC21DLSx2D05zvD8vnXW6qUg7JnXZ4I6qLVQ==

"@types/websocket@^1.0.3":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@types/websocket/-/websocket-1.0.4.tgz#1dc497280d8049a5450854dd698ee7e6ea9e60b8"
integrity sha512-qn1LkcFEKK8RPp459jkjzsfpbsx36BBt3oC3pITYtkoBw/aVX+EZFa5j3ThCRTNpLFvIMr5dSTD4RaMdilIOpA==
dependencies:
"@types/node" "*"

"@typescript-eslint/eslint-plugin@^2.19.2":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9"
Expand Down Expand Up @@ -2221,6 +2267,13 @@ buffer@^5.5.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

bufferutil@^4.0.1:
version "4.0.3"
resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b"
integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==
dependencies:
node-gyp-build "^4.2.0"

builtin-modules@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-2.0.0.tgz#60b7ef5ae6546bd7deefa74b08b62a43a232648e"
Expand Down Expand Up @@ -2779,6 +2832,13 @@ [email protected]:
dependencies:
node-fetch "2.6.1"

cross-fetch@^3.0.6, cross-fetch@^3.1.0:
version "3.1.4"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.4.tgz#9723f3a3a247bf8b89039f3a380a9244e8fa2f39"
integrity sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==
dependencies:
node-fetch "2.6.1"

cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand Down Expand Up @@ -4822,6 +4882,11 @@ is-symbol@^1.0.2:
dependencies:
has-symbols "^1.0.1"

is-typedarray@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=

is-whitespace-character@^1.0.0:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-whitespace-character/-/is-whitespace-character-1.0.4.tgz#0858edd94a95594c7c9dd0b5c174ec6e45ee4aa7"
Expand Down Expand Up @@ -5621,6 +5686,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-gyp-build@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==

[email protected]:
version "1.4.9"
resolved "https://registry.yarnpkg.com/node-html-parser/-/node-html-parser-1.4.9.tgz#3c8f6cac46479fae5800725edb532e9ae8fd816c"
Expand Down Expand Up @@ -8296,6 +8366,13 @@ type@^2.0.0:
resolved "https://registry.yarnpkg.com/type/-/type-2.5.0.tgz#0a2e78c2e77907b252abe5f298c1b01c63f0db3d"
integrity sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
integrity sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==
dependencies:
is-typedarray "^1.0.0"

typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
Expand Down Expand Up @@ -8512,6 +8589,13 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

utf-8-validate@^5.0.2:
version "5.0.5"
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.5.tgz#dd32c2e82c72002dc9f02eb67ba6761f43456ca1"
integrity sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==
dependencies:
node-gyp-build "^4.2.0"

util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down Expand Up @@ -8708,6 +8792,18 @@ [email protected]:
watchpack "^1.7.4"
webpack-sources "^1.4.1"

websocket@^1.0.34:
version "1.0.34"
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111"
integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==
dependencies:
bufferutil "^4.0.1"
debug "^2.2.0"
es5-ext "^0.10.50"
typedarray-to-buffer "^3.1.5"
utf-8-validate "^5.0.2"
yaeti "^0.0.6"

whatwg-url@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06"
Expand Down Expand Up @@ -8954,6 +9050,11 @@ y18n@^4.0.0:
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==

yaeti@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/yaeti/-/yaeti-0.0.6.tgz#f26f484d72684cf42bedfb76970aa1608fbf9577"
integrity sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=

yallist@^3.0.2:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
Expand Down