Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ulysses-front/src/cljs/ulysses/subs.cljs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
174 lines (146 sloc)
4.41 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ulysses.subs | |
(:require-macros [reagent.ratom :refer [reaction]]) | |
(:require [re-frame.core :as re-frame :refer [register-sub]] | |
[ulysses.utils :refer [remap metric-maxes]] | |
[ulysses.config :as config])) | |
;; ---------------------------------------------------------------------------- | |
;; general | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:page-with-args | |
(fn [db _] | |
(reaction | |
(let [{:keys [active-page route-args]} @db] | |
[active-page route-args])))) | |
(register-sub | |
:window-size | |
(fn [db _] | |
(reaction (-> @db :window-size)))) | |
(register-sub | |
:scroll-y | |
(fn [db _] | |
(reaction (-> @db :window-scroll-position :y)))) | |
(register-sub | |
:scroll-implies-load-more | |
(fn [db _] | |
(reaction | |
(let [scroll-y (-> @db :window-scroll-position :y) | |
w-height (-> @db :window-size :height) | |
d-height (-> @db :document-size :height) | |
b-from-b (- d-height (+ w-height scroll-y))] | |
(< b-from-b config/load-from-bottom-at))))) | |
(register-sub | |
:overall-progress | |
(fn [db _] | |
(reaction | |
(let [ap (-> @db :progress vals)] | |
(if (nil? ap) 0 | |
(/ (apply + ap) | |
(count ap))))))) | |
(register-sub | |
:is-loading | |
(fn [db _] | |
(reaction (-> @db :progress not-empty boolean)))) | |
(register-sub | |
:pagination | |
(fn [db _] | |
(reaction | |
(let [{:keys [page-current page-last]} @db] | |
{:current page-current :last page-last})))) | |
;; ---------------------------------------------------------------------------- | |
;; user | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:user | |
(fn [db _] | |
(reaction (:user @db)))) | |
;; ---------------------------------------------------------------------------- | |
;; raw data | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:grant-ops | |
(fn [db _] | |
(reaction (:grant-ops @db)))) | |
(register-sub | |
:builder-grant-op | |
(fn [db _] | |
(reaction (:builder-grant-op @db)))) | |
(register-sub | |
:faculties | |
(fn [db _] | |
(reaction (:faculties @db)))) | |
(register-sub | |
:faculty-titles | |
(fn [db _] | |
(reaction (:faculty-titles @db)))) | |
(register-sub | |
:builder-faculties-pool | |
(fn [db _] | |
(reaction (:builder-faculties-pool @db)))) | |
(register-sub | |
:workspaces | |
(fn [db _] | |
(reaction (:workspaces @db)))) | |
(register-sub | |
:builder-workspace | |
(fn [db _] | |
(reaction (:builder-workspace @db)))) | |
;; ---------------------------------------------------------------------------- | |
;; user data | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:home-filters | |
(fn [db _] | |
(reaction (:home-filters @db)))) | |
(register-sub | |
:builder-filters | |
(fn [db _] | |
(reaction (:builder-filters @db)))) | |
;; ---------------------------------------------------------------------------- | |
;; derived data | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:builder-faculties-pool-filtered | |
(fn [db _] | |
(reaction | |
(let [{:keys [builder-faculties-pool builder-filters]} @db] | |
(let [{:keys [metrics]} builder-filters | |
maxes (metric-maxes metrics builder-faculties-pool) | |
metrics-n (remap #(/ % 100) metrics)] | |
(filter | |
(fn [f] | |
(every? | |
(fn [[k v]] | |
(< v (/ (get-in f [:metrics k]) | |
(get maxes k)))) | |
metrics-n)) | |
builder-faculties-pool)))))) | |
(register-sub | |
:workspaces-current | |
(fn [db _] | |
(reaction | |
(let [{:keys [workspaces builder-grant-op]} @db] | |
(if builder-grant-op | |
(let [{:keys [id]} builder-grant-op] | |
(filter | |
(fn [w] (= id (:grant-op-id w))) | |
workspaces)) | |
(vector)))))) | |
(register-sub | |
:builder-workspace-faculty-hover | |
(fn [db _] | |
(reaction | |
(let [{:keys [faculties builder-workspace-faculty-hover]} @db] | |
(when builder-workspace-faculty-hover | |
(get faculties builder-workspace-faculty-hover)))))) | |
(register-sub | |
:builder-workspaces-saved-timestamps | |
(fn [db _] | |
(reaction (-> @db :builder-workspaces-saved-timestamps)))) | |
;; ---------------------------------------------------------------------------- | |
;; interface | |
;; ---------------------------------------------------------------------------- | |
(register-sub | |
:modal | |
(fn [db _] | |
(reaction (:modal @db)))) |