Skip to content

Commit da8253a

Browse files
authored
Merge pull request #34 from ekgus419/feature/33-n-comments
[고도화] 댓글 기능 고도화 - n차 대댓글
2 parents 7ded9b4 + 63d4774 commit da8253a

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

src/main/resources/templates/articles/detail.html

+3-22
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ <h1>첫번째 글</h1>
6161
</div>
6262
</form>
6363

64-
<ul id="article-comments" class="row col-md-10 col-lg-8 pt-3">
65-
<li class="parent-comment">
64+
<ul class="article-comments">
65+
<li class="article-comment">
6666
<form class="comment-delete-form">
6767
<input type="hidden" class="article-id">
6868
<div class="row">
@@ -80,26 +80,7 @@ <h1>첫번째 글</h1>
8080
</div>
8181
</form>
8282

83-
<ul class="row me-0">
84-
<li class="child-comment">
85-
<form class="comment-delete-form">
86-
<input type="hidden" class="article-id">
87-
<div class="row">
88-
<div class="col-md-10 col-lg-9">
89-
<strong>Uno</strong>
90-
<small><time>2022-01-01</time></small>
91-
<p class="mb-1">
92-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
93-
Lorem ipsum dolor sit amet
94-
</p>
95-
</div>
96-
<div class="col-2 mb-3 align-self-center">
97-
<button type="submit" class="btn btn-outline-danger">삭제</button>
98-
</div>
99-
</div>
100-
</form>
101-
</li>
102-
</ul>
83+
<ul class="child-comments"></ul>
10384

10485
<div class="row">
10586
<details class="col-md-10 col-lg-9 mb-4">

src/main/resources/templates/articles/detail.th.xml

+8-13
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,20 @@
2828
<attr sel=".comment-textbox" th:name="content" />
2929
</attr>
3030

31-
<attr sel="#article-comments" th:remove="all-but-first">
32-
<attr sel=".parent-comment[0]" th:each="articleComment : ${articleComments}">
31+
<attr sel=".article-comments"
32+
th:remove="all-but-first"
33+
th:fragment="articleComments(childComments)"
34+
th:classappend="${childComments} != null ? 'row me-0' : 'row col-md-10 col-lg-8 pt-3'"
35+
>
36+
<attr sel=".article-comment[0]" th:each="articleComment : ${childComments} ?: ${articleComments}">
3337
<attr sel=".comment-delete-form" th:action="'/comments/' + ${articleComment.id} + '/delete'" th:method="post">
3438
<attr sel="div/strong" th:text="${articleComment.nickname}" />
3539
<attr sel="div/small/time" th:datetime="${articleComment.createdAt}" th:text="${#temporals.format(articleComment.createdAt, 'yyyy-MM-dd HH:mm:ss')}" />
3640
<attr sel="div/p" th:text="${articleComment.content}" />
3741
<attr sel="button" th:if="${#authorization.expression('isAuthenticated()')} and ${articleComment.userId} == ${#authentication.name}" />
3842
</attr>
39-
<attr sel="ul" th:if="${articleComment.childComments != null and !articleComment.childComments.isEmpty()}"
40-
th:remove="all-but-first">
41-
<attr sel=".child-comment[0]" th:each="childComment : ${articleComment.childComments}">
42-
<attr sel=".comment-delete-form" th:action="'/comments/' + ${childComment.id} + '/delete'" th:method="post">
43-
<attr sel="div/strong" th:text="${childComment.nickname}" />
44-
<attr sel="div/small/time" th:datetime="${childComment.createdAt}" th:text="${#temporals.format(childComment.createdAt, 'yyyy-MM-dd HH:mm:ss')}" />
45-
<attr sel="div/p" th:text="${childComment.content}" />
46-
<attr sel="button" th:if="${#authorization.expression('isAuthenticated()')} and ${childComment.userId} == ${#authentication.name}" />
47-
</attr>
48-
</attr>
49-
</attr>
43+
44+
<attr sel=".child-comments" th:unless="${articleComment.childComments.isEmpty}" th:replace=":: articleComments(${articleComment.childComments})" />
5045
</attr>
5146
<attr sel=".parent-comment-id" th:name="parentCommentId" th:value="${articleComment.id}" />
5247
</attr>

0 commit comments

Comments
 (0)