~sjm/nesktop

b2c66f8287098648bb5c438af669990953f16294 — Sam Marshall 1 year, 11 months ago 46b2d82
refactor: extract root-view
2 files changed, 23 insertions(+), 17 deletions(-)

A src/nesktop/components/root_view.cljs
M src/nesktop/core.cljs
A src/nesktop/components/root_view.cljs => src/nesktop/components/root_view.cljs +22 -0
@@ 0,0 1,22 @@
(ns nesktop.components.root-view
  (:require
    [re-frame.core :as rf]
    [reagent.core :as reagent]
    [nesktop.events :as e]
    [nesktop.queries :as q]
    [nesktop.components.note :refer [note]]))

(defn root-view
  "Render the page"
  []
  (let [dragging @(rf/subscribe [::q/dragging])]
    [:div.base
     {:on-mouse-move #(rf/dispatch [::e/update-mouse (.-clientX %) (.-clientY %)])
      :on-mouse-up #(when (> (count dragging) 0)
                      (rf/dispatch [::e/update-note-position (first (first dragging))]))
      :style {:width "100%"
              :height "100%"}}
     (let [notes (rf/subscribe [::q/notes])]
       (map (fn [n]
              [note (into n {:key (:id n)})])
            (vals @notes)))]))

M src/nesktop/core.cljs => src/nesktop/core.cljs +1 -17
@@ 4,30 4,14 @@
    [reagent.core :as reagent]
    [nesktop.events :as e]
    [nesktop.queries :as q]
    [nesktop.components.note :refer [note]]))
    [nesktop.components.root-view :refer [root-view]]))

(defn root-view
  "Render the page"
  []
  (let [dragging @(rf/subscribe [::q/dragging])]
    [:div.base
     {:on-mouse-move #(rf/dispatch [::e/update-mouse (.-clientX %) (.-clientY %)])
      :on-mouse-up #(when (> (count dragging) 0)
                      (rf/dispatch [::e/update-note-position (first (first dragging))]))
      :style {:width "100%"
              :height "100%"}}
     (let [notes (rf/subscribe [::q/notes])]
       (map (fn [n]
              [note (into n {:key (:id n)})])
            (vals @notes)))]))
     

(defn ^:export render []
  (reagent/render [root-view]
                  (js/document.getElementById "shadow-re-frame")))

(defn ^:export init []
  (rf/dispatch-sync [:initialize])

  (render))