From 59cb26c6e0e4c31c309ca3cb2af728bcd64f5df1 Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Thu, 15 Nov 2018 21:37:57 -0500 Subject: [PATCH] Add preliminary chars carousel widget Refs #69 Mostly just ensures sheets are loaded; styling to come... eventually --- src/cljs/wish/sheets/dnd5e/campaign.cljs | 8 +++- src/cljs/wish/subs.cljs | 19 ++++++++ src/cljs/wish/subs_util.cljs | 1 + .../wish/views/campaign/chars_carousel.cljs | 45 +++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/cljs/wish/views/campaign/chars_carousel.cljs diff --git a/src/cljs/wish/sheets/dnd5e/campaign.cljs b/src/cljs/wish/sheets/dnd5e/campaign.cljs index d0d6fdec..bc7aabc1 100644 --- a/src/cljs/wish/sheets/dnd5e/campaign.cljs +++ b/src/cljs/wish/sheets/dnd5e/campaign.cljs @@ -1,8 +1,14 @@ (ns ^{:author "Daniel Leong" :doc "Campaign-viewer for D&D 5e"} - wish.sheets.dnd5e.campaign) + wish.sheets.dnd5e.campaign + (:require [wish.views.campaign.chars-carousel :refer [chars-carousel]])) + +(defn char-card [c] + [:div.character + (:name c)]) (defn view [section] [:div + [chars-carousel char-card] "TODO Campaign"]) diff --git a/src/cljs/wish/subs.cljs b/src/cljs/wish/subs.cljs index d37e9d3d..68fcba44 100644 --- a/src/cljs/wish/subs.cljs +++ b/src/cljs/wish/subs.cljs @@ -99,6 +99,7 @@ (reg-sub :sheets-filters :sheets-filters) (reg-sub :sheet-sources :sheet-sources) +; sheets (reg-meta-sub :meta/sheet :sheet) (reg-meta-sub :meta/sources :sources) (reg-meta-sub :meta/kind :kind) @@ -110,6 +111,9 @@ (reg-meta-sub :meta/items :items) (reg-meta-sub :meta/equipped :equipped) +; campaigns +(reg-meta-sub :meta/players :players) + (reg-sub :active-sheet-source-ids :<- [:meta/sources] @@ -705,3 +709,18 @@ (when (and sheet-id (not (contains? my-sheets sheet-id))) (into #{sheet-id} source-ids)))) + + +; ======= Campaign-related ================================ + +(reg-sub + :campaign-members + :<- [:meta/players] + :<- [:sheets] + (fn [[char-sheet-ids sheets]] + (->> char-sheet-ids + (map (fn [id] + (or (assoc (get sheets id) + :id id) + {:id id}))) + (sort-by :name)))) diff --git a/src/cljs/wish/subs_util.cljs b/src/cljs/wish/subs_util.cljs index 41e558f1..43a69cf0 100644 --- a/src/cljs/wish/subs_util.cljs +++ b/src/cljs/wish/subs_util.cljs @@ -8,6 +8,7 @@ (:page db))] (let [[page args] page-vec] (case page + :campaign (first args) :sheet args :sheet-builder (first args) diff --git a/src/cljs/wish/views/campaign/chars_carousel.cljs b/src/cljs/wish/views/campaign/chars_carousel.cljs new file mode 100644 index 00000000..09c699bd --- /dev/null +++ b/src/cljs/wish/views/campaign/chars_carousel.cljs @@ -0,0 +1,45 @@ +(ns ^{:author "Daniel Leong" + :doc "campaign.chars-carousel"} + wish.views.campaign.chars-carousel + (:require [wish.util :refer [evt]] + [wish.views.error-boundary :refer [error-boundary]])) + +(defn- sheet-loader [sheet] + [:div "Loading " (:name sheet) "..."]) + +(defn- sources-loader [sheet] + [:div "Loading " (:name sheet) "..."]) + +(defn- char-sheet-loader + [sheet-id content-fn] + (let [sheet (evt [:load-sheet-source! sheet (:sources sheet)]) + [sources-loader sheet])) + + ; either we don't have the sheet at all, or it's just + ; a stub with no actual data; either way, load it! + (do + (>evt [:load-sheet! sheet-id]) + [sheet-loader sheet])))) + +(defn chars-carousel [chars-card-view] + (if-let [members (seq (