<commit_before>(ns braid.client.ui.views.pages.tags
  (:require [reagent.core :as r]
            [reagent.ratom :include-macros true :refer-macros [reaction]]
            [clojure.string :as string]
            [braid.client.reagent-adapter :refer [subscribe]]
            [braid.client.dispatcher :refer [dispatch!]]
            [braid.client.ui.views.pills :refer [tag-pill-view subscribe-button-view]]
            [braid.client.ui.views.pages.tag :refer [edit-description-view]]
            [braid.common.util :refer [valid-tag-name?]])
  (:import [goog.events KeyCodes]))

(defn new-tag-view
  [data]
  (let [error (r/atom nil)
        set-error! (fn [err?] (reset! error err?))]
    (fn [data]
      [:input.new-tag
       {:class (when error "error")
        :on-key-up
        (fn [e]
          (let [text (.. e -target -value)]
            (set-error! (not (valid-tag-name? text)))))
        :on-key-down
        (fn [e]
          (when (= KeyCodes.ENTER e.keyCode)
            (let [text (.. e -target -value)]
              (dispatch! :create-tag [text (data :group-id)]))
            (.preventDefault e)
            (aset (.. e -target) "value" "")))
        :placeholder "New Tag"}])))

(defn tag-info-view
  [tag]
  (let [group-id (subscribe [:open-group-id])
        admin? (subscribe [:current-user-is-group-admin?] [group-id])]
    (fn [tag]
      [:div.tag-info
       [:span.count.threads-count
        (tag :threads-count)]
       [:span.count.subscribers-count
        (tag :subscribers-count)]
       [tag-pill-view (tag :id)]
       [subscribe-button-view (tag :id)]
       [:div.description
        [:p
         (if (string/blank? (tag :description))
           "One day, a tag description will be here."
           (tag :description))]
        (when @admin?
          [edit-description-view tag]) ]])))

(defn tags-page-view
  []
  (let [group-id (subscribe [:open-group-id])
        tags (subscribe [:tags])
        sorted-tags (reaction (->> @tags
                                   (filter (fn [t] (= @group-id (t :group-id))))
                                   (sort-by :threads-count)
                                   reverse))
        subscribed-tag-ids (subscribe [:user-subscribed-tag-ids])
        subscribed-to? (fn [tag-id] (contains? (set @subscribed-tag-ids) tag-id))
        subscribed-tags (reaction
                          (->> @sorted-tags<commit_msg>add button for admins to delete tags<commit_after>(ns braid.client.ui.views.pages.tags
  (:require [reagent.core :as r]
            [reagent.ratom :include-macros true :refer-macros [reaction]]
            [clojure.string :as string]
            [braid.client.reagent-adapter :refer [subscribe]]
            [braid.client.dispatcher :refer [dispatch!]]
            [braid.client.ui.views.pills :refer [tag-pill-view subscribe-button-view]]
            [braid.client.ui.views.pages.tag :refer [edit-description-view]]
            [braid.common.util :refer [valid-tag-name?]])
  (:import [goog.events KeyCodes]))

(defn new-tag-view
  [data]
  (let [error (r/atom nil)
        set-error! (fn [err?] (reset! error err?))]
    (fn [data]
      [:input.new-tag
       {:class (when error "error")
        :on-key-up
        (fn [e]
          (let [text (.. e -target -value)]
            (set-error! (not (valid-tag-name? text)))))
        :on-key-down
        (fn [e]
          (when (= KeyCodes.ENTER e.keyCode)
            (let [text (.. e -target -value)]
              (dispatch! :create-tag [text (data :group-id)]))
            (.preventDefault e)
            (aset (.. e -target) "value" "")))
        :placeholder "New Tag"}])))

(defn delete-tag-view
  [tag]
  [:button {:on-click (fn [_] (dispatch! :retract-tag (tag :id)))}
   "Delete Tag"])

(defn tag-info-view
  [tag]
  (let [group-id (subscribe [:open-group-id])
        admin? (subscribe [:current-user-is-group-admin?] [group-id])]
    (fn [tag]
      [:div.tag-info
       [:span.count.threads-count
        (tag :threads-count)]
       [:span.count.subscribers-count
        (tag :subscribers-count)]
       [tag-pill-view (tag :id)]
       [subscribe-button-view (tag :id)]
       [:div.description
        [:p
         (if (string/blank? (tag :description))
           "One day, a tag description will be here."
           (tag :description))]
        (when @admin?
          [:div
           [edit-description-view tag]
           [delete-tag-view tag]])]])))

(defn tags-page-view
  []
  (let [group-id (subscribe [:open-group-id])
        tags (subscribe [:tags])
        sorted-tags (reaction (->> @tags
                                   (filter (fn [t] (= @group-id (t :group-id))))
                                   (sort-by :threads-count)
                                   reverse))
        subscribed-tag-ids (subscribe [:user-subscribed-tag-ids])
        subscribed-to? (fn [tag-id] (contains? (set @subscribed-tag-ids) tag-id))
        subscribed-tags (reaction
                          (->> @sorted-tags
{'fraction_non_alphanumeric': 0.16576359622717238, 'fraction_numerical': 0.0, 'mean_word_length': 1.8577981651376148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4727661', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1624, 'n_words': 360}