فهرست منبع

게시물 상세 페이지 기능

Gayeon Park 3 سال پیش
والد
کامیت
89599f03a0

+ 1 - 1
realworld/src/main/java/com/dbs/realworld/controller/ArticleController.java

@@ -73,7 +73,7 @@ public class ArticleController {
     }
 
     @RequestMapping("/{articleId}")
-    String getArticleById(@PathVariable("articleId") int articleId, ModelMap model) {
+    public String getArticleById(@PathVariable("articleId") int articleId, ModelMap model) {
 
         ArticleDTO articleDTO = articleService.findByArticleId(articleId);
         model.put("articleDetail", articleDTO);

+ 0 - 3
realworld/src/main/webapp/WEB-INF/jsp/article/article.jsp

@@ -72,15 +72,12 @@
 
             fetch("/article", options)
                 .then(response => {
-                    console.log(response);
                     if (response.status === 201) {
                         return response.json();
                     }
                 })
                 .then(json => {
                     location.href = "/article/" + json.id;
-                    const id = json.id;
-                    console.log(json);
                 })
         }
     }

+ 101 - 23
realworld/src/main/webapp/WEB-INF/jsp/article/articleDetails.jsp

@@ -8,7 +8,48 @@
 
 <jsp:include page="/WEB-INF/jsp/include/head.jsp"></jsp:include>
 <script>
-    
+    function favorite() {
+        const favArticleBtn = document.querySelectorAll('.favorite-btn');
+        if("${ssIsLogin}" === "true"){
+            favArticleBtn.forEach(value =>
+                value.classList.toggle('active')
+            )
+        } else {
+            location.href = "/user/signin"
+        }
+    }
+        
+
+    function follow() {
+        const followBtn = document.querySelectorAll('.follow-btn');
+        if("${ssIsLogin}" === "true"){
+            followBtn.forEach(value =>
+                value.classList.toggle('active')
+            )
+        } else {
+            location.href = "/user/signin"
+        }
+    }
+
+
+    window.onload = () => {
+        const tags = document.querySelector('.tag-list');
+        const tagString = "${articleDetail.tags}"
+        const tagList = tagString.split(',');
+        if(tagString !== ''){
+            tags.innerHTML = tagList.map(tag => 
+                `<li class="tag">\${tag}</li>`
+            ).join('');
+        }
+
+        
+        const date = "${articleDetail.created}"
+        document.querySelectorAll('.date').forEach(value => 
+            value.textContent = new Date(date).toLocaleString()
+        )
+    }
+
+    fet
 </script>
 </head>
 <body>
@@ -18,24 +59,43 @@
         <!-- Article Banner -->
         <section class="banner">
             <div class="container">
-                <h1 class="article-banner-title">Article Title</h1>
+                <h1 class="article-banner-title">
+                    <c:out value="${articleDetail.title}"></c:out>
+                </h1>
                 <div class="article-meta">
                     <div class="metadata">
                         <a href="userpage-my.html" class="profile-link">
                             <img src="img/avatar.jpg" alt="">
                         </a>
                         <div class="article-info">
-                            <a href="userpage-my.html" class="name">Username</a>
-                            <span class="date">November 24, 2021</span>
-                        </div>
-                        <div class="buttons">
-                            <a href="editor.html" class="edit-article btn-sm">
-                                <i class="fas fa-pencil-alt"> Edit Article</i>
+                            <a href="userpage-my.html" class="name">
+                                <c:out value="${articleDetail.writerName}"></c:out>
                             </a>
-                            <button class="delete-article btn-sm">
-                                <i class="fas fa-trash-alt"> Delete Article</i>
-                            </button>
+                            <span class="date">
+                            </span>
                         </div>
+                        <c:choose>
+                            <c:when test="${articleDetail.writerId eq ssId}">
+                                <div class="buttons">
+                                    <a href="editor.html" class="edit-article btn-sm">
+                                        <i class="fas fa-pencil-alt"> Edit Article</i>
+                                    </a>
+                                    <button class="delete-article btn-sm">
+                                        <i class="fas fa-trash-alt"> Delete Article</i>
+                                    </button>
+                                </div>
+                            </c:when>
+                            <c:otherwise>
+                                <div class="buttons">
+                                    <button class="follow-btn btn-sm" onclick="follow()">
+                                        <i class="fas fa-plus"></i>&nbsp;Follow Gerome
+                                    </button>
+                                    <button class="favorite-btn btn-sm" onclick="favorite()">
+                                        <i class="fas fa-heart"></i>&nbsp;Favorite Article (564)
+                                    </button>
+                                </div>
+                            </c:otherwise>
+                        </c:choose>
                     </div>
                 </div>
             </div>
@@ -44,10 +104,10 @@
         <div class="container main">
             <div class="article-content">
                 <div class="col-12">
-                    <p>Article content</p>
+                    <pre>
+                        <c:out value="${articleDetail.content}"></c:out>
+                    </pre>
                     <ul class="tag-list">
-                        <li class="tag">welcome</li>
-                        <li class="tag">welcome</li>
                     </ul>
                 </div>
             </div>
@@ -59,17 +119,35 @@
                             <img src="img/avatar.jpg" alt="">
                         </a>
                         <div class="article-info">
