Skip to content

Commit 832f03d

Browse files
FrostyXnikromen
authored andcommitted
frontend: allow deleting snippets in review
See #156 This will be useful for changing a location of a snippet, in case the new snippet should be over the previous one.
1 parent f72399d commit 832f03d

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

frontend/src/app/review/core.cljs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
add-snippet
2424
add-snippet-from-backend-map
2525
on-snippet-textarea-change
26+
on-click-delete-snippet
2627
snippet-color
2728
snippet-color-square
2829
highlight-text
@@ -61,7 +62,7 @@
6162
(let [text (subs (:content log)
6263
(:start_index itm)
6364
(:end_index itm))
64-
text (highlight-text idx
65+
text (highlight-text (str "snippet-" idx)
6566
(safe text)
6667
(:user_comment itm)
6768
(:color (nth @snippets idx)))]
@@ -163,7 +164,7 @@
163164
{:start-index :start_index
164165
:end-index :end_index
165166
:user-comment :comment})))
166-
@snippets))}]
167+
(remove nil? @snippets)))}]
167168

168169
;; Remember the username, so we can prefill it the next time
169170
;; TODO See PR #130
@@ -234,17 +235,23 @@
234235
(fontawesome-icon "fa-thumbs-down")]]))
235236

236237
(defn snippet [text index color]
237-
(let [name (str "snippet-" index)]
238-
{:title [:<> (snippet-color-square color) "Snippet"]
239-
:body
240-
[:textarea
241-
{:class "form-control"
242-
:rows "3"
243-
:placeholder "What makes this snippet relevant?"
244-
:value text
245-
:on-change #(do (on-snippet-textarea-change %)
246-
(vote (keyword name) 1))}]
247-
:buttons (buttons name)}))
238+
(when color
239+
(let [name (str "snippet-" index)]
240+
{:title [:<> (snippet-color-square color) "Snippet"]
241+
:body
242+
[:textarea
243+
{:class "form-control"
244+
:rows "3"
245+
:placeholder "What makes this snippet relevant?"
246+
:value text
247+
:on-change #(do (on-snippet-textarea-change %)
248+
(vote (keyword name) 1))}]
249+
:buttons
250+
(conj (buttons name)
251+
[:button {:type "button"
252+
:class ["btn btn-vote btn-outline-danger"]
253+
:on-click #(on-click-delete-snippet %)}
254+
(fontawesome-icon "fa-trash-can")])})))
248255

249256
(defn card [title text name placeholder]
250257
[:div {:class "card review-card"}

0 commit comments

Comments
 (0)