Skip to content

Commit

Permalink
Fix handlePostSave function to use string for
Browse files Browse the repository at this point in the history
postId
  • Loading branch information
thebkht committed Nov 20, 2023
1 parent 26f55e0 commit db71229
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
42 changes: 21 additions & 21 deletions components/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ import postgres from "@/lib/postgres"
import { getSessionUser } from "./get-session-user"
import { revalidatePath } from "next/cache"

export const handlePostSave = async ({ postId, path} : {postId: number, path: string}) => {
export const handlePostSave = async ({ postId, path} : {postId: string, path: string}) => {
const sessionUser = await getSessionUser()
if (!sessionUser) {
console.log("No session user")
}
console.log(path, postId)
try {
const saved = await postgres.bookmark.findFirst({
where: {
postId,
userId: Number(sessionUser?.id)
userId: sessionUser?.id
}
})

if (saved) {
await postgres.bookmark.delete({
where: {
id: saved.id
}
})
console.log("unsaved")
} else {
await postgres.bookmark.create({
data: {
userId: Number(sessionUser?.id),
postId
}
})
console.log("saved")
}

revalidatePath(path)
if (sessionUser?.id) {
if (saved) {
await postgres.bookmark.delete({
where: {
id: saved.id
}
})
console.log("unsaved")
} else {
await postgres.bookmark.create({
data: {
userId: sessionUser.id,
postId
}
})
}

revalidatePath(path)
}
} catch (error) {
console.log(error)
}
Expand Down
7 changes: 5 additions & 2 deletions components/markdown-card.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @next/next/no-img-element */
import { PreBlock } from "@/lib/syntax"
import Markdown from "markdown-to-jsx"

Expand All @@ -9,11 +10,13 @@ export default function MarkdownCard({ code }: { code: string }) {
pre: PreBlock,
img: {
component: (props: any) => {
return (
return props.title ? (
<figure>
<img {...props} className="!relative w-full" />
<img {...props} className="!relative w-full" alt={props.alt} />
<figcaption className="text-center text-sm text-muted">{props.title}</figcaption>
</figure>
) : (
<img {...props} className="!relative w-full" alt={props.alt} />
)
}
},
Expand Down

0 comments on commit db71229

Please sign in to comment.