-                            <a href="userpage-my.html" class="name">Username</a>
-                            <span class=date>November 24, 2021</span>
-                        </div>
-                        <div class="buttons">
-                            <a class="edit-article btn-sm" href="editor.html">
-                                <i class="fas fa-pencil-alt"> Edit Article</i>
+                            <a href="userpage-my.html" class="name">
+                                <c:out value="${articleDetail.writerName}"></c:out>
                             </a>
-                            <button class="delete-article btn-sm">
-                                <i class="fas fa-trash-alt"> Delete Article</i>
-                            </button>
+                            <span class=date>
+                                <c:out value="${articleDetail.created}"></c:out>
+                            </span>
                         </div>
+                        <c:choose>
+                            <c:when test="${articleDetail.writerId eq ssId}">
+                                <div class="buttons">
+                                    <a href="editor.html" class="edit-article btn-sm">
+                                        <i class="fas fa-pencil-alt"> Edit Article</i>
+                                    </a>
+                                    <button class="delete-article btn-sm">
+                                        <i class="fas fa-trash-alt"> Delete Article</i>
+                                    </button>
+                                </div>
+                            </c:when>
+                            <c:otherwise>
+                                <div class="buttons">
+                                    <button class="follow-btn btn-sm" onclick="follow()">
+                                        <i class="fas fa-plus"></i>&nbsp;Follow Gerome
+                                    </button>
+                                    <button class="favorite-btn btn-sm" onclick="favorite()">
+                                        <i class="fas fa-heart"></i>&nbsp;Favorite Article (564)
+                                    </button>
+                                </div>
+                            </c:otherwise>
+                        </c:choose>
                     </div>
                 </div>
             </div>

+ 37 - 18
realworld/src/main/webapp/resources/css/style.css

@@ -310,7 +310,7 @@ img {
     background-color: var(--green-color);
 }
 
-.favorete-btn.active {
+.favorite-btn.active {
     color: var(--white-color);
     background-color: var(--green-color);
 }
@@ -537,13 +537,21 @@ textarea {
     filter: none;
 }
 
-.article-page .edit-article {
+.article-page .edit-article,
+.article-page .follow-btn {
     color: var(--light-grey-color);
     border: 1px solid var(--light-grey-color);
     margin-right: 3px;
+    font-weight: 400;
+}
+
+.article-page .edit-article:hover,
+.article-page .follow-btn:hover {
+    color: var(--white-color);
+    background-color: var(--light-grey-color);
 }
 
-.article-page .edit-article:hover {
+.article-page .follow-btn.active {
     color: var(--white-color);
     background-color: var(--light-grey-color);
 }
@@ -551,6 +559,11 @@ textarea {
 .article-page .delete-article {
     color: var(--red-color);
     border-color: var(--red-color);
+    font-weight: 400;
+}
+
+.article-page .favorite-btn {
+    font-weight: 400;
 }
 
 .article-page .delete-article:hover {
@@ -558,17 +571,23 @@ textarea {
     background-color: var(--red-color);
 }
 
-.article-page .article-content p{
+.article-page .article-content pre{
     font-family: 'Source Serif Pro', serif;
     font-size: 1.25rem;
     line-height: 1.8rem;
     margin-bottom: 2rem;
+    white-space: pre-line;
 }
 
 .tag-list {
     display: flex;
 }
 
+.article-page .tag-list .tag {
+    margin-left: 0 !important;
+    margin-right: 3px;
+}
+
 .article-page .article-content ul {
     padding-bottom: 1rem;
 }
@@ -749,8 +768,7 @@ hr {
 
 
 /* modal.jsp */
-#modal-container {
-    z-index: 9999;
+#modal-container {   
     position: fixed;
     width: 100%;
     height: 100%;
@@ -763,10 +781,10 @@ hr {
     z-index: 10000;
     position: absolute;
     padding: 30px 40px;
-    /* display: flex;
+    display: flex;
+    justify-content: center;
     flex-direction: column;
-    justify-content: space-between; */
-    background: #fff;
+    background: var(--white-color);
     cursor: default;
     width: 60%;
     height: 30%;
@@ -777,25 +795,26 @@ hr {
     bottom: 0;
     border-color: rgba(0, 0, 0, 0.3);
     border-style: groove;
-    border-width: medium;
-    border-radius: 3%;
-    display: block;
+    border-radius: 1rem;
 }
 
 .modal-message {
-    padding-top: 20px;
     padding-bottom: 40px;
     font-size: 2rem;
-    font-family: 'Font Awesome 5 Free';
-    color: orangered;
+    font-family: 'Nanum Gothic', sans-serif;
+    color: var(--green-color);
 }
 
 .modal-close-btn {
     position: relative;
-    background-color: coral;
+    background-color: var(--green-color);
+    color: var(--white-color);
+    font-weight: 700;
+    font-family: 'Nanum Gothic', sans-serif;
     width: 5rem;
     height: 2rem;
-    border-radius: 10%;
+    border-radius: 0.3rem;
     cursor: pointer;
-    margin: auto;
+    margin: 0 auto;
+    margin-top: 1rem;
 }