-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Campaign events/subs to own file; support add/remove members
Refs #69
- Loading branch information
Showing
7 changed files
with
109 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(ns ^{:author "Daniel Leong" | ||
:doc "Campaign-specific events"} | ||
wish.views.campaign.events | ||
(:require-macros [wish.util.log :as log :refer [log]]) | ||
(:require [clojure.string :as str] | ||
[re-frame.core :refer [dispatch reg-event-db reg-event-fx | ||
path | ||
inject-cofx trim-v]] | ||
[day8.re-frame.tracing :refer-macros [fn-traced defn-traced]] | ||
[vimsical.re-frame.cofx.inject :as inject] | ||
[wish.sheets.util :refer [update-sheet-path]])) | ||
|
||
;; can also be passed nil to leave a campaign | ||
(reg-event-fx | ||
::join-campaign | ||
[trim-v (inject-cofx ::inject/sub [:active-sheet-id])] | ||
(fn [{:keys [active-sheet-id] :as cofx} [campaign-id ?campaign-name]] | ||
(if campaign-id | ||
(let [info {:id campaign-id | ||
:name ?campaign-name}] | ||
(log/info "Joining " campaign-id) | ||
|
||
(-> cofx | ||
(update-sheet-path [] assoc :campaign info) | ||
|
||
; raise a notifier | ||
(assoc :dispatch [:notify! {:duration :short | ||
:content (str "Joined " | ||
(or (:name info) | ||
"the campaign") | ||
" successfully!")}]))) | ||
|
||
(do | ||
(log/info "Leaving campaign") | ||
|
||
(-> cofx | ||
(update-sheet-path [] dissoc :campaign) | ||
|
||
; raise a notifier | ||
(assoc :dispatch [:notify! {:duration :short | ||
:content "Left the campaign successfully."}])))))) | ||
|
||
(reg-event-fx | ||
::add-player | ||
[trim-v] | ||
(fn-traced [cofx [character-id]] | ||
(update-sheet-path cofx [:players] conj character-id))) | ||
|
||
(reg-event-fx | ||
::remove-player | ||
[trim-v] | ||
(fn-traced [cofx [character-id]] | ||
(update-sheet-path cofx [:players] disj character-id))) | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns ^{:author "Daniel Leong" | ||
:doc "Campaign-specific subs"} | ||
wish.views.campaign.subs | ||
(:require [clojure.string :as str] | ||
[re-frame.core :refer [reg-sub subscribe]])) | ||
|
||
(reg-sub | ||
::add-char-candidates | ||
:<- [:meta/players] | ||
:<- [:known-sheets] | ||
(fn [[current-members sheets]] | ||
(->> sheets | ||
(remove (comp current-members :id)) | ||
))) | ||
|
||
(reg-sub | ||
::campaign-members | ||
:<- [:meta/players] | ||
:<- [:sheets] | ||
(fn [[char-sheet-ids sheets] qv] | ||
(->> char-sheet-ids | ||
(map (fn [id] | ||
(or (assoc (get sheets id) | ||
:id id) | ||
{:id id}))) | ||
(sort-by :name)))) |