sungjin

Add full support for difficulty pages.

1 +import { Link } from "@nextui-org/react";
2 +import { getPostsByDifficulty } from "../../api/post";
3 +import { useState } from "react";
4 +import { useEffect } from "react";
5 +import { useRouter } from "next/router";
6 +
7 +export default function Popular() {
8 + const [posts, setPosts] = useState([]);
9 + const router = useRouter();
10 + useEffect(() => {
11 + getPostsByDifficulty(3).then(setPosts);
12 + }, []);
13 +
14 + const DateType = (date) => {
15 + console.log(date);
16 + const dateObj = new Date(date);
17 + const month = dateObj.toLocaleString("default", { month: "long" });
18 + const day = dateObj.getDate();
19 + const year = dateObj.getFullYear();
20 + return dateObj.toLocaleString();
21 + }
22 + return (
23 + <div className="ml-10 mr-10">
24 + <ul>
25 + {posts.map(post => (
26 + <li key={post.id}>
27 + <a onClick={() => router.push(`/post/${post.id}`)} className="cursor-pointer transition
28 + duration-100 transform hover:text-white text-2xl">
29 + {post.title}
30 + </a>
31 + <span className="float-right">{DateType(post.createdAt)}</span>
32 + </li>
33 + ))}
34 + </ul>
35 + </div>
36 + );
37 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,20 +2,33 @@ import { Link } from "@nextui-org/react"; ...@@ -2,20 +2,33 @@ import { Link } from "@nextui-org/react";
2 import { getPostsByDifficulty } from "../../api/post"; 2 import { getPostsByDifficulty } from "../../api/post";
3 import { useState } from "react"; 3 import { useState } from "react";
4 import { useEffect } from "react"; 4 import { useEffect } from "react";
5 +import { useRouter } from "next/router";
5 6
6 export default function Popular() { 7 export default function Popular() {
7 const [posts, setPosts] = useState([]); 8 const [posts, setPosts] = useState([]);
9 + const router = useRouter();
8 useEffect(() => { 10 useEffect(() => {
9 getPostsByDifficulty(1).then(setPosts); 11 getPostsByDifficulty(1).then(setPosts);
10 }, []); 12 }, []);
13 +
14 + const DateType = (date) => {
15 + console.log(date);
16 + const dateObj = new Date(date);
17 + const month = dateObj.toLocaleString("default", { month: "long" });
18 + const day = dateObj.getDate();
19 + const year = dateObj.getFullYear();
20 + return dateObj.toLocaleString();
21 + }
11 return ( 22 return (
12 - <div> 23 + <div className="ml-10 mr-10">
13 <ul> 24 <ul>
14 {posts.map(post => ( 25 {posts.map(post => (
15 <li key={post.id}> 26 <li key={post.id}>
16 - <Link href={`/post/${post.id}`}> 27 + <a onClick={() => router.push(`/post/${post.id}`)} className="cursor-pointer transition
17 - <a>{post.title}</a> 28 + duration-100 transform hover:text-white text-2xl">
18 - </Link> 29 + {post.title}
30 + </a>
31 + <span className="float-right">{DateType(post.createdAt)}</span>
19 </li> 32 </li>
20 ))} 33 ))}
21 </ul> 34 </ul>
......
...@@ -2,20 +2,33 @@ import { Link } from "@nextui-org/react"; ...@@ -2,20 +2,33 @@ import { Link } from "@nextui-org/react";
2 import { getPostsByDifficulty } from "../../api/post"; 2 import { getPostsByDifficulty } from "../../api/post";
3 import { useState } from "react"; 3 import { useState } from "react";
4 import { useEffect } from "react"; 4 import { useEffect } from "react";
5 +import { useRouter } from "next/router";
5 6
6 export default function Popular() { 7 export default function Popular() {
7 const [posts, setPosts] = useState([]); 8 const [posts, setPosts] = useState([]);
9 + const router = useRouter();
8 useEffect(() => { 10 useEffect(() => {
9 getPostsByDifficulty(2).then(setPosts); 11 getPostsByDifficulty(2).then(setPosts);
10 }, []); 12 }, []);
13 +
14 + const DateType = (date) => {
15 + console.log(date);
16 + const dateObj = new Date(date);
17 + const month = dateObj.toLocaleString("default", { month: "long" });
18 + const day = dateObj.getDate();
19 + const year = dateObj.getFullYear();
20 + return dateObj.toLocaleString();
21 + }
11 return ( 22 return (
12 - <div> 23 + <div className="ml-10 mr-10">
13 <ul> 24 <ul>
14 {posts.map(post => ( 25 {posts.map(post => (
15 <li key={post.id}> 26 <li key={post.id}>
16 - <Link href={`/post/${post.id}`}> 27 + <a onClick={() => router.push(`/post/${post.id}`)} className="cursor-pointer transition
17 - <a>{post.title}</a> 28 + duration-100 transform hover:text-white text-2xl">
18 - </Link> 29 + {post.title}
30 + </a>
31 + <span className="float-right">{DateType(post.createdAt)}</span>
19 </li> 32 </li>
20 ))} 33 ))}
21 </ul> 34 </ul>
......
1 import * as auth from "../api/auth"; 1 import * as auth from "../api/auth";
2 -import push from "next/router"; 2 +import { useRouter } from "next/router";
3 3
4 export default function Signup() { 4 export default function Signup() {
5 +
6 + const router = useRouter();
7 +
5 return ( 8 return (
6 - <div> 9 + <div className="flex h-auto">
7 - <h1>Signup</h1> 10 + <div className="w-auto inline-block p-3 rounded-lg m-auto">
11 + <h1 className="font-bold text-4xl text-center">회원가입</h1>
8 <form onSubmit={handleSubmit}> 12 <form onSubmit={handleSubmit}>
9 - <label htmlFor="name">Name</label> 13 + <input type="email" id="email" placeholder="email" className="my-2 rounded-sm" />
10 - <input type="text" id="name" />
11 <br /> 14 <br />
12 - <label htmlFor="email">Email</label> 15 + <input type="text" id="name" placeholder="nickname" className="my-2 rounded-sm" />
13 - <input type="email" id="email" />
14 <br /> 16 <br />
15 - <label htmlFor="password">Password</label> 17 + <input type="password" id="password" className="my-2 rounded-sm" placeholder="password" />
16 - <input type="password" id="password" />
17 <br /> 18 <br />
18 - <label htmlFor="password-confirm">Confirm Password</label> 19 + <input type="password" id="passwordConfirm" className="my-2 rounded-sm" placeholder="password confirm" />
19 - <input type="password" id="password-confirm" />
20 <br /> 20 <br />
21 - <button type="submit">Signup</button> 21 + <button type="submit" className="mt-2 px-4 py-2 text-base font-semibold text-white transition duration-500 transform bg-blue-300 rounded-lg hover:shadow-lg focus:bg-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-300 focus:ring-offset-2 focus:ring-offset-blue-300 motion-reduce:transform-none hover:scale-105 tramsform">Signup</button>
22 </form> 22 </form>
23 </div> 23 </div>
24 + </div>
25 +
24 ); 26 );
25 -}
26 27
27 -function handleSubmit(event) { 28 + async function handleSubmit(event) {
28 event.preventDefault(); 29 event.preventDefault();
29 const form = event.target; 30 const form = event.target;
30 const name = form.name.value; 31 const name = form.name.value;
...@@ -36,12 +37,14 @@ function handleSubmit(event) { ...@@ -36,12 +37,14 @@ function handleSubmit(event) {
36 alert("Passwords do not match"); 37 alert("Passwords do not match");
37 return; 38 return;
38 } 39 }
39 - const signup = auth.signup(name, email, password); 40 + const signup = await auth.signup(name, email, password);
40 - if(!signup) { 41 + if (!signup) {
41 alert("Signup failed"); 42 alert("Signup failed");
42 } 43 }
43 else { 44 else {
44 alert("Signup success"); 45 alert("Signup success");
45 - return push("/"); 46 + return router.push("/");
47 + }
46 } 48 }
47 } 49 }
50 +
......