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 21:45:14 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
dbb765f55d1b9a42e30665a2026a2a3aabf52c80
dbb765f5
2 parents
d3a0ca36
5dee7418
Merge search feature to master
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
src/api/post/post.js
src/components/Header.js
src/pages/search.js
src/api/post/post.js
View file @
dbb765f
...
...
@@ -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/components/Header.js
View file @
dbb765f
...
...
@@ -2,7 +2,7 @@ import {
HomeIcon
,
SearchIcon
,
UserIcon
,
Cube
Icon
,
Terminal
Icon
,
MailIcon
,
StarIcon
}
from
"@heroicons/react/outline"
...
...
@@ -17,13 +17,13 @@ function Header() {
<
header
className
=
"flex flex-col sm:flex-row m-5 mt-0 pt-5 justify-between items-center"
>
<
Link
href
=
"/"
passHref
>
<
div
className
=
"flex cursor-pointer transform hover:scale-105"
>
<
Cube
Icon
className
=
"h-20"
/>
<
Terminal
Icon
className
=
"h-20"
/>
<
p
className
=
"text-7xl font-extrabold"
>
Learn
In
Web
<
/p
>
<
/div></
Link
>
<
div
className
=
"flex flex-grow justify-evenly max-w-sm"
>
<
HeaderItem
title
=
'HOME'
Icon
=
{
HomeIcon
}
link
=
"/"
/>
<
HeaderItem
title
=
'STAR'
Icon
=
{
StarIcon
}
link
=
"/"
/>
<
HeaderItem
title
=
'SEARCH'
Icon
=
{
SearchIcon
}
link
=
"/"
/>
<
HeaderItem
title
=
'SEARCH'
Icon
=
{
SearchIcon
}
link
=
"/
search/
"
/>
<
HeaderItem
title
=
'ACCOUNT'
Icon
=
{
UserIcon
}
link
=
"/"
/>
<
Islogin
/>
<
/div
>
...
...
src/pages/search.js
0 → 100644
View file @
dbb765f
import
{
searchPost
}
from
"../api/post/post"
;
import
{
useState
}
from
"react"
;
import
{
SearchIcon
}
from
"@heroicons/react/outline"
;
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
className
=
" ml-10 mr-10"
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
input
name
=
"search"
id
=
"search"
placeholder
=
"Search Something..."
className
=
"w-[90%] h-10 text-xl"
><
/input
>
<
button
type
=
"submit"
>
<
SearchIcon
className
=
"h-10 ml-2 -mb-3 rounded-full border-black border-2 p-1"
/>
<
/button
>
<
/form
>
<
div
>
<
h1
className
=
"text-2xl font-bold"
>
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