diff --git a/app/actions/comments.ts b/app/actions/comments.ts
index bd7b8b0..bb893d2 100644
--- a/app/actions/comments.ts
+++ b/app/actions/comments.ts
@@ -9,10 +9,10 @@ export async function loginWithGitHub() {
await signIn('github')
}
-const notificationBody = (comment: { id: number, content: string }, user: { name: string }) => {
+const notificationBody = (comment: { id: number, content: string }, user: { name: string }, article: { title: string }) => {
return {
- topic: 'comments',
- message: `You've got a new comment from ${user.name}:\n${comment.content}`,
+ topic: 'portfolio',
+ message: `New comment on ${article.title} from ${user.name}:\n${comment.content}`,
actions: [
{
action: 'http',
@@ -60,7 +60,7 @@ export async function addComment(prevState: { message: string }, formData: FormD
const [{data: user}, {data: article}] = await Promise.all([
supabase.from('users').upsert({name, email, image}, {onConflict: 'email'}).select('*').single(),
- supabase.from('articles').select('id').eq('slug', slug).single()
+ supabase.from('articles').select('*').eq('slug', slug).single()
])
const {data: newComment, error} = await supabase
@@ -73,7 +73,7 @@ export async function addComment(prevState: { message: string }, formData: FormD
return {message: general_error}
}
- await sendNotification(notificationBody(newComment, user))
+ await sendNotification(notificationBody(newComment, user, article))
return {message: success_message}
} catch (error) {
diff --git a/app/actions/views.ts b/app/actions/views.ts
index 5e16019..571cff5 100644
--- a/app/actions/views.ts
+++ b/app/actions/views.ts
@@ -2,9 +2,9 @@
import {createClient} from '@/lib/supabase/server'
-export async function incrementViews(slug: string) {
- if (slug !== null) {
+export async function incrementViews(slug: string, title: string) {
+ if (slug !== null && title !== null) {
const supabase = await createClient()
- await supabase.rpc('increment_views', {param_slug: slug})
+ await supabase.rpc('increment_views', {param_slug: slug, param_title: title})
}
}
\ No newline at end of file
diff --git a/app/api/comments/moderate/[id]/route.ts b/app/api/comments/moderate/[id]/route.ts
index 5519ff8..955126d 100644
--- a/app/api/comments/moderate/[id]/route.ts
+++ b/app/api/comments/moderate/[id]/route.ts
@@ -14,7 +14,7 @@ export async function PATCH(request: Request, {params}: { params: Promise<{ id:
.update({published: true})
.eq('id', id)
- return new Response(null, {status: 204})
+ return new Response(JSON.stringify({}), {status: 200})
}
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
}
diff --git a/app/page.tsx b/app/page.tsx
index b160252..4dfab76 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -49,6 +49,7 @@ function Article(article: Article) {