Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// "use client"
// import { Prisma } from "@prisma/client";
// import { useRouter } from "next/navigation";
// import { startTransition } from "react";
// import { Icons } from "./icons";
// import { Button } from "./ui/button";
// type likeType = Prisma.LikeUncheckedCreateInput
// type postType = Prisma.PostUncheckedCreateInput
// type commentType = Prisma.CommentUncheckedCreateInput
// // type commentWithLikes = Prisma.CommentGetPayload<typeof commentWithPosts>
// export default function LikeButton(props: { data: any }) {
// const router = useRouter();
// const likeCount = props.data.Like.length
// // const likeCount = countLikes(likeArray, props.data);
// async function postLike(e: any) {
// e.preventDefault()
// const postLikeData = props.data;
// const likeData = {} as likeType
// if (postLikeData.postId == undefined) {
// likeData.postId = postLikeData.id!
// } else {
// likeData.postId = postLikeData.postId
// likeData.commentId = postLikeData.id
// }
// likeData.userId = postLikeData.userId
// const response = await fetch('/api/likes', {
// method: 'PUT',
// body: JSON.stringify(likeData)
// })
// startTransition(() => {
// // Refresh the current route and fetch new data from the server without
// // losing client-side browser or React state.
// router.refresh();
// });
// return await response.json()
// }
// return (
// <form onSubmit={postLike}>
// <Button type="submit" variant="ghost" size="lg" className="px-6 py-3" >
// <span className="pr-1">{likeCount}</span>
// <Icons.heart className="h-5 w-5" />
// </Button>
// </form>
// )
// }
// function countLikes(likeArray: any, msg: any): number {
// let likeCount = 0;
// if (msg.postId == undefined) {
// likeArray.forEach(function (like: any) {
// if (like.postId == undefined) {
// likeCount++;
// }
// })
// } else {
// likeArray.forEach(function (like: any) {
// if (like.postId != undefined) {
// likeCount++;
// }
// })
// }
// return likeCount;
// }