Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
feat: 게시글 상세 페이지 (#7 #5 #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunolike committed Jan 18, 2023
1 parent 06f6966 commit 0a41b55
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
39 changes: 39 additions & 0 deletions src/controllers/detail.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import views from '../views/detail/detail.html'
import Axios from 'axios';

export default () => {
const divElement = document.createElement('div');
divElement.classList = "detail-section";
divElement.innerHTML = views;

const postId = localStorage.getItem('postId');
const API_URL = 'http://43.201.103.199/post/' + postId;

Axios.get(API_URL).then((res) => {
console.log(res.data.data)
let detail = res.data.data;

divElement.querySelector("#detail-img").innerHTML = `
<img src=${detail.post.image} style="width: 200px" />
`
divElement.querySelector("#detail-title").innerHTML = `
${detail.post.title}
`
divElement.querySelector("#detail-date").innerHTML = `
${detail.post.updatedAt.substr(0,9)}
`
divElement.querySelector("#detail-desc").innerHTML = `
${detail.post.content}
`

detail.comments.forEach((el) => {
divElement.querySelector("#detail-comment").innerHTML += `
댓글 ::: ${el.content} <br>
`
})


})

return divElement;
}
2 changes: 2 additions & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Home from './home.controller'
import Post from './post.controller'
import Detail from './detail.controller'
import NotFound from './404.controller'

const pages = {
home: Home,
post: Post,
detail: Detail,
notFound: NotFound
}

Expand Down
7 changes: 3 additions & 4 deletions src/router/index.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ const router = (route) => {
switch (route) {
case '#/':
return rootContent.appendChild(pages.home());
case '#/feat':
case '#/detail':
return rootContent.appendChild(pages.detail());
case '#/post':
return rootContent.appendChild(pages.post());
case '#/pricing':
return console.log('pricing!')
default:
return rootContent.appendChild(pages.notFound());
}
// console.log(route)
}

export {router};
7 changes: 7 additions & 0 deletions src/views/detail/detail.fn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
async function delDetail() {
let postId = localStorage.getItem("postId")
const res = await fetch("http://43.201.103.199/post/" + postId, {
method: "DELETE",
})
location.href = "#/"
}
17 changes: 17 additions & 0 deletions src/views/detail/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div id="detail-img">

</div>
<div id="detail-post">
<div id="detail-title"></div>
<div id="detail-date"></div>
<div id="detail-desc"></div>
</div>

<div id="detail-comment">

</div>
<hr>
<div id="detail-control">
<div id="detail-fix">수정하기</div>
<div id="detail-delete" onClick="delDetail()">삭제하기</div>
</div>
Empty file added src/views/detail/detail.scss
Empty file.

0 comments on commit 0a41b55

Please sign in to comment.