Skip to content

Commit

Permalink
Scaffold out campaign invitation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dhleong committed Feb 9, 2019
1 parent cdd7794 commit b3fdd50
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions dev/cljs/wish/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
12 changes: 12 additions & 0 deletions less/site.less
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,25 @@ a {
//
// Campaign screen widgets

.add-chars-overlay {
padding: 32px;
}

.carousel-container {
width: 100%;
overflow-x: auto;

.carousel {
.flex();

a.add-button {
.flex();
.flex-direction(row);
.align-items(center);

padding: 8px;
}

a.card {
color: inherit;
margin: 8px 4px;
Expand Down
3 changes: 3 additions & 0 deletions prod/cljs/wish/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 3 additions & 0 deletions src/cljs/wish/routes.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
12 changes: 12 additions & 0 deletions src/cljs/wish/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/cljs/wish/util/nav.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/cljs/wish/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
[wish.util :refer [<sub click>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]]
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/cljs/wish/views/campaign/base.cljs
Original file line number Diff line number Diff line change
@@ -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"]])
39 changes: 37 additions & 2 deletions src/cljs/wish/views/campaign/chars_carousel.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
:doc "campaign.chars-carousel"}
wish.views.campaign.chars-carousel
(:require [wish.util :refer [<sub >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) "..."])
Expand All @@ -31,11 +31,46 @@
(>evt [:load-sheet! sheet-id])
[sheet-loader sheet]))))

(defn add-chars-overlay []
(let [campaign-id (<sub [:active-sheet-id])]
[:div.add-chars-overlay
[:div.title
"Add characters to "
(<sub [:meta/name])]

[:div.candidates
(for [c (<sub [:campaign-members])]
^{:key (:id c)}
[:div.character
(:name c)

[:input.invite-url
{:type :text
:value (nav/campaign-invite-url
campaign-id
(:id c))}
]
])

(for [c (<sub [:campaign-add-char-candidates])]
^{:key (:id c)}
[:div.character
(:name c)

[:div
"INVITE (todo)"]
])]
]))

(defn chars-carousel [chars-card-view]
(if-let [members (seq (<sub [:campaign-members]))]
[:div.carousel-container
[:div.carousel

[link>evt {:> [:toggle-overlay [#'add-chars-overlay]]
:class "add-button"}
(icon :add)]

(for [c members]
^{:key (:id c)}
[link {:href (sheet-url (:id c))
Expand Down
6 changes: 6 additions & 0 deletions src/cljs/wish/views/campaign/join.cljs
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit b3fdd50

Please sign in to comment.