sungjin

Add full support comment, with some design

...@@ -66,6 +66,9 @@ export const refreshToken = async () => { ...@@ -66,6 +66,9 @@ export const refreshToken = async () => {
66 66
67 export const validateToken = async () => { 67 export const validateToken = async () => {
68 console.log(useSession.accessToken); 68 console.log(useSession.accessToken);
69 + if(useSession.accessToken == undefined){
70 + return false;
71 + }
69 const response = await axios.post(`${SERVER_BASE_URL}/auth/validate`, { 72 const response = await axios.post(`${SERVER_BASE_URL}/auth/validate`, {
70 token: useSession.accessToken, 73 token: useSession.accessToken,
71 }).catch(err => { 74 }).catch(err => {
......
...@@ -12,7 +12,7 @@ export const newPost = async ( ...@@ -12,7 +12,7 @@ export const newPost = async (
12 difficulty, 12 difficulty,
13 ) => { 13 ) => {
14 if (!auth.validateToken()) { 14 if (!auth.validateToken()) {
15 - throw new Error("plz login"); 15 + throw alert("Please login first.");
16 } 16 }
17 const response = await axios.post(`${SERVER_BASE_URL}/post`, { 17 const response = await axios.post(`${SERVER_BASE_URL}/post`, {
18 token: auth.getToken(), 18 token: auth.getToken(),
...@@ -60,6 +60,9 @@ export const getPostsByDifficulty = async (difficulty) => { ...@@ -60,6 +60,9 @@ export const getPostsByDifficulty = async (difficulty) => {
60 } 60 }
61 61
62 export const createComment = async (id, content) => { 62 export const createComment = async (id, content) => {
63 + if (!await auth.validateToken()) {
64 + throw alert("Please login first.");
65 + }
63 const response = await axios.post(`${SERVER_BASE_URL}/post/comment/${id}`, { 66 const response = await axios.post(`${SERVER_BASE_URL}/post/comment/${id}`, {
64 token : useSession.accessToken, 67 token : useSession.accessToken,
65 content, 68 content,
......
...@@ -6,7 +6,7 @@ import { useSession } from 'next-auth/client'; ...@@ -6,7 +6,7 @@ import { useSession } from 'next-auth/client';
6 6
7 export const run = async (code, type) => { 7 export const run = async (code, type) => {
8 if (!auth.validateToken()) { 8 if (!auth.validateToken()) {
9 - throw new Error("plz login"); 9 + throw alert("Please login first.");
10 } 10 }
11 const response = await axios.post(`${SERVER_BASE_URL}/runner`, { 11 const response = await axios.post(`${SERVER_BASE_URL}/runner`, {
12 token: auth.getToken(), 12 token: auth.getToken(),
......
...@@ -26,7 +26,7 @@ export default function Popular() { ...@@ -26,7 +26,7 @@ export default function Popular() {
26 <li key={post.id}> 26 <li key={post.id}>
27 <a onClick={() => router.push(`/post/${post.id}`)} className="cursor-pointer transition 27 <a onClick={() => router.push(`/post/${post.id}`)} className="cursor-pointer transition
28 duration-100 transform hover:text-white text-2xl"> 28 duration-100 transform hover:text-white text-2xl">
29 - <a>{post.title}</a> 29 + {post.title}
30 </a> 30 </a>
31 <span className="float-right">{DateType(post.createdAt)}</span> 31 <span className="float-right">{DateType(post.createdAt)}</span>
32 </li> 32 </li>
......
...@@ -11,7 +11,7 @@ export default function Home() { ...@@ -11,7 +11,7 @@ export default function Home() {
11 <link rel="icon" href="/favicon.ico" /> 11 <link rel="icon" href="/favicon.ico" />
12 </Head> 12 </Head>
13 {/* 기본 컨텐츠 */} 13 {/* 기본 컨텐츠 */}
14 - <div className='ui container fixed left-10'> 14 + <div className='ui container relative left-10'>
15 <h3 className="text-3xl font-bold">인기 문제</h3> 15 <h3 className="text-3xl font-bold">인기 문제</h3>
16 <Popular /> 16 <Popular />
17 </div> 17 </div>
......
...@@ -7,7 +7,7 @@ export default function Login() { ...@@ -7,7 +7,7 @@ export default function Login() {
7 7
8 return ( 8 return (
9 <div className="flex h-auto"> 9 <div className="flex h-auto">
10 - <div className="w-auto inline-block p-3 bg-black rounded-lg m-auto"> 10 + <div className="w-auto inline-block p-3 rounded-lg m-auto">
11 <h1 className="font-bold text-4xl text-center">로그인</h1> 11 <h1 className="font-bold text-4xl text-center">로그인</h1>
12 <form onSubmit={handleSubmit}> 12 <form onSubmit={handleSubmit}>
13 <input type="email" id="email" placeholder="email" className="my-2 rounded-sm"/> 13 <input type="email" id="email" placeholder="email" className="my-2 rounded-sm"/>
......
...@@ -36,22 +36,24 @@ export default function Post() { ...@@ -36,22 +36,24 @@ export default function Post() {
36 const [comment, setComment] = useState(""); 36 const [comment, setComment] = useState("");
37 37
38 const addComment = async () => { 38 const addComment = async () => {
39 + console.log("comment is " + comment);
39 const { id } = router.query 40 const { id } = router.query
40 - const response = await createComment(id, comment) 41 + await createComment(id, comment)
41 } 42 }
42 43
43 const displayComment = () => { 44 const displayComment = () => {
44 console.log(post.comments); 45 console.log(post.comments);
45 if (post.comments != undefined) { 46 if (post.comments != undefined) {
46 return post.comments.map(comment => ( 47 return post.comments.map(comment => (
47 - <div className="w-full"> 48 + <div className="flex w-full border-carbon border-4 rounded-xl my-2">
48 - <div className="w-full flex justify-between"> 49 + <div className="w-full justify-between">
49 - <div className="w-1/2"> 50 + <div className=" mx-2">
50 - <span className="text-gray-700">{comment.username}</span> 51 + <p className="text-black w-[90%]">{comment.content}</p>
52 + <span className="text-black float-right">{`작성자 : ${comment.author.name}`}</span>
51 </div> 53 </div>
52 </div> 54 </div>
53 - </div>) 55 + </div>
54 - ) 56 + ));
55 } 57 }
56 return <div></div> 58 return <div></div>
57 } 59 }
......