sungjin

Add Runner Test without Post

1 node_modules 1 node_modules
2 -a.out 2 +.next
3 -tmp.c
4 -
......
1 module.exports = { 1 module.exports = {
2 reactStrictMode: true, 2 reactStrictMode: true,
3 } 3 }
4 +const removeImports = require("next-remove-imports")();
5 +module.exports = removeImports({
6 + experimental: { esmExternals: true }
7 +});
...\ No newline at end of file ...\ No newline at end of file
......
This diff could not be displayed because it is too large.
...@@ -9,9 +9,12 @@ ...@@ -9,9 +9,12 @@
9 }, 9 },
10 "dependencies": { 10 "dependencies": {
11 "@heroicons/react": "^1.0.5", 11 "@heroicons/react": "^1.0.5",
12 + "@nextui-org/react": "^1.0.1-alpha.57",
13 + "@uiw/react-textarea-code-editor": "^1.4.4",
12 "axios": "^0.24.0", 14 "axios": "^0.24.0",
13 "next": "12.0.4", 15 "next": "12.0.4",
14 "next-auth": "^3.29.0", 16 "next-auth": "^3.29.0",
17 + "next-remove-imports": "^1.0.6",
15 "react": "17.0.2", 18 "react": "17.0.2",
16 "react-dom": "17.0.2", 19 "react-dom": "17.0.2",
17 "semantic-ui-react": "^2.0.4", 20 "semantic-ui-react": "^2.0.4",
...@@ -22,6 +25,7 @@ ...@@ -22,6 +25,7 @@
22 "eslint": "7.32.0", 25 "eslint": "7.32.0",
23 "eslint-config-next": "12.0.4", 26 "eslint-config-next": "12.0.4",
24 "postcss": "^8.3.11", 27 "postcss": "^8.3.11",
28 + "react-syntax-highlighter": "^15.4.5",
25 "tailwindcss": "^2.2.19" 29 "tailwindcss": "^2.2.19"
26 } 30 }
27 } 31 }
......
...@@ -13,6 +13,7 @@ export const login = async (email, password) => { ...@@ -13,6 +13,7 @@ export const login = async (email, password) => {
13 } 13 }
14 console.log(response.data.access_token) 14 console.log(response.data.access_token)
15 useSession.accessToken = response.data.access_token; 15 useSession.accessToken = response.data.access_token;
16 + console.log("로그인" + useSession.accessToken);
16 return response.data; 17 return response.data;
17 } 18 }
18 19
...@@ -56,6 +57,7 @@ export const refreshToken = async () => { ...@@ -56,6 +57,7 @@ export const refreshToken = async () => {
56 } 57 }
57 58
58 export const validateToken = async () => { 59 export const validateToken = async () => {
60 + console.log(useSession.accessToken);
59 const response = await axios.post(`${SERVER_BASE_URL}/auth/validate`, { 61 const response = await axios.post(`${SERVER_BASE_URL}/auth/validate`, {
60 token: useSession.accessToken, 62 token: useSession.accessToken,
61 }); 63 });
......
...@@ -19,7 +19,7 @@ export const newPost = async (title, content, privat) => { ...@@ -19,7 +19,7 @@ export const newPost = async (title, content, privat) => {
19 } 19 }
20 20
21 export const getPostbyId = async (id) => { 21 export const getPostbyId = async (id) => {
22 - const response = await axios.get(`${SERVERBASE_URL}/post/${id}`); 22 + const response = await axios.get(`${SERVER_BASE_URL}/post/${id}`);
23 if (response.status !== 200) { 23 if (response.status !== 200) {
24 throw new Error('Failed to get post!'); 24 throw new Error('Failed to get post!');
25 } 25 }
......
1 +export * from './runner'
...\ No newline at end of file ...\ No newline at end of file
1 +import * as auth from '../auth';
2 +import axios from 'axios';
3 +import { SERVER_BASE_URL } from '..';
4 +import { useRouter } from 'next/dist/client/router';
5 +import { useSession } from 'next-auth/client';
6 +
7 +export const run = async (code, type) => {
8 + if (!auth.validateToken()) {
9 + throw new Error("plz login");
10 + }
11 + const response = await axios.post(`${SERVER_BASE_URL}/runner`, {
12 + token: auth.getToken(),
13 + code,
14 + type,
15 + input: '',
16 + });
17 + return response.data.output;
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +import { Link } from "@nextui-org/react"
1 import router from "next/router" 2 import router from "next/router"
3 +import { Button } from "semantic-ui-react"
2 4
3 export default function Nav() { 5 export default function Nav() {
6 + const moverun = () => {
7 + router.push("/run")
8 + }
4 return ( 9 return (
5 <nav className="navbar"> 10 <nav className="navbar">
6 <div className="flex px-10 sm:px-20 text-2xl whitespace-nowrap 11 <div className="flex px-10 sm:px-20 text-2xl whitespace-nowrap
...@@ -8,6 +13,9 @@ export default function Nav() { ...@@ -8,6 +13,9 @@ export default function Nav() {
8 <a herf="" className="last:pr-24 cursor-pointer transition 13 <a herf="" className="last:pr-24 cursor-pointer transition
9 duration-100 transform hover:scale-125 hover:text-white 14 duration-100 transform hover:scale-125 hover:text-white
10 active:text-blue-500">난이도 </a> 15 active:text-blue-500">난이도 </a>
16 + <Button onClick={moverun} className="cursor-pointer transition
17 + duration-100 transform hover:scale-125 hover:text-white
18 + active:text-blue-500">실행하기</Button>
11 <a herf="" className="last:pr-24 cursor-pointer transition 19 <a herf="" className="last:pr-24 cursor-pointer transition
12 duration-100 transform hover:scale-125 hover:text-white 20 duration-100 transform hover:scale-125 hover:text-white
13 active:text-blue-500">난이도 </a> 21 active:text-blue-500">난이도 </a>
......
1 import { useRouter } from "next/dist/client/router" 1 import { useRouter } from "next/dist/client/router"
2 import { getPostbyId } from "../../api/post" 2 import { getPostbyId } from "../../api/post"
3 +import "@uiw/react-textarea-code-editor/dist.css";
4 +import dynamic from "next/dynamic";
5 +import { useState } from "react";
6 +import { Button } from "semantic-ui-react";
3 7
8 +const CodeEditor = dynamic(
9 + () => import("@uiw/react-textarea-code-editor").then((mod) => mod.default),
10 + { ssr: false }
11 +);
4 12
5 export default function Post() { 13 export default function Post() {
6 const router = useRouter() 14 const router = useRouter()
7 const { id } = router.query 15 const { id } = router.query
8 const post = getPostbyId(id) 16 const post = getPostbyId(id)
17 +
18 + const [value, setValue] = useState("c");
19 +
20 + const [code, setCode] = useState("");
21 +
22 + const runCode = () => {
23 + Runner.run(code, value);
24 + }
25 +
9 return ( 26 return (
10 <div> 27 <div>
11 <p>{post.title}</p> 28 <p>{post.title}</p>
12 <p>{post.body}</p> 29 <p>{post.body}</p>
30 + <select value={value} onChange={(e) => setValue(e.target.value)}>
31 + <option value="c">c</option>
32 + <option value="cpp">cpp</option>
33 + <option value="js">javascript</option>
34 + </select>
35 + <CodeEditor
36 + value={code}
37 + language={value}
38 + placeholder="Please Enter the Code."
39 + onChange={(e) => setCode(e.target.value)}
40 + padding={15}
41 + style={{
42 + fontSize: 12,
43 + backgroundColor: "#f5f5f5",
44 + fontFamily:
45 + "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace"
46 + }}
47 + />
48 + <Button onClick={runCode}>Run</Button>
13 </div> 49 </div>
14 ) 50 )
15 } 51 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +import "@uiw/react-textarea-code-editor/dist.css";
2 +import dynamic from "next/dynamic";
3 +import { useState } from "react";
4 +import { Button } from "semantic-ui-react";
5 +import { run } from "../api/runner/runner";
6 +import { useRouter } from "next/dist/client/router";
7 +
8 +const CodeEditor = dynamic(
9 + () => import("@uiw/react-textarea-code-editor").then((mod) => mod.default),
10 + { ssr: false }
11 +);
12 +
13 +export default function Run() {
14 + const router = useRouter();
15 +
16 + const [value, setValue] = useState("c");
17 +
18 + const [code, setCode] = useState("");
19 +
20 + const [answer, setAnswer] = useState("");
21 +
22 + const runCode = async function () {
23 + var result = await run(code, value);
24 + console.log(result);
25 + setAnswer(result);
26 + }
27 +
28 + return (<div>
29 + <select value={value} onChange={(e) => setValue(e.target.value)}>
30 + <option value="c">c</option>
31 + <option value="cpp">cpp</option>
32 + <option value="js">javascript</option>
33 + </select>
34 + <CodeEditor
35 + value={code}
36 + language={value}
37 + placeholder="Please Enter the Code."
38 + onChange={(e) => setCode(e.target.value)}
39 + padding={15}
40 + style={{
41 + fontSize: 12,
42 + backgroundColor: "#f5f5f5",
43 + fontFamily:
44 + "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace"
45 + }}
46 + />
47 + <Button onClick={runCode}>Run</Button>
48 + <div>{answer}</div>
49 + </div>);
50 +}
...\ No newline at end of file ...\ No newline at end of file