<commit_before>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 <NAME> <<EMAIL>>
;; Copyright (c) 2015-2016 <NAME> <<EMAIL>>

(ns uxbox.main.ui.workspace.sidebar.icons
  (:require [lentes.core :as l]
            [uxbox.util.router :as r]
            [uxbox.util.rstore :as rs]
            [uxbox.main.state :as st]
            [uxbox.main.data.workspace :as dw]
            [uxbox.main.data.icons :as udi]
            [uxbox.main.ui.shapes.icon :as icon]
            [uxbox.main.ui.workspace.base :as wb]
            [uxbox.main.ui.dashboard.icons :as icons]
            [uxbox.main.ui.icons :as i]
            [uxbox.util.mixins :as mx :include-macros true]
            [uxbox.util.dom :as dom]
            [uxbox.util.data :refer (read-string)]))

;; --- Refs

(def ^:private drawing-shape
  "A focused vision of the drawing property
  of the workspace status. This avoids
  rerender the whole toolbox on each workspace
  change."
  (-> (l/in [:workspace :drawing])
      (l/derive st/state)))

;; --- Icons (Component)

(mx/defc icon-wrapper
  {:mixins [mx/static]}
  [icon]
  (icon/icon-svg icon))

(defn- icons-toolbox-will-mount
  [own]
  (let [local (:rum/local own)]
    (rs/emit! (udi/fetch-collections))
    (add-watch local ::key (fn [_ _ _ {:keys [id]}]
                             (rs/emit! (udi/fetch-icons id))))
    own))

(defn- icons-toolbox-will-unmount
  [own]
  (let [local (:rum/local own)]
    (remove-watch local ::key)
    own))

(mx/defcs icons-toolbox
  {:mixins [(mx/local) mx/reactive]
   :will-mount icons-toolbox-will-mount
   :will-unmount icons-toolbox-will-unmount}
  [own]
  (let [local (:rum/local own)<commit_msg>Load storage collection icons on sidebar icons component is mounted.<commit_after>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 <NAME> <<EMAIL>>
;; Copyright (c) 2015-2016 <NAME> <<EMAIL>>

(ns uxbox.main.ui.workspace.sidebar.icons
  (:require [lentes.core :as l]
            [uxbox.util.router :as r]
            [uxbox.util.rstore :as rs]
            [uxbox.main.state :as st]
            [uxbox.main.data.workspace :as dw]
            [uxbox.main.data.icons :as udi]
            [uxbox.main.ui.shapes.icon :as icon]
            [uxbox.main.ui.workspace.base :as wb]
            [uxbox.main.ui.dashboard.icons :as icons]
            [uxbox.main.ui.icons :as i]
            [uxbox.util.mixins :as mx :include-macros true]
            [uxbox.util.dom :as dom]
            [uxbox.util.data :refer (read-string)]))

;; --- Refs

(def ^:private drawing-shape
  "A focused vision of the drawing property
  of the workspace status. This avoids
  rerender the whole toolbox on each workspace
  change."
  (-> (l/in [:workspace :drawing])
      (l/derive st/state)))

;; --- Icons (Component)

(mx/defc icon-wrapper
  {:mixins [mx/static]}
  [icon]
  (icon/icon-svg icon))

(defn- icons-toolbox-will-mount
  [own]
  (let [local (:rum/local own)]
    (rs/emit! (udi/fetch-collections))
    (rs/emit! (udi/fetch-icons nil))
    (add-watch local ::key (fn [_ _ _ {:keys [id]}]
                             (rs/emit! (udi/fetch-icons id))))
    own))

(defn- icons-toolbox-will-unmount
  [own]
  (let [local (:rum/local own)]
    (remove-watch local ::key)
    own))

(mx/defcs icons-toolbox
  {:mixins [(mx/local) mx/reactive]
   :will-mount icons-toolbox-will-mount
   :will-unmount icons-toolbox-will-unmount}
  [own]
  (let [local (:rum/local own)
{'fraction_non_alphanumeric': 0.15345744680851064, 'fraction_numerical': 0.010638297872340425, 'mean_word_length': 2.466359447004608, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4546952', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1327, 'n_words': 355}