From 4d675e45a78cd2aa5b4dacd0a051ed3c82ff7f9b Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Mon, 12 Nov 2018 10:10:21 -0500 Subject: [PATCH] Scaffold out Campaign pages Refs #69 --- less/site.less | 4 ++ src/cljs/wish/sheets.cljs | 17 +++++-- src/cljs/wish/sheets/dnd5e/campaign.cljs | 8 ++++ src/cljs/wish/subs.cljs | 6 +++ src/cljs/wish/util/nav.cljs | 54 ++++++++++++++++++----- src/cljs/wish/views.cljs | 7 ++- src/cljs/wish/views/campaign_browser.cljs | 29 ++++++++++++ src/cljs/wish/views/home.cljs | 38 ++++++++++------ src/cljs/wish/views/new_campaign.cljs | 21 +++++++++ 9 files changed, 156 insertions(+), 28 deletions(-) create mode 100644 src/cljs/wish/sheets/dnd5e/campaign.cljs create mode 100644 src/cljs/wish/views/campaign_browser.cljs create mode 100644 src/cljs/wish/views/new_campaign.cljs diff --git a/less/site.less b/less/site.less index c09780ac..772ffec6 100644 --- a/less/site.less +++ b/less/site.less @@ -193,6 +193,10 @@ a { } } +.group { + margin: 8px 0; +} + .sections { .flex(wrap); .justify-content(center); diff --git a/src/cljs/wish/sheets.cljs b/src/cljs/wish/sheets.cljs index faaa8d30..65fc45b9 100644 --- a/src/cljs/wish/sheets.cljs +++ b/src/cljs/wish/sheets.cljs @@ -3,6 +3,7 @@ wish.sheets (:require [wish.sheets.dnd5e :as dnd5e] [wish.sheets.dnd5e.builder :as dnd5e-builder] + [wish.sheets.dnd5e.campaign :as dnd5e-campaign] [wish.sheets.dnd5e.keymaps :as dnd5e-key] [wish.sheets.dnd5e.util :as dnd5e-util] [wish.sources.compiler :refer [compiler-version]] @@ -20,6 +21,7 @@ {:dnd5e {:name "D&D 5E" :fn #'dnd5e/sheet :builder #'dnd5e-builder/view + :campaign #'dnd5e-campaign/view :v 1 :default-sources [:wish/wdnd5e-srd] @@ -169,12 +171,19 @@ [[sheet-id section]] (ensuring-loaded sheet-id - (fn [sheet-info] - [(:builder sheet-info) section]))) + (fn [{view :builder}] + [view section]))) + +(defn campaign + [[campaign-id section]] + (ensuring-loaded + campaign-id + (fn [{view :campaign}] + [view section]))) (defn viewer [sheet-id] (ensuring-loaded sheet-id - (fn [sheet-info] - [(:fn sheet-info)]))) + (fn [{view :fn}] + [view]))) diff --git a/src/cljs/wish/sheets/dnd5e/campaign.cljs b/src/cljs/wish/sheets/dnd5e/campaign.cljs new file mode 100644 index 00000000..d0d6fdec --- /dev/null +++ b/src/cljs/wish/sheets/dnd5e/campaign.cljs @@ -0,0 +1,8 @@ +(ns ^{:author "Daniel Leong" + :doc "Campaign-viewer for D&D 5e"} + wish.sheets.dnd5e.campaign) + +(defn view + [section] + [:div + "TODO Campaign"]) diff --git a/src/cljs/wish/subs.cljs b/src/cljs/wish/subs.cljs index 4de50c7e..40da74e7 100644 --- a/src/cljs/wish/subs.cljs +++ b/src/cljs/wish/subs.cljs @@ -180,6 +180,12 @@ (:shared? filters) (remove :mine? sheets)))) +(reg-sub + :known-campaigns + (fn [db] + ; TODO + nil)) + ; if a specific sheet-id is not provided, loads ; for the active sheet id (reg-sub diff --git a/src/cljs/wish/util/nav.cljs b/src/cljs/wish/util/nav.cljs index 81142f6b..60516f87 100644 --- a/src/cljs/wish/util/nav.cljs +++ b/src/cljs/wish/util/nav.cljs @@ -86,19 +86,54 @@ (js/window.location.replace (prefix new-location))) + +(defn- base-sheet-url + "Generate the url to a sheet, optionally with + extra path sections after it" + [kind id & extra-sections] + (apply str "/" kind + "/" (namespace id) + "/" (name id) + (when extra-sections + (interleave (repeat "/") + (map + #(if (keyword? %) + (name %) + (str %)) + extra-sections))))) + +(defn campaign-url + "Generate the url to a campaign, optionally with + extra path sections after it" + [id & extra-sections] + (apply base-sheet-url "campaigns" id extra-sections)) + (defn sheet-url "Generate the url to a sheet, optionally with extra path sections after it" + [kind id & extra-sections] + (apply str "/" kind + "/" (namespace id) + "/" (name id) + (when extra-sections + (interleave (repeat "/") + (map + #(if (keyword? %) + (name %) + (str %)) + extra-sections))))) + +(defn campaign-url + "Generate the url to a campaign, optionally with + extra path sections after it" [id & extra-sections] - (apply str "/sheets/" (namespace id) - "/" (name id) - (when extra-sections - (interleave (repeat "/") - (map - #(if (keyword? %) - (name %) - (str %)) - extra-sections))))) + (apply base-sheet-url "campaigns" id extra-sections)) + +(defn sheet-url + "Generate the url to a sheet, optionally with + extra path sections after it" + [id & extra-sections] + (apply base-sheet-url "sheets" id extra-sections)) ; ======= support back button to close overlays =========== @@ -129,4 +164,3 @@ ; stop listening to onpopstate (set! js/window.onpopstate nil) (js/history.go -1)))) - diff --git a/src/cljs/wish/views.cljs b/src/cljs/wish/views.cljs index 6d43ca85..8990adb8 100644 --- a/src/cljs/wish/views.cljs +++ b/src/cljs/wish/views.cljs @@ -6,7 +6,9 @@ [wish.sheets :as sheets] [wish.subs :as subs] [wish.util :refer [evt]] + [wish.views.campaign-browser :as campaign-browser] [wish.views.home :refer [home]] + [wish.views.new-campaign :as new-campaign] [wish.views.new-sheet :refer [new-sheet-page]] [wish.views.router :refer [router]] [wish.views.sheet-browser :as sheet-browser] @@ -17,7 +19,10 @@ )) (def pages - {:home #'home + {:campaign #'sheets/campaign + :campaign-browser #'campaign-browser/page + :home #'home + :new-campaign #'new-campaign/page :new-sheet #'new-sheet-page :sheet #'sheets/viewer :sheet-browser #'sheet-browser/page diff --git a/src/cljs/wish/views/campaign_browser.cljs b/src/cljs/wish/views/campaign_browser.cljs new file mode 100644 index 00000000..88f660a0 --- /dev/null +++ b/src/cljs/wish/views/campaign_browser.cljs @@ -0,0 +1,29 @@ +(ns ^{:author "Daniel Leong" + :doc "campaign-browser"} + wish.views.campaign-browser + (:require [reagent.core :as r] + [reagent-forms.core :refer [bind-fields]] + [wish.util :refer [>evt