Skip to content

Commit 8d0bc02

Browse files
committed
chore(fe/lint): fix run lint
1 parent e7d6f12 commit 8d0bc02

File tree

9 files changed

+52
-44
lines changed

9 files changed

+52
-44
lines changed

spez-frontend/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
22
"extends": ["next/core-web-vitals", "next/typescript"]
3+
34
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ export default async function Post({ params }: Props) {
2828
e.preventDefault();
2929
try {
3030
// Send a POST request to your FastAPI backend
31-
let token: string | null
31+
let token: string | null = null
3232
if (typeof window !== 'undefined')
3333
token = localStorage.getItem('jwt')
3434
await axios.post(`http://localhost:8000/likes/?post_id=${id}`,
3535
{
3636
headers: {
3737
'accept': 'application/json',
38+
/* eslint-disable @typescript-eslint/no-use-before-define */
3839
'Authorization': `Bearer ${token}`
3940
}
4041
}
@@ -48,7 +49,7 @@ export default async function Post({ params }: Props) {
4849
}
4950
};
5051
const handleDelPost = async () => {
51-
let token: string | null
52+
let token: string | null = null
5253
if (typeof window !== 'undefined')
5354
token = localStorage.getItem('jwt')
5455
const deletePost:string = await delPost(id, token);
+40-33
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
1-
2-
"use client"
3-
import React, { useState } from 'react';
1+
"use client";
2+
import React, { useState } from "react";
43
// import dynamic from 'next/dynamic';
5-
import SunEditor from 'suneditor-react';
6-
import 'suneditor/dist/css/suneditor.min.css';
7-
import axios from 'axios';
8-
import { useRouter } from 'next/navigation';
4+
import SunEditor from "suneditor-react";
5+
import "suneditor/dist/css/suneditor.min.css";
6+
import axios from "axios";
7+
import { useRouter } from "next/navigation";
98

109
// Dynamically import SunEditor to avoid SSR issues
1110
// const DynamicSunEditor = dynamic(() => import('suneditor-react'), {
1211
// ssr: false,
1312
// });
1413

1514
type Props = {
16-
postId: string
17-
}
18-
export default function CmtForm ({postId}: Props) {
19-
const [content, setContent] = useState<string>('');
15+
postId: string;
16+
};
17+
export default function CmtForm({ postId }: Props) {
18+
const [content, setContent] = useState<string>("");
2019
const router = useRouter();
2120

2221
// Handle form submission
2322
const handleSubmit = async (e: React.FormEvent) => {
2423
e.preventDefault();
2524
try {
2625
// Send a POST request to your FastAPI backend
27-
let token: string | null
28-
if (typeof window !== 'undefined')
29-
token = localStorage.getItem('jwt')
30-
if(token === undefined)
31-
router.push('/')
26+
let token: string | null = null;
27+
if (typeof window !== "undefined") token = localStorage.getItem("jwt");
28+
if (token === undefined) router.push("/");
3229
// console.log(token)
33-
await axios.post(`http://localhost:8000/posts/cmt/${postId}`,
30+
await axios.post(
31+
`http://localhost:8000/posts/cmt/${postId}`,
3432
{
35-
36-
content: content,
37-
},
38-
{
39-
headers: {
40-
'accept': 'application/json',
41-
'Authorization': `Bearer ${token}`
33+
content: content,
34+
},
35+
{
36+
headers: {
37+
accept: "application/json",
38+
Authorization: `Bearer ${token}`,
39+
},
4240
}
43-
}
44-
);
41+
);
4542

4643
// Redirect or give feedback upon success
47-
alert('Post created successfully!');
44+
alert("Post created successfully!");
4845
} catch (error) {
49-
console.error('Error posting data:', error);
50-
alert('Failed to create post.');
46+
console.error("Error posting data:", error);
47+
alert("Failed to create post.");
5148
}
5249
};
5350

@@ -63,17 +60,27 @@ export default function CmtForm ({postId}: Props) {
6360
setOptions={{
6461
height: "200",
6562
buttonList: [
66-
['formatBlock', 'bold', 'underline', 'italic', 'list', 'link', 'image'],
63+
[
64+
"formatBlock",
65+
"bold",
66+
"underline",
67+
"italic",
68+
"list",
69+
"link",
70+
"image",
71+
],
6772
],
6873
}}
6974
/>
7075
</div>
7176

72-
<button type="submit" className="bg-blue-500 text-white px-4 py-1 rounded-full left-2/3">
77+
<button
78+
type="submit"
79+
className="bg-blue-500 text-white px-4 py-1 rounded-full left-2/3"
80+
>
7381
Tạo bình loạn
7482
</button>
7583
</form>
7684
</div>
7785
);
78-
};
79-
86+
}

spez-frontend/src/components/Comment.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default async function Comment({id, author, content, created_at}: ICommen
99
const usr_url = "/user/" + author.id;
1010
const { delComment } = await svPost();
1111
const handleDelCmt = async () => {
12-
let token: string | null;
12+
let token: string | null = null;
1313
if (typeof window !== "undefined") token = localStorage.getItem("jwt");
1414
await delComment(id, token);
1515
};

spez-frontend/src/components/ImgUpload.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function ImageUploader({ userId }: ImgUploadProps) {
2323

2424
const handleSubmit = async () => {
2525
try {
26-
let token: string | null
26+
let token: string | null = null
2727
if (typeof window !== undefined) token = localStorage.getItem("jwt");
2828
const response = await updUsrProfile(userId, token, base64Image);
2929
const data = await response.json();

spez-frontend/src/components/LoginForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function LoginForm() {
88
const [username, setUsername] = useState<string>("");
99
const [password, setPassword] = useState<string>("");
1010
const [showPassword, setShowPassword] = useState<boolean | null>(false);
11-
const [isLoading, setIsLoading] = useState<boolean | null>(false);
11+
const [isLoading, setIsLoading] = useState<boolean | undefined>(false);
1212
const [error, setError] = useState("");
1313
const togglePasswordVisibility = () => {
1414
setShowPassword((prev: boolean | null) => !prev);

spez-frontend/src/components/PostForm.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ export default function PostForm () {
2222

2323
try {
2424
// Send a POST request to your FastAPI backend
25-
let token: string | null
25+
let token: string | null = null
2626
if (typeof window !== 'undefined')
2727
token = localStorage.getItem('jwt')
2828
if(token === undefined)
2929
router.push('/')
30-
console.log(token)
3130
await axios.post('http://localhost:8000/posts/',
3231
{
3332

spez-frontend/src/utils/svPost.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export default function svPost() {
2424
});
2525
return data.data;
2626
}
27-
async function delPost(id: string, token: string) {
27+
async function delPost(id: string, token: string | null) {
2828
const data = await axios.delete(API.post + id, {
2929
headers: {
3030
accept: "application/json",
3131
Authorization: `Bearer ${token}`,
3232
},
3333
});
34-
return data;
34+
return data.data;
3535
}
3636
async function getLike(id: string) {
3737
const data = await axios.get(API.like + "/post/" + id, {
@@ -49,7 +49,7 @@ export default function svPost() {
4949
});
5050
return data.data;
5151
}
52-
async function delComment(id: string, token: string) {
52+
async function delComment(id: string, token: string | null) {
5353
const data = await axios.delete(BE_URI + "/comments/" + id, {
5454
headers: {
5555
accept: "application/json",

spez-frontend/src/utils/svUser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function svUser() {
2222
});
2323
return data.data;
2424
}
25-
async function updUsrProfile(id: string, token: string, imgBase64: string) {
25+
async function updUsrProfile(id: string, token: string | null, imgBase64: string | null) {
2626
const data = await axios.put(
2727
API.usr + id + "/profile",
2828
{

0 commit comments

Comments
 (0)