Toggle navigation
Toggle navigation
This project
Loading...
Sign in
엄성진
/
Learn_In_Web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sungjin
2021-12-05 17:49:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
acbc4105b359d834a64a0a60031c4992d5e1fd0c
acbc4105
1 parent
d9740a5a
Add Like Post full service
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
src/api/index.js
src/api/post/post.js
src/pages/post/[id].js
src/api/index.js
View file @
acbc410
export
const
SERVER_BASE_URL
=
'https://do.sungjin.dev'
;
\ No newline at end of file
//export const SERVER_BASE_URL = 'https://do.sungjin.dev';
export
const
SERVER_BASE_URL
=
"http://localhost:4000"
;
\ No newline at end of file
...
...
src/api/post/post.js
View file @
acbc410
...
...
@@ -71,4 +71,17 @@ export const createComment = async (id, content) => {
throw
new
Error
(
'Failed to create comment!'
);
}
return
response
.
data
;
}
export
const
likePost
=
async
(
id
)
=>
{
if
(
!
await
auth
.
validateToken
())
{
throw
alert
(
"Please login first."
);
}
const
response
=
await
axios
.
post
(
`
${
SERVER_BASE_URL
}
/post/like/
${
id
}
`
,
{
token
:
auth
.
getToken
(),
});
if
(
response
.
status
!==
200
&&
response
.
status
!==
201
)
{
throw
new
Error
(
'Failed to like post!'
);
}
return
response
.
data
;
}
\ No newline at end of file
...
...
src/pages/post/[id].js
View file @
acbc410
...
...
@@ -7,6 +7,8 @@ import { Button } from "semantic-ui-react";
import
{
run
}
from
"../../api/runner"
;
import
{
useSession
}
from
"next-auth/client"
;
import
SyntaxHighlighter
from
'react-syntax-highlighter'
;
import
{
ThumbUpIcon
}
from
"@heroicons/react/solid"
;
import
{
likePost
}
from
"../../api/post"
;
const
CodeEditor
=
dynamic
(
()
=>
import
(
"@uiw/react-textarea-code-editor"
).
then
((
mod
)
=>
mod
.
default
),
...
...
@@ -70,6 +72,16 @@ export default function Post() {
setAnswer
(
`출력 :
${
result
}
`
);
}
const
like
=
async
()
=>
{
if
(
useSession
.
accessToken
==
null
)
{
alert
(
"You need to login first!"
)
router
.
push
(
"/login"
)
return
;
}
const
{
id
}
=
router
.
query
setPost
(
await
likePost
(
id
));
}
return
(
<
div
className
=
"ml-10 mr-10"
>
<
h3
className
=
"text-3xl font-bold"
>
{
post
.
title
}
<
/h3
>
...
...
@@ -102,7 +114,14 @@ export default function Post() {
/>
<
/div
>
<
div
className
=
"w-6/12 inline-block align-top"
>
{
post
.
explain
}
<
/div
>
<
div
className
=
"w-6/12 inline-block align-top"
>
<
div
className
=
"w-full"
>
{
post
.
explain
}
<
/div
>
<
Button
className
=
"bg-blue-500 rounded-full p-1 text-white "
onClick
=
{
like
}
>
<
ThumbUpIcon
className
=
"h-5 inline-block mb-1 "
><
/ThumbUpIcon
>
<
span
>
{
` Likes :
${
post
.
likes
}
`
}
<
/span
>
<
/Button
>
<
/div
>
<
Button
onClick
=
{
runCode
}
className
=
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Run
<
/Button
>
<
div
className
=
""
>
{
answer
}
<
/div
>
<
details
>
...
...
Please
register
or
login
to post a comment