From d936a3e09c2482fa093be5da9ace9d922d4d71de Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Tue, 20 Nov 2018 00:03:23 -0500 Subject: [PATCH] Scaffold out campaign invitation Refs #69 Basically the DM has to add them to the DM sheet, then the player has to open a special "invite" link to "accept" (IE: save the "campaign" field in their own sheet). Sort of an extra step, but reasonable, I think. --- dev/cljs/wish/config.cljs | 1 + less/site.less | 12 ++++++ prod/cljs/wish/config.cljs | 3 ++ src/cljs/wish/routes.cljs | 3 ++ src/cljs/wish/subs.cljs | 12 ++++++ src/cljs/wish/util/nav.cljs | 11 ++++++ src/cljs/wish/views.cljs | 3 ++ src/cljs/wish/views/campaign/base.cljs | 10 +++-- .../wish/views/campaign/chars_carousel.cljs | 39 ++++++++++++++++++- src/cljs/wish/views/campaign/join.cljs | 6 +++ 10 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 src/cljs/wish/views/campaign/join.cljs diff --git a/dev/cljs/wish/config.cljs b/dev/cljs/wish/config.cljs index 090f5424..ed61b5f3 100644 --- a/dev/cljs/wish/config.cljs +++ b/dev/cljs/wish/config.cljs @@ -8,6 +8,7 @@ ^boolean goog.DEBUG) (def server-root "") +(def full-url-root (str "http://localhost:3450" server-root)) (def gdrive-client-id "661182319990-1uerkr0pue6k60a83atj2f58md95fb1b.apps.googleusercontent.com") diff --git a/less/site.less b/less/site.less index f993ae80..5db96c59 100644 --- a/less/site.less +++ b/less/site.less @@ -320,6 +320,10 @@ a { // // Campaign screen widgets +.add-chars-overlay { + padding: 32px; +} + .carousel-container { width: 100%; overflow-x: auto; @@ -327,6 +331,14 @@ a { .carousel { .flex(); + a.add-button { + .flex(); + .flex-direction(row); + .align-items(center); + + padding: 8px; + } + a.card { color: inherit; margin: 8px 4px; diff --git a/prod/cljs/wish/config.cljs b/prod/cljs/wish/config.cljs index bd4d5353..5470a037 100644 --- a/prod/cljs/wish/config.cljs +++ b/prod/cljs/wish/config.cljs @@ -9,6 +9,9 @@ ; IE: https://dhleong.github.io/wish (def server-root "/wish") +; TODO good-define? +(def full-url-root (str "https://dhleong.github.io" server-root)) + (def gdrive-client-id "661182319990-3aa8akj9fh8eva9lf7bt02621q2i18s6.apps.googleusercontent.com") (def push-server "https://wish-server.now.sh") diff --git a/src/cljs/wish/routes.cljs b/src/cljs/wish/routes.cljs index 3848c41a..78ac5a5b 100644 --- a/src/cljs/wish/routes.cljs +++ b/src/cljs/wish/routes.cljs @@ -21,6 +21,9 @@ (defroute #"/campaigns/([a-z0-9-]+/[^/]+)" [id] (navigate! :campaign [(keyword id)])) + (defroute #"/join-campaign/([a-z0-9-]+/[^/]+)/as/(.*)" [campaign-id sheet-id] + (navigate! :join-campaign [(keyword campaign-id) (keyword sheet-id)])) + (defroute "/sheets" [] (navigate! :sheet-browser)) diff --git a/src/cljs/wish/subs.cljs b/src/cljs/wish/subs.cljs index 156b002a..4198975d 100644 --- a/src/cljs/wish/subs.cljs +++ b/src/cljs/wish/subs.cljs @@ -100,6 +100,7 @@ (reg-sub :sheet-sources :sheet-sources) ; sheets +(reg-meta-sub :meta/name :name) (reg-meta-sub :meta/sheet :sheet) (reg-meta-sub :meta/sources :sources) (reg-meta-sub :meta/kind :kind) @@ -718,6 +719,17 @@ ; ======= Campaign-related ================================ +; TODO can these be broken out to a separate file? + +(reg-sub + :campaign-add-char-candidates + :<- [:meta/players] + :<- [:known-sheets] + (fn [[current-members sheets]] + (->> sheets + (remove :mine?) + (remove (comp current-members :id)) + ))) (reg-sub :campaign-members diff --git a/src/cljs/wish/util/nav.cljs b/src/cljs/wish/util/nav.cljs index 2f395110..35c64462 100644 --- a/src/cljs/wish/util/nav.cljs +++ b/src/cljs/wish/util/nav.cljs @@ -8,6 +8,7 @@ [goog.events :as gevents] [goog.history.EventType :as HistoryEventType] [pushy.core :as pushy] + [wish.config :as config] [wish.util :refer [is-ios? >evt]]) (:import goog.History)) @@ -108,6 +109,16 @@ [id & extra-sections] (apply base-sheet-url "campaigns" id extra-sections)) +(defn campaign-invite-url + "Generate the url to join a campaign" + [campaign-id invited-sheet-url] + (str + config/full-url-root + (prefix + (base-sheet-url "join-campaign" campaign-id + "as" + (namespace invited-sheet-url) invited-sheet-url)))) + (defn sheet-url "Generate the url to a sheet, optionally with extra path sections after it" diff --git a/src/cljs/wish/views.cljs b/src/cljs/wish/views.cljs index 8a27ff98..440d181d 100644 --- a/src/cljs/wish/views.cljs +++ b/src/cljs/wish/views.cljs @@ -8,6 +8,8 @@ [wish.util :refer [evt]] [wish.views.error-boundary :refer [error-boundary]] [wish.views.campaign-browser :as campaign-browser] + [wish.views.campaign.join :as join-campaign] + [wish.views.error-boundary :refer [error-boundary]] [wish.views.home :refer [home]] [wish.views.new-campaign :as new-campaign] [wish.views.new-sheet :refer [new-sheet-page]] @@ -23,6 +25,7 @@ {:campaign #'sheets/campaign :campaign-browser #'campaign-browser/page :home #'home + :join-campaign #'join-campaign/page :new-campaign #'new-campaign/page :new-sheet #'new-sheet-page :sheet #'sheets/viewer diff --git a/src/cljs/wish/views/campaign/base.cljs b/src/cljs/wish/views/campaign/base.cljs index 5dc2fedb..e53cf035 100644 --- a/src/cljs/wish/views/campaign/base.cljs +++ b/src/cljs/wish/views/campaign/base.cljs @@ -1,10 +1,12 @@ (ns ^{:author "Daniel Leong" :doc "base"} wish.views.campaign.base - (:require [wish.views.campaign.chars-carousel :refer [chars-carousel]])) + (:require [wish.views.campaign.chars-carousel :refer [chars-carousel]] + [wish.views.error-boundary :refer [error-boundary]])) (defn campaign-page [section & {:keys [char-card]}] - [:div.campaign - [chars-carousel char-card] - "TODO campaign"]) + [error-boundary + [:div.campaign + [chars-carousel char-card] + "TODO campaign"]]) diff --git a/src/cljs/wish/views/campaign/chars_carousel.cljs b/src/cljs/wish/views/campaign/chars_carousel.cljs index 107d901c..e8fb38a3 100644 --- a/src/cljs/wish/views/campaign/chars_carousel.cljs +++ b/src/cljs/wish/views/campaign/chars_carousel.cljs @@ -2,9 +2,9 @@ :doc "campaign.chars-carousel"} wish.views.campaign.chars-carousel (:require [wish.util :refer [evt]] - [wish.util.nav :refer [sheet-url]] + [wish.util.nav :as nav :refer [sheet-url]] [wish.views.error-boundary :refer [error-boundary]] - [wish.views.widgets :refer [link]])) + [wish.views.widgets :refer [icon link link>evt]])) (defn- sheet-loader [sheet] [:div "Loading " (:name sheet) "..."]) @@ -31,11 +31,46 @@ (>evt [:load-sheet! sheet-id]) [sheet-loader sheet])))) +(defn add-chars-overlay [] + (let [campaign-id (evt {:> [:toggle-overlay [#'add-chars-overlay]] + :class "add-button"} + (icon :add)] + (for [c members] ^{:key (:id c)} [link {:href (sheet-url (:id c)) diff --git a/src/cljs/wish/views/campaign/join.cljs b/src/cljs/wish/views/campaign/join.cljs new file mode 100644 index 00000000..9e131513 --- /dev/null +++ b/src/cljs/wish/views/campaign/join.cljs @@ -0,0 +1,6 @@ +(ns ^{:author "Daniel Leong" + :doc "Join a campaign as a player"} + wish.views.campaign.join) + +(defn page [campaign-id sheet-id] + [:div "TODO"])