Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
f21493ca
Commit
f21493ca
authored
Aug 15, 2022
by
Lee Soobeom
Browse files
board
parent
a6e57583
Changes
1
Show whitespace changes
Inline
Side-by-side
frontend/src/board/board.tsx
View file @
f21493ca
...
@@ -17,6 +17,7 @@ export default function BoardPage() {
...
@@ -17,6 +17,7 @@ export default function BoardPage() {
const
[
posts
,
setPosts
]
=
useState
<
PostType
[]
>
();
const
[
posts
,
setPosts
]
=
useState
<
PostType
[]
>
();
const
location
=
useLocation
()
as
Newpost
;
const
location
=
useLocation
()
as
Newpost
;
const
newPost
=
location
.
state
;
const
newPost
=
location
.
state
;
const
deletePostId
=
location
.
state
.
_id
;
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
{
user
}
=
useAuth
();
const
{
user
}
=
useAuth
();
...
@@ -34,17 +35,17 @@ export default function BoardPage() {
...
@@ -34,17 +35,17 @@ export default function BoardPage() {
setNewPosts
(
newPost
);
setNewPosts
(
newPost
);
},
[]);
},
[]);
// posts
const
getDataList
=
async
()
=>
{
const
getDataList
=
async
()
=>
{
const
res
=
await
postApi
.
getData
();
const
res
=
await
postApi
.
getData
();
setPosts
(
res
);
//posts = res
setPosts
(
res
);
//posts = res
};
};
const
titleHandleClick
=
async
(
event
:
MouseEvent
<
HTMLButtonElement
>
)
=>
{
const
deletePost
=
async
(
postId
:
string
)
=>
{
if
(
!
user
.
isLoggedIn
)
{
const
res
=
await
postApi
.
deletePost
(
postId
);
alert
(
"
로그인이 필요합니다.
"
);
return
res
;
navigate
(
"
/login
"
,
{
replace
:
true
});
};
}
else
{
const
handleClick
=
async
(
event
:
MouseEvent
<
HTMLButtonElement
>
)
=>
{
const
postId
=
event
.
currentTarget
.
id
;
const
postId
=
event
.
currentTarget
.
id
;
const
newpost
=
posts
?.
find
((
element
)
=>
{
const
newpost
=
posts
?.
find
((
element
)
=>
{
if
(
element
.
_id
===
postId
)
{
if
(
element
.
_id
===
postId
)
{
...
@@ -55,8 +56,7 @@ export default function BoardPage() {
...
@@ -55,8 +56,7 @@ export default function BoardPage() {
const
post
=
newpost
;
const
post
=
newpost
;
const
res
=
await
postApi
.
addCounts
(
post
.
_id
,
post
.
counts
);
const
res
=
await
postApi
.
addCounts
(
post
.
_id
,
post
.
counts
);
// console.log(res);
// console.log(res);
setPosts
(
res
);
// setPosts(res);
}
}
}
};
};
...
@@ -94,7 +94,7 @@ export default function BoardPage() {
...
@@ -94,7 +94,7 @@ export default function BoardPage() {
</
div
>
</
div
>
<
div
>
<
div
>
{
posts
?.
map
((
post
,
i
)
=>
(
{
posts
?.
map
((
post
,
i
)
=>
(
<
Post
key
=
{
i
}
post
=
{
post
}
handleClick
=
{
titleH
andleClick
}
/>
<
Post
key
=
{
i
}
post
=
{
post
}
handleClick
=
{
h
andleClick
}
/>
))
}
))
}
</
div
>
</
div
>
</
div
>
</
div
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment