forked from larrychristensen/orcpub
-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
views.cljs
8026 lines (7568 loc) · 294 KB
/
views.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(ns orcpub.dnd.e5.views
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[reagent.core :as r]
[orcpub.route-map :as routes]
[orcpub.common :as common]
[orcpub.entity :as entity]
[orcpub.components :as comps]
[orcpub.entity-spec :as es]
[orcpub.pdf-spec :as pdf-spec]
[orcpub.dice :as dice]
[orcpub.entity.strict :as se]
[orcpub.dnd.e5.subs :as subs]
[orcpub.dnd.e5.equipment-subs]
[orcpub.dnd.e5.character :as char]
[orcpub.dnd.e5.backgrounds :as bg]
[orcpub.dnd.e5.languages :as langs]
[orcpub.dnd.e5.selections :as selections]
[orcpub.dnd.e5.races :as races]
[orcpub.dnd.e5.classes :as classes]
[orcpub.dnd.e5.feats :as feats]
[orcpub.dnd.e5.units :as units]
[orcpub.dnd.e5.party :as party]
[orcpub.dnd.e5.character.random :as char-random]
[orcpub.dnd.e5.character.equipment :as char-equip]
[orcpub.registration :as registration]
[orcpub.dnd.e5 :as e5]
[orcpub.dnd.e5.magic-items :as mi]
[orcpub.dnd.e5.damage-types :as damage-types]
[orcpub.dnd.e5.monsters :as monsters]
[orcpub.dnd.e5.encounters :as encounters]
[orcpub.dnd.e5.combat :as combat]
[orcpub.dnd.e5.spells :as spells]
[orcpub.dnd.e5.skills :as skills]
[orcpub.dnd.e5.equipment :as equip]
[orcpub.dnd.e5.weapons :as weapon]
[orcpub.dnd.e5.armor :as armor]
[orcpub.dnd.e5.display :as disp]
[orcpub.dnd.e5.template :as t]
[orcpub.dnd.e5.views-2 :as views-2]
[orcpub.template :as template]
[orcpub.dnd.e5.options :as opt]
[orcpub.dnd.e5.events :as events]
[orcpub.ver :as v]
[clojure.string :as s]
[cljs.reader :as reader]
[orcpub.user-agent :as user-agent]
[bidi.bidi :as bidi]
[camel-snake-kebab.core :as csk]))
;; the `amount` of "uses" an action may have before it warrants
;; using a dropdown instead of a list of checkboxes
(def actions-amount-many 5)
(def text-color "#484848")
(def orange "#f0a100")
(def input-style
{:height "38px"
:border-style "solid"
:border-width "1px"
:border-radius "3px"
:font-size "14px"
:padding-left "10px"
:color text-color})
(def default-input-style
(merge
input-style
{:border-color "rgba(72,72,72,0.37)"}))
(defn event-value [e]
(.. e -target -value))
(defn set-value [atom key e]
(swap! atom assoc key (event-value e)))
(defn validation-messages [messages]
(if messages
[:ul.t-a-l.p-l-20.p-r-20.m-b-10
(doall
(map-indexed
(fn [i msg]
^{:key i}
[:li.red (str common/dot-char " " msg)])
messages))]))
(defn base-input [attrs]
[:div.m-b-10
[:div.f-s-10.t-a-l.m-l-10 (:placeholder attrs)]
[:div.flex.p-l-10.p-l-10.p-r-10
[:input.flex-grow-1
(merge
attrs
;; Rem'd out to allow auto fill on use/password
;;{:auto-complete :off}
)]]])
(defn form-input []
(let [blurred? (r/atom false)]
(fn [{:keys [title key value messages type on-change]}]
[:div
[base-input
{:name key
:type type
:value value
:placeholder title
:style input-style
:class-name (if (and @blurred? (seq messages))
"b-red"
"b-gray")
:on-focus (fn [_] (reset! blurred? false))
:on-change on-change
:on-blur (fn [e] (reset! blurred? true))}]
(if @blurred? (validation-messages messages))])))
(defn export-pdf [built-char id & [options]]
(fn [_]
(let [field (.getElementById js/document "fields-input")]
(aset field "value" (str (pdf-spec/make-spec built-char id options)))
(.submit (.getElementById js/document "download-form")))))
(defn download-form [built-char]
[:form.download-form
{:id "download-form"
:action (if (and js/window.location
(s/starts-with? js/window.location.href "http://localhost"))
"http://localhost:8890/character.pdf"
"/character.pdf")
:method "POST"
:target "_blank"}
[:input {:type "hidden" :name "body" :id "fields-input"}]])
(defn svg-icon [icon-name & [size theme-override]]
(let [theme (or theme-override @(subscribe [:theme]))
light-theme? (= "light-theme" theme)
size (or size 32)]
[:img.svg-icon
{:style {:height (str size "px")
:width (str size "px")}
:class-name (if light-theme? " opacity-7")
:src (str (if light-theme? "/image/black/" "/image/") icon-name ".svg")}]))
(def login-style
{:color "#f0a100"})
(defn dispatch-logout []
(dispatch [:logout]))
(defn dispatch-route-to-login [e]
(.stopPropagation e)
(dispatch [:route-to-login]))
(defn dispatch-route-to-my-account [e]
(dispatch [:route :my-account]))
(def header-tab-style
{:width "85px"})
(def active-style {:background-color "rgba(240, 161, 0, 0.7)"})
(def menu-color "#2c3445")
(def header-menu-item-style
{:position :absolute
:background-color "#2c3445"
:z-index 10000
:top 84
:right 0})
(def desktop-menu-item-style
(assoc header-menu-item-style
:width "100%"))
(def mobile-header-menu-item-style
(assoc header-menu-item-style
:top 46))
(def user-menu-style
{:background-color menu-color
:z-index 10000
:position :absolute
:right 0
:display :none})
(defn handle-user-menu [e]
(let [user-header (js/document.getElementById "user-header")
user-menu (js/document.getElementById "user-menu")
bounding-rect (.getBoundingClientRect user-header)
width (.-offsetWidth user-header)
bottom (.-bottom bounding-rect)
right (.-right bounding-rect)
style (.-style user-menu)
window-width js/document.documentElement.clientWidth]
(set! (.-display style) "block")))
(defn hide-user-menu [e]
(let [user-menu (js/document.getElementById "user-menu")
style (.-style user-menu)]
(set! (.-display style) "none")))
(defn user-header-view []
(let [username @(subscribe [:username])
mobile? @(subscribe [:mobile?])]
[:div#user-header.pointer.posn-rel
(if username
{:on-mouse-over handle-user-menu
:on-mouse-out hide-user-menu})
[:div.flex.align-items-c
[:div.user-icon [svg-icon "orc-head" 40 ""]]
(if username
[:span.f-w-b.t-a-r
(if (not @(subscribe [:mobile?])) [:span.m-r-5 username])]
[:span.pointer.flex.flex-column.align-items-end
[:span.orange.underline.f-w-b.m-l-5
{:style login-style
:on-click dispatch-route-to-login}
[:span "LOGIN"]]])
(if username
[:i.fa.m-l-5.fa-caret-down])]
[:div#user-menu.shadow.f-w-b
{:style user-menu-style
:on-click hide-user-menu}
[:div.p-10.opacity-5.hover-opacity-full
{:on-click dispatch-logout}
"LOG OUT"]
[:div.p-10.opacity-5.hover-opacity-full
{:on-click dispatch-route-to-my-account}
"ACCOUNT"]]
#_(if username
[:span.f-w-b.t-a-r
(if (not @(subscribe [:mobile?])) [:span.m-r-5 username])
[:span.underline.pointer
{:style login-style
:on-click dispatch-logout}
"LOG OUT"]]
[:span.pointer.flex.flex-column.align-items-end
[:span.orange.underline.f-w-b.m-l-5
{:style login-style
:on-click dispatch-route-to-login}
[:span "LOGIN"]]])]))
(defn route-fn [route]
(fn [e]
(dispatch [:route route])
(.stopPropagation e)))
(def route-handler (memoize route-fn))
(defn header-tab []
(let [hovered? (r/atom false)]
(fn [title icon on-click disabled active device-type & buttons]
(let [mobile? (= :mobile device-type)]
[:div.f-w-b.f-s-14.t-a-c.header-tab.m-l-2.m-r-2.posn-rel
{:on-click (fn [e] (if (seq buttons)
#(swap! hovered? not)
(on-click e)))
:on-mouse-over #(reset! hovered? true)
:on-mouse-out #(reset! hovered? false)
:style (if active active-style)
:class-name (str (if disabled "disabled" "pointer")
" "
(if (not mobile?) " w-110"))}
[:div.p-10
{:class-name (if (not active) (if disabled "opacity-2" "opacity-6 hover-opacity-full"))}
(let [size (if mobile? 24 48)] (svg-icon icon size ""))
(if (not mobile?)
[:div.title.uppercase title])]
(if (and (seq buttons)
@hovered?)
[:div.uppercase.shadow
{:style (if mobile? mobile-header-menu-item-style header-menu-item-style)}
(doall
(map
(fn [{:keys [name route]}]
^{:key name}
[:div.p-10.opacity-5.hover-opacity-full
(let [current-route @(subscribe [:route])]
{:style (if (or (= route current-route)
(= route (get current-route :handler))) active-style)
:on-click (route-handler route)})
name])
buttons))])]))))
(def social-icon-style
{:color :white
:font-size "20px"})
(defn social-icon [icon link]
[:a.p-5.opacity-5.hover-opacity-full.main-text-color
{:style social-icon-style
:href link :target :_blank}
[:i.fab
{:class-name (str "fa-" icon)}]])
(def search-input-style
{:height "60px"
:margin-top "0px"
:border :none
:font-size "28px"
:background-color :transparent
:color :white})
(def search-icon-style
{:top 6
:right 25})
(def search-input-parent-style
{:background-color "rgba(0,0,0,0.15)"})
(def transparent-search-input-style
(assoc search-input-style :color :transparent))
(defn route-to-default-route []
(dispatch [:route routes/default-route]))
(defn search-input-keypress [e]
(if (= "Enter" (.-key e)) (dispatch [:set-search-text @(subscribe [:search-text])])))
(defn set-search-text [e]
(dispatch [:set-search-text (event-value e)]))
(defn set-search-text-empty [e]
(dispatch [:set-search-text ""]))
(defn open-orcacle []
(dispatch [:open-orcacle]))
(defn route-to-character-list-page []
(dispatch [:route routes/dnd-e5-char-list-page-route]))
(defn route-to-spell-list-page []
(dispatch [:route routes/dnd-e5-spell-list-page-route]))
(defn route-to-monster-list-page []
(dispatch [:route routes/dnd-e5-monster-list-page-route]))
(defn route-to-item-list-page []
(dispatch [:route routes/dnd-e5-item-list-page-route]))
(defn route-to-my-content-page []
(dispatch [:route routes/dnd-e5-my-content-route]))
(defn route-to-my-encounters-page []
(dispatch [:route routes/dnd-e5-my-encounters-route]))
(def logo [:img.h-60.pointer
{:src "/image/dmv-logo.svg"
:on-click route-to-default-route}])
(defn app-header []
(let [device-type @(subscribe [:device-type])
mobile? (= :mobile device-type)
active-route @(subscribe [:route])]
[:div#app-header.app-header.flex.flex-column.justify-cont-s-b.white
[:div.app-header-bar.container
[:div.content
[:div.flex.align-items-c.h-100-p
[:div.flex.justify-cont-s-b.align-items-c.w-100-p.p-l-20.p-r-20.h-100-p
logo
(let [search-text @(subscribe [:search-text])
search-text? @(subscribe [:search-text?])]
[:div
{:class-name (if mobile? "p-l-10 p-r-10" "p-l-20 p-r-20 flex-grow-1")}
[:div.b-rad-5.flex.align-items-c
{:style search-input-parent-style}
(if (not mobile?)
[:div.p-l-20.flex-grow-1
[:input.w-100-p.main-text-color
{:style search-input-style
:value search-text
:on-key-press search-input-keypress
:on-change set-search-text
:placeholder "search"}]])
[:div.p-r-10.pointer
{:on-click open-orcacle}
[svg-icon "magnifying-glass" (if mobile? 32 48) ""]]]])
[user-header-view]]]]]
[:div.container
[:div.content
[:div.flex.w-100-p.align-items-end
{:class-name (if mobile? "justify-cont-s-b" "justify-cont-s-b")}
[:div
{:style {:min-width "53px"}}
[:a {:href "https://www.patreon.com/DungeonMastersVault" :target :_blank}
[:img.h-32.m-l-10.m-b-5.pointer.opacity-7.hover-opacity-full
{:src (if mobile?
"https://c5.patreon.com/external/logo/downloads_logomark_color_on_navy.png"
"https://c5.patreon.com/external/logo/become_a_patron_button.png")}]]
(if (not mobile?)
[:div.main-text-color.p-10
(social-icon "facebook-f" "https://www.facebook.com/groups/252484128656613/")
(social-icon "twitter" "https://twitter.com/thDMV")
(social-icon "reddit-alien" "https://www.reddit.com/r/dungeonmastersvault/")])]
[:div.flex.m-b-5.m-t-5.justify-cont-s-b.app-header-menu
[header-tab
"characters"
"battle-gear"
route-to-character-list-page
false
(routes/dnd-e5-char-page-routes (or (:handler active-route) active-route))
device-type
{:name "Character List"
:route routes/dnd-e5-char-list-page-route}
{:name "Character Builder"
:route routes/dnd-e5-char-builder-route}
{:name "Parties"
:route routes/dnd-e5-char-parties-page-route}]
[header-tab
"spells"
"spell-book"
route-to-spell-list-page
false
(routes/dnd-e5-spell-page-routes (or (:handler active-route) active-route))
device-type
{:name "Spell List"
:route routes/dnd-e5-spell-list-page-route}
{:name "Spell Builder"
:route routes/dnd-e5-spell-builder-page-route}]
[header-tab
"monsters"
"spiked-dragon-head"
route-to-monster-list-page
false
(routes/dnd-e5-monster-page-routes (or (:handler active-route) active-route))
device-type
{:name "Monster List"
:route routes/dnd-e5-monster-list-page-route}
{:name "Monster Builder"
:route routes/dnd-e5-monster-builder-page-route}]
[header-tab
"items"
"all-for-one"
route-to-item-list-page
false
(routes/dnd-e5-item-page-routes
(or (:handler active-route)
active-route))
device-type
{:name "Item List"
:route routes/dnd-e5-item-list-page-route}
{:name "Item Builder"
:route routes/dnd-e5-item-builder-page-route}]
[header-tab
"encounters"
"dungeon-gate"
route-to-my-encounters-page
false
(routes/dnd-e5-my-encounters-routes
(or (:handler active-route)
active-route))
device-type
{:name "Combat Tracker"
:route routes/dnd-e5-combat-tracker-page-route}
{:name "Encounter Builder"
:route routes/dnd-e5-encounter-builder-page-route}]
[header-tab
"My Content"
"beer-stein"
route-to-my-content-page
false
(routes/dnd-e5-my-content-routes
(or (:handler active-route)
active-route))
device-type
{:name "Content List"
:route routes/dnd-e5-my-content-route}
{:name "Feat Builder"
:route routes/dnd-e5-feat-builder-page-route}
{:name "Background Builder"
:route routes/dnd-e5-background-builder-page-route}
{:name "Language Builder"
:route routes/dnd-e5-language-builder-page-route}
{:name "Race Builder"
:route routes/dnd-e5-race-builder-page-route}
{:name "Subrace Builder"
:route routes/dnd-e5-subrace-builder-page-route}
{:name "Class Builder"
:route routes/dnd-e5-class-builder-page-route}
{:name "Subclass Builder"
:route routes/dnd-e5-subclass-builder-page-route}
{:name "Eldritch Invocation Builder"
:route routes/dnd-e5-invocation-builder-page-route}
{:name "Pact Boon Builder"
:route routes/dnd-e5-boon-builder-page-route}
{:name "Selection Builder"
:route routes/dnd-e5-selection-builder-page-route}]]]]]]))
(def registration-content-style
{:background-color :white
:border "1px solid white"
:color text-color})
(def registration-page-style
{:background-image "url(/image/login-side.jpg)"
:background-clip :content-box
:width "350px"
:min-height "600px"})
(def registration-left-column-style
{:flex-direction :column
:width "435px"})
(def registration-header-style
{:height "65px"
:background-color "#1a2532"
:border-right "1px solid white"})
(defn route-to-default-page []
(dispatch [:route :default]))
(defn registration-page [content]
[:div.sans.h-full.flex
{:style {:flex-direction :column}}
[:div.flex.justify-cont-s-a.align-items-c.flex-grow-1.h-100-p
[:div.registration-content
{:style registration-content-style}
[:div.flex.h-100-p
[:div.flex {:style registration-left-column-style}
[:div.flex.justify-cont-s-a.align-items-c
{:style registration-header-style}
[:img.h-55.pointer
{:src "/image/dmv-logo.svg"
:on-click route-to-default-page}]]
[:div.flex-grow-1 content]
[views-2/legal-footer]]
[:div.registration-image
{:style registration-page-style}]]]]])
(def make-event-handler
(memoize
(fn [event-kw & args]
#(dispatch (vec (cons event-kw args))))))
(def make-stop-prop-event-handler
(memoize
(fn [event-kw & args]
(fn [e]
(dispatch (vec (cons event-kw args)))
(.stopPropagation e)))))
(defn verify-failed []
(let [params (r/atom {})]
(fn []
(registration-page
[:div.flex.justify-cont-s-b {:style {:text-align :center
:flex-direction :column}}
[:div.p-20
[:div.f-w-b.f-s-24.p-b-10
"Your key has expired."]
[:div "You must verify your email within 24 hours of registering. Send another verification email by submitting you address here:"]
[base-input
{:name :email
:value (:email @params)
:type :email
:placeholder "Email"
:style default-input-style
:on-change (partial set-value params :email)}]
[:button.form-button.m-l-20.m-t-10
{:style {:height "40px"
:width "174px"
:font-size "16px"
:font-weight "600"}
:on-click (make-event-handler :re-verify @params)}
"RESEND"]]]))))
(def message-style
{:padding "10px"
:border-radius "5px"
:display :flex
:justify-content :space-between})
(defn message [message-type message-text close-handler]
[:div.pointer.f-w-b ;;.h-0.opacity-0.fade-out
{:on-click close-handler}
[:div.white
{:style message-style
:class-name (case message-type
:error "bg-red"
:warning "bg-orange"
"bg-green")}
[:span message-text]
[:i.fa.fa-times]]])
(defn hide-login-message []
(dispatch [:hide-login-message]))
(defn send-password-reset-page []
(let [params (r/atom {})]
(fn [error-message]
(let [email (:email @params)
bad-email? (registration/bad-email? email)]
(registration-page
[:div.flex.justify-cont-s-b.w-100-p
{:style {:text-align :center
:flex-direction :column}}
[:div.p-t-10
(if error-message [:div.red.m-b-20 error-message])
[:div.f-w-b.f-s-24.p-b-10
"Send Password Reset Email"]
[:div.m-b-10 "Submit your email address here and we will send you a link to reset your password."]
[form-input
{:title "Email"
:key :email
:messages (if bad-email?
["Not a valid email address"]
[])
:type :email
:value email
:on-change (partial set-value params :email)}]
(if @(subscribe [:login-message-shown?])
[:div.m-t-5.p-r-5.p-l-5
[message
:error
@(subscribe [:login-message])
hide-login-message]])
[:button.form-button.m-t-10
{:style {:height "40px"
:width "174px"
:font-size "16px"
:font-weight "600"}
:class-name (if bad-email? "disabled opacity-5 hover-no-shadow")
:on-click (if (not bad-email?) (make-event-handler :send-password-reset @params))}
"SUBMIT"]]])))))
(defn password-reset-expired-page []
[send-password-reset-page "Your reset link has expired, you must complete the reset within 24 hours. Please use the form below to send another reset email."])
(defn password-reset-used-page []
[send-password-reset-page "Your reset link has already been used. Please use the form below to send another reset email."])
(defn password-validation-messages [password]
(-> password
registration/validate-password
:password))
(defn password-reset-page []
(let [params (r/atom {})]
(fn []
(let [password (:password @params)
verify-password (:verify-password @params)
password-messages (password-validation-messages password)
different? (not= password verify-password)
invalid? (or (seq password-messages)
different?)]
(registration-page
[:div.flex.justify-cont-s-b {:style {:text-align :center
:flex-direction :column}}
[:div.p-20
[:div.f-w-b.f-s-24.p-b-10
"Reset Password"]
[:div "Create a new password."]
[form-input {:title "Password"
:key :password
:value password
:type :password
;;:messages password-messages
:on-change (fn [e] (swap! params assoc :password (event-value e)))}]
[form-input {:title "Verify Password"
:key :verify-password
:value verify-password
:type :password
:messages (if different? ["Passwords do not match"])
:on-change (fn [e] (swap! params assoc :verify-password (event-value e)))}]
(if @(subscribe [:login-message-shown?])
[:div.m-t-5.p-r-5.p-l-5 [message
:error
@(subscribe [:login-message])
hide-login-message]])
[:button.form-button.m-l-20.m-t-10
{:style {:height "40px"
:width "174px"
:font-size "16px"
:font-weight "600"}
:class-name (if invalid? "opacity-5 hover-no-shadow cursor-disabled")
:on-click (if (not invalid?) (make-event-handler :password-reset @params))}
"SUBMIT"]]])))))
(defn login-link []
[:span.underline.f-w-b.m-l-10.pointer.orange
{:on-click dispatch-route-to-login}
"LOGIN"])
(defn verify-success []
(registration-page
[:div {:style {:text-align :center}}
[:div {:style {:color orange
:font-weight :bold
:font-size "36px"
:text-transform :uppercase
:text-shadow "1px 2px 1px rgba(0,0,0,0.37)"
:margin-top "100px"}}
"Success! Registration is complete"]
[:div.m-t-20 "You can now"]
[login-link]]))
(defn password-reset-success []
(registration-page
[:div {:style {:text-align :center}}
[:div {:style {:color orange
:font-weight :bold
:font-size "36px"
:text-transform :uppercase
:text-shadow "1px 2px 1px rgba(0,0,0,0.37)"
:margin-top "100px"}}
"Your password has been successfully reset"]
[:div.m-t-20 "You can now log in"]
[login-link]]))
(defn email-sent [text]
(registration-page
[:div {:style {:text-align :center}}
[:div {:style {:color orange
:font-weight :bold
:font-size "36px"
:text-transform :uppercase
:text-shadow "1px 2px 1px rgba(0,0,0,0.37)"
:margin-top "100px"}}
"Check your email"]
[:div.p-20
text]]))
(defn verify-sent []
(email-sent
[:div
[:span "We sent a verification email to "]
[:span.f-w-b.red.f-s-18 @(subscribe [:temp-email])]
[:span ". You must verify to complete registration and the link we sent will only be valid for 24 hours."]]))
(defn password-reset-sent []
(email-sent
(str "We sent an email to "
@(subscribe [:temp-email])
" with a link to reset your password.")))
(defn register-form []
(let [registration-validation @(subscribe [:registration-validation])
registration-form @(subscribe [:registration-form])
send-updates? (not= false (:send-updates? registration-form))
password-strength (registration/password-strength (:password registration-form))]
(registration-page
[:div {:style {:text-align :center}}
[:div {:style {:color orange
:font-weight :bold
:font-size "36px"
:text-transform :uppercase
:text-shadow "1px 2px 1px rgba(0,0,0,0.37)"
:margin-top "20px"}}
"join for free"]
[:div.f-s-16.m-t-20 "Join now to save your characters and more!"]
[:div.m-t-10
[form-input {:title "Username"
:key :username
:value (:username registration-form)
:messages (:username registration-validation)
:type :username
:on-change (fn [e] (dispatch [:registration-username (event-value e)]))}]
[form-input {:title "Email"
:key :email
:value (:email registration-form)
:messages (:email registration-validation)
:type :email
:on-change (fn [e] (dispatch [:registration-email (event-value e)]))}]
[form-input {:title "Verify Email"
:key :verify-email
:value (:verify-email registration-form)
:messages (:verify-email registration-validation)
:type :email
:on-change (fn [e] (dispatch [:registration-verify-email (event-value e)]))}]
[form-input {:title "Password"
:key :password
:value (:password registration-form)
:messages (:password registration-validation)
:type :password
:on-change (fn [e] (dispatch [:registration-password (event-value e)]))}]
(let [[color text]
(cond
(= 5 password-strength) ["bg-green" "Strong"]
(< 1 password-strength 5) ["bg-orange" "Moderate"]
:else ["bg-red" "Weak"])]
[:div.p-r-10.p-l-10.p-t-5
[:div
{:style {:position :relative
:height "30px"}}
[:div.b-rad-5
{:style {:top 0
:left 0
:height "30px"
:opacity "0.7"
:width "100%"
:position :absolute}
:class-name color}]
[:div.b-rad-5.password-strength-meter
{:style {:top 0
:left 0
:position :absolute
:height "30px"
:transition "width 1s"
:width (str (* 100 (float (/ password-strength 5))) "%")}
:class-name color}]
[:div.main-text-color.p-l-10.b-rad-5
{:style {:position :absolute
:padding-top "6px"}}
[:span "Password Strength:"]
[:span.f-w-b.m-l-5 text]]]])
[:div.m-t-20
{:style {:text-align :left
:margin-left "15px"}}
[:i.fa.fa-check.f-s-14.pointer
{:class-name (if send-updates? "orange" "white")
:style {:margin-top "-3px"
:border-color "#f0a100"
:border-style :solid
:border-width "1px"
:border-bottom-width "3px"}
:on-click #(dispatch [:registration-send-updates? (not send-updates?)])}]
[:span.m-l-5 "Yes! Send me updates about OrcPub."]]
[:div.m-t-30
[:div.p-10
[:span "Already have an account?"]
(login-link)]
[:button.form-button
{:style {:height "40px"
:width "174px"
:font-size "16px"
:font-weight "600"}
:class-name (if (seq registration-validation) "opacity-5 hover-no-shadow cursor-disabled")
:on-click #(if (empty? registration-validation)
(dispatch [:register]))}
"JOIN"]]]
[:div.m-t-5.p-r-10.p-l-10
[:span.f-s-14
"By clicking JOIN you agree to our"
[:a.m-l-5 {:href "/terms-of-use" :target :_blank
:style {:color text-color}} "Terms of Use"]
[:span.m-l-5 "and that you've read our"]
[:a.m-l-5 {:href "/privacy-policy" :target :_blank
:style {:color text-color}} "Privacy Policy"]]]])))
(defn route-to-register-page []
(dispatch [:route routes/register-page-route {:secure true :no-return? true}]))
(defn route-to-reset-password-page []
(dispatch [:route routes/send-password-reset-page-route {:secure? true :no-return? true}]))
(defn login-page []
(let [params (r/atom {})]
(fn []
(let [login-message-shown? @(subscribe [:login-message-shown?])
login-message @(subscribe [:login-message])]
(registration-page
[:div {:style {:text-align :center}}
[:div {:style {:color orange
:font-weight :bold
:font-size "36px"
:text-transform :uppercase
:text-shadow "1px 2px 1px rgba(0,0,0,0.37)"
:margin-top "20px"}}
"LOGIN"]
;[:div.m-t-10
; [facebook-login-button]]
[:div
{:style {:margin-top "50px"}}
[form-input {:title "Username or Email"
:key :username
:value (:username @params)
:type :username
:on-change #(swap! params assoc :username (event-value %))}]
[form-input {:title "Password"
:key :password
:value (:password @params)
:type :password
:on-change #(swap! params assoc :password (event-value %))}]
(if login-message-shown?
[:div.m-t-5.p-r-5.p-l-5 [message
:error
login-message
hide-login-message]])
[:div.m-t-10
[:button.form-button
{:style {:height "40px"
:width "174px"
:font-size "16px"
:font-weight "600"}
:on-click #(dispatch [:login @params true])}
"LOGIN"]
[:div.m-t-20
[:span "Don't have a login? "]
[:span.orange.underline.pointer
{:on-click route-to-register-page}
"REGISTER NOW"]]
[:div.m-t-20
[:span "Forgot your password? "]
[:span.orange.underline.pointer
{:on-click route-to-reset-password-page}
"RESET PASSWORD"]]]]])))))
(def loading-style
{:position :fixed
:height "100%"
:width "100%"
:top 0
:bottom 0
:right 0
:left 0
:z-index 100
:background-color "rgba(0,0,0,0.6)"})
(defn hide-confirmation []
(dispatch [:hide-confirmation]))
(defn hide-message []
(dispatch [:hide-message]))
(defn confirm-fn [cfg]
#(do
(if (:pre cfg)
((:pre cfg)))
(dispatch [:confirm (:event cfg)])))
(def confirm-handler (memoize confirm-fn))
(defn header [title button-cfgs & {:keys [frame?]}]
(let [device-type @(subscribe [:device-type])]
[:div.w-100-p
[:div.flex.align-items-c.justify-cont-s-b.flex-wrap
[:div.flex
[:h1.f-s-36.f-w-b.m-t-5.m-l-10
{:class-name (if (not= :mobile device-type) "m-t-21 m-b-20")}
title]
(if frame?
logo)]
[:div.flex.align-items-c.justify-cont-end.flex-wrap.m-r-10.m-l-10
(map-indexed
(fn [i {:keys [title icon on-click style class-name] :as cfg}]
(if (vector? cfg)
(with-meta
cfg
{:key i})
^{:key i}
[:button.form-button.h-40.m-l-5.m-t-5.m-b-5
{:on-click on-click
:class-name class-name
:style style}
[:span
[:i.fa.f-s-18
(if icon {:class-name (str "fa-" icon)})]]
[:span.m-l-5.header-button-text title]]))
button-cfgs)]]
(if @(subscribe [:confirmation-shown?])
[:div.flex.justify-cont-end.m-r-10.m-b-20.m-l-10
(let [cfg @(subscribe [:confirmation-cfg])]
[:div
[:div.f-w-b (:question cfg)]
[:div.flex.justify-cont-end.m-t-5
[:button.form-button
{:on-click hide-confirmation}
"CANCEL"]
[:button.link-button.underline.f-w-b
{:on-click (confirm-handler cfg)}
(:confirm-button-text cfg)]]])])
(if @(subscribe [::char/options-shown?])
[:div.bg-light.m-b-10 @(subscribe [::char/options-component])])
(if @(subscribe [:message-shown?])
[:div.p-b-10.p-r-10.p-l-10.white
[message
@(subscribe [:message-type])
@(subscribe [:message])
hide-message]])]))
(def debug-data-style {:width "400px" :height "450px"})
(defn clj->json
[ds]
(.stringify js/JSON (clj->js ds) nil 2))
(defn debug-data []
(let [expanded? (r/atom false)]
(fn []
[:div.t-a-r
[:div.orange.pointer.underline
{:on-click (make-event-handler ::e5/export-all-plugins-pretty-print)
:title "Development - Download all Orcbrews as Pretty Print, if you click this button it will take a long time to generate the orcbrew. Click and wait."}
[:i.fa.fa-cloud-download-alt]]
[:div.orange.pointer.underline
{:on-click #(swap! expanded? not)
:title "Development - Debug Info" }
[:i.fa.fa-bug {:class-name (if @expanded? "white")}]]
(if @expanded?
[:textarea.m-t-5
{:read-only true
:style debug-data-style
:value (str {:browser (user-agent/browser)
:browser-version (user-agent/browser-version)
:device-type (user-agent/device-type)
:platform (user-agent/platform)
:platform-version (user-agent/platform-version)
:character (char/to-strict @(subscribe [:character]))})}])