<commit_before>(ns swarmpit.component.mixin
  (:require [rum.core :as rum]
            [swarmpit.event.source :as event]
            [swarmpit.component.state :as state]))

(defn refresh-form
  ([handler] (refresh-form handler 2000))
  ([handler ms]
   {:did-mount    (fn [state]
                    (let [comp (:rum/react-component state)
                          callback #(do (handler (first (:rum/args state)))
                                        (rum/request-render comp))
                          interval (js/setInterval callback ms)]
                      (assoc state ::interval interval)))
    :will-unmount (fn [state]
                    (js/clearInterval (::interval state))
                    (dissoc state ::interval))}))

(defn init-form
  [handler]
  {:init (fn [state _]
           (state/reset-form)
           (handler (first (:rum/args state)))
           state)})

(defn init-tab
  [handler]
  {:init (fn [state _]
           (handler (first (:rum/args state)))
           state)})

(def subscribe-form
  {:did-mount    (fn [state]
                   (event/open! (first (:rum/args state)))
                   state)
   :will-unmount (fn [state]
                   (event/close!)
                   state)})

(def scroll-to-section
  {:after-render
   (fn [state]
     (let [scrolled? (state/get-value (conj state/form-state-cursor :scrolled))]
       (when (nil? scrolled?)
         (let [section (-> state :rum/args first :params :section)
               el (.getElementById js/document section)]
           (when (and el section)
             (do
               (.scrollIntoView el true)
               (.scrollBy js/window 0 -74)
               (state/update-value [:scrolled] true state/form-state-cursor))))))
     state)})

(def focus-filter
  {:did-mount (fn [state]
                ;(-> js/document
                ;    (.getElementById "Swarmpit-appbar-search-filter")
                ;    (.focus))
                state)})<commit_msg>scroll to top on init<commit_after>(ns swarmpit.component.mixin
  (:require [rum.core :as rum]
            [swarmpit.event.source :as event]
            [swarmpit.component.state :as state]))

(defn refresh-form
  ([handler] (refresh-form handler 2000))
  ([handler ms]
   {:did-mount    (fn [state]
                    (let [comp (:rum/react-component state)
                          callback #(do (handler (first (:rum/args state)))
                                        (rum/request-render comp))
                          interval (js/setInterval callback ms)]
                      (assoc state ::interval interval)))
    :will-unmount (fn [state]
                    (js/clearInterval (::interval state))
                    (dissoc state ::interval))}))

(defn init-form
  [handler]
  {:init      (fn [state _]
                (state/reset-form)
                (handler (first (:rum/args state)))
                state)
   :did-mount (fn [state]
                (.scrollTo js/window 0 0)
                state)})

(def subscribe-form
  {:did-mount    (fn [state]
                   (event/open! (first (:rum/args state)))
                   state)
   :will-unmount (fn [state]
                   (event/close!)
                   state)})

(def scroll-to-section
  {:after-render
   (fn [state]
     (let [scrolled? (state/get-value (conj state/form-state-cursor :scrolled))]
       (when (nil? scrolled?)
         (let [section (-> state :rum/args first :params :section)
               el (.getElementById js/document section)]
           (when (and el section)
             (do
               (.scrollIntoView el true)
               (.scrollBy js/window 0 -74))))))
     state)})

(def focus-filter
  {:did-mount (fn [state]
                ;(-> js/document
                ;    (.getElementById "Swarmpit-appbar-search-filter")
                ;    (.focus))
                state)})
{'fraction_non_alphanumeric': 0.1352607124419205, 'fraction_numerical': 0.004130098089829634, 'mean_word_length': 1.5359947643979057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5700326', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1069, 'n_words': 280}