Skip to content

Commit b4db0ac

Browse files
committed
chore(fe): hooks
1 parent d65da82 commit b4db0ac

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

spez-frontend/.eslintrc.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2-
"extends": ["next/core-web-vitals", "next/typescript"]
3-
2+
"extends": ["next/core-web-vitals", "next/typescript"],
3+
"rules": {
4+
"@typescript-eslint/no-unused-vars": "off"
5+
}
46
}

spez-frontend/src/app/post/[id]/page.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import Parser from 'html-react-parser'
66
import CmtForm from "@/components/CmtForm";
77
import { getRelativeTime } from "@/utils/getRelativeTime";
88
import { GoTrash } from "react-icons/go";
9-
import { IPost, IComment } from "@/types";
9+
// import { IPost, IComment } from "@/types";
10+
import { IComment } from "@/types";
1011
import LikeButton from "@/components/LikeButton";
1112
// import svLike from "@/services/svLike";
1213
import { useEffect, useState } from "react";
@@ -18,6 +19,7 @@ type Props = {
1819
};
1920
export default function Post({ params }: Props) {
2021
const id: string = params.id;
22+
/* eslint-enable @typescript-eslint/no-unused-vars */
2123
const {post, isLoadingInfo} = usePost(id)
2224
const {Comments, isLoadingComments} = useComments(id)
2325
const {Likes, isLoadingLikes} = useLikes(id)
@@ -29,6 +31,8 @@ export default function Post({ params }: Props) {
2931
token = localStorage.getItem('jwt')
3032
await delPost(id, token);
3133
}
34+
const Cmts: IComment[] = Comments as IComment[]
35+
// console.log(post)
3236
return (
3337
<>
3438
<div className="w-full p-8 flex flex-col justify-center items-center space-y-2">
@@ -51,7 +55,8 @@ export default function Post({ params }: Props) {
5155
</div>
5256
<div className="border-2 border-slate-950 p-2 text-black rounded shadow h-full w-1/2 space-y-5">
5357
<a className="font-bold text-2xl">Bình Loạn</a>
54-
{Comments?.map((element: IComment) => (
58+
{/* {
59+
Cmts?.map((element: IComment) => (
5560
<Comment
5661
key={element.id}
5762
id = {element.id}
@@ -61,7 +66,7 @@ export default function Post({ params }: Props) {
6166
updated_at= {element.updated_at}
6267
post_id= {element.post_id}
6368
/>
64-
))}
69+
))} */}
6570
</div>
6671
</div>
6772
</>

spez-frontend/src/components/Comment.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Link from "next/link";
33
import Parser from "html-react-parser";
44
import { GoTrash } from "react-icons/go";
55
import { IComment } from "@/types";
6-
import svCmt from "@/services/svCmt";
6+
import {svCmt} from "@/services/svCmt";
77

88
export default async function Comment({id, author, content, created_at}: IComment) {
99
const usr_url = "/user/" + author.id;

spez-frontend/src/components/LikeButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useState } from "react";
44
import Image from "next/image";
55
import EagleEmoji from "../../public/eagle_emoji.png";
6-
import svLike from "@/services/svLike";
6+
import {svLike} from "@/services/svLike";
77
interface LikeButtonProps {
88
initialLikes: number | null;
99
post_id: string

spez-frontend/src/components/LoginForm.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function LoginForm() {
2020
const body = new URLSearchParams();
2121
body.append('username', username);
2222
body.append('password', password);
23-
console.log(body)
23+
// console.log(body)
2424
// API call to authenticate using x-www-form-urlencoded
2525
try {
2626
const res = await authenticate(body.toString())
@@ -33,7 +33,7 @@ export default function LoginForm() {
3333

3434
const data = await res.json();
3535
// Assuming the API returns the JWT token in the response
36-
console.log(data)
36+
// console.log(data)
3737
if (data.access_token) {
3838
// Store JWT in localStorage (or cookies for security-sensitive applications)
3939
localStorage.setItem('jwt', data.access_token);

spez-frontend/src/hooks/useComments.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import useSWR from "swr"
22
import { getComments } from "@/services/svCmt"
3+
// import { IComment } from "@/types"
34
const useComments = (id: string) => {
45

56
const {data, isLoading } = useSWR(id, getComments)

spez-frontend/src/services/svLike.ts

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ export const svLike = () => {
2121
})
2222
}
2323

24-
async function getLike(id: string) {
25-
const data = await axios.get(API.like + "/post/" + id, {
26-
headers: {
27-
accept: "application/json",
28-
},
29-
});
30-
return data.data;
31-
}
3224
return {
3325
postLike,
3426
delLike,

0 commit comments

Comments
 (0)