Monorepo for Tangled tangled.org
855
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: add comment to strings

Signed-off-by: Seongmin Lee <git@boltless.me>

+82 -1
+3
appview/pages/pages.go
··· 1612 1612 IsStarred bool 1613 1613 StarCount int 1614 1614 Owner identity.Identity 1615 + CommentList []models.CommentListItem 1616 + 1617 + VouchRelationships map[syntax.DID]*models.VouchRelationship 1615 1618 } 1616 1619 1617 1620 func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error {
+58
appview/pages/templates/strings/string.html
··· 94 94 </div> 95 95 {{ template "fragments/multiline-select" }} 96 96 </section> 97 + <div class="flex flex-col gap-4 mt-4"> 98 + {{ 99 + template "fragments/comment/commentList" 100 + (dict 101 + "LoggedInUser" .LoggedInUser 102 + "VouchRelationships" .VouchRelationships 103 + "CommentList" .CommentList) 104 + }} 105 + {{ template "newComment" . }} 106 + </div> 107 + {{ end }} 108 + 109 + {{ define "newComment" }} 110 + {{ if .LoggedInUser }} 111 + <form 112 + hx-post="/comment" 113 + hx-trigger="submit, keydown[(ctrlKey || metaKey) && key=='Enter'] from:find textarea" 114 + hx-swap="none" 115 + hx-disabled-elt="find button[type='submit']" 116 + hx-on::after-request="if(event.detail.successful) this.reset()" 117 + class="group/form" 118 + > 119 + <input name="subject-uri" type="hidden" value="{{ .String.AtUri }}"> 120 + <div class="bg-white dark:bg-gray-800 rounded drop-shadow-sm py-4 px-4 relative w-full"> 121 + <div class="text-sm pb-2 text-gray-500 dark:text-gray-400"> 122 + {{ template "user/fragments/picHandleLink" .LoggedInUser.Did }} 123 + </div> 124 + <textarea 125 + name="body" 126 + class="w-full p-2 rounded" 127 + placeholder="Add to the discussion. Markdown is supported." 128 + rows="5" 129 + required 130 + ></textarea> 131 + <div id="comment-error" class="error"></div> 132 + </div> 133 + <div class="flex gap-2 mt-2"> 134 + <button 135 + id="comment-button" 136 + type="submit" 137 + class="btn-create p-2 flex items-center gap-2 no-underline hover:no-underline" 138 + > 139 + {{ i "message-square-plus" "w-4 h-4 inline group-[.htmx-request]/form:hidden" }} 140 + {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]/form:inline" }} 141 + comment 142 + </button> 143 + </div> 144 + </form> 145 + {{ else }} 146 + <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded drop-shadow-sm p-6 relative flex gap-2 items-center"> 147 + <a href="/signup" class="btn-create py-0 hover:no-underline hover:text-white flex items-center gap-2"> 148 + sign up 149 + </a> 150 + <span class="text-gray-500 dark:text-gray-400">or</span> 151 + <a href="/login" class="underline">login</a> 152 + to add to the discussion 153 + </div> 154 + {{ end }} 97 155 {{ end }}
+21 -1
appview/strings/strings.go
··· 156 156 isStarred = db.GetStarStatus(s.Db, user.Did, string.AtUri()) 157 157 } 158 158 159 - s.Pages.SingleString(w, pages.SingleStringParams{ 159 + comments, err := db.GetComments(s.Db, orm.FilterEq("subject_uri", string.AtUri())) 160 + if err != nil { 161 + l.Error("failed to get comments", "err", err) 162 + } 163 + 164 + vouchRelationships := make(map[syntax.DID]*models.VouchRelationship) 165 + if user != nil { 166 + var participants []syntax.DID 167 + for _, c := range comments { 168 + participants = append(participants, c.Did) 169 + } 170 + vouchRelationships, err = db.GetVouchRelationshipsBatch(s.Db, syntax.DID(user.Did), participants) 171 + if err != nil { 172 + l.Error("failed to fetch vouch relationships", "err", err) 173 + } 174 + } 175 + 176 + err = s.Pages.SingleString(w, pages.SingleStringParams{ 160 177 LoggedInUser: user, 161 178 RenderToggle: renderToggle, 162 179 ShowRendered: showRendered, ··· 165 182 IsStarred: isStarred, 166 183 StarCount: starCount, 167 184 Owner: id, 185 + CommentList: models.NewCommentList(comments), 186 + 187 + VouchRelationships: vouchRelationships, 168 188 }) 169 189 } 170 190