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 15:53:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e09d3b2285847e0f6f03e6440916fbbbbd7c8e55
e09d3b22
1 parent
d9740a5a
Add new feature, search
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
src/api/post/post.js
src/pages/search.js
src/api/post/post.js
View file @
e09d3b2
...
...
@@ -71,4 +71,14 @@ export const createComment = async (id, content) => {
throw
new
Error
(
'Failed to create comment!'
);
}
return
response
.
data
;
}
export
const
searchPost
=
async
(
search
)
=>
{
const
response
=
await
axios
.
post
(
`
${
SERVER_BASE_URL
}
/post/search/`
,
{
search
,
});
if
(
response
.
status
!==
200
&&
response
.
status
!==
201
)
{
throw
new
Error
(
'Failed to get posts!'
);
}
return
response
.
data
;
}
\ No newline at end of file
...
...
src/pages/search.js
0 → 100644
View file @
e09d3b2
import
{
searchPost
}
from
"../api/post/post"
;
import
{
useState
}
from
"react"
;
export
default
function
Search
()
{
const
handleSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
const
search
=
await
searchPost
(
e
.
target
.
search
.
value
);
console
.
log
(
search
)
setResult
(
search
);
}
const
[
result
,
setResult
]
=
useState
([]);
return
(
<
div
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
input
name
=
"search"
id
=
"search"
placeholder
=
"Search Something..."
><
/input
>
<
button
type
=
"submit"
>
Search
<
/button
>
<
/form
>
<
div
>
<
h1
>
Search
Result
<
/h1
>
{
result
.
map
((
post
)
=>
{
return
(
<
div
>
<
h2
>
{
post
.
title
}
<
/h2
>
<
/div
>
)
})}
<
/div
>
<
/div
>
);
}
\ No newline at end of file
Please
register
or
login
to post a comment