-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcit.cirru
More file actions
1314 lines (1313 loc) · 57.5 KB
/
Copy pathcalcit.cirru
File metadata and controls
1314 lines (1313 loc) · 57.5 KB
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
{} (:about "|Machine-generated snapshot. Do not edit directly — changes will be overwritten. Use `calcit query` to inspect and `calcit edit`/`calcit tree` to modify. Run `calcit docs agents --full` first. Manual edits must follow format and schema conventions, then run `calcit edit format`.") (:package |app)
:entries $ {}
:default $ {} (:description |) (:init-fn 'app.client/main!) (:mode :js) (:reload-fn 'app.client/reload!)
:feature-policy $ {}
:modules $ [] |respo.calcit/ |lilac/ |recollect/ |memof/ |respo-ui.calcit/ |ws-edn.calcit/ |cumulo-util.calcit/ |respo-message.calcit/ |cumulo-reel.calcit/ |respo-feather.calcit/ |alerts.calcit/
:type-slots $ {}
:server $ {} (:description |) (:init-fn 'app.server/main!) (:mode :native) (:reload-fn 'app.server/reload!)
:feature-policy $ {}
:modules $ [] |lilac/ |recollect/ |memof/ |cumulo-util.calcit/ |cumulo-reel.calcit/ |calcit.std/ |calcit-wss/ |respo.calcit/
:type-slots $ {}
:files $ {}
'app.client $ %{} 'FileEntry
:defs $ {}
'*states $ %{} 'CodeEntry (:doc |)
:code $ quote
defatom *states $ {}
:states $ {}
:cursor $ []
:examples $ []
:schema $ :: 'Dynamic
'*store $ %{} 'CodeEntry (:doc |)
:code $ quote (defatom *store nil)
:examples $ []
:schema $ :: 'Dynamic
'connect! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn connect! () $ let
url-obj $ unsafe-coerce (url-parse js/location.href true) 'JsObject
query $ unsafe-coerce (.-query url-obj) 'JsObject
host-value $ .-host query
port-value $ .-port query
host $ if (js-present? host-value) (unsafe-coerce host-value 'String) (unsafe-coerce js/location.hostname 'String)
port $ if (js-present? port-value) (unsafe-coerce port-value 'String)
str $ :port config/site
ws-connect!
if config/dev? (str |ws:// host |: port) (str |wss:// host |/ws)
{}
:on-open $ fn (event) (simulate-login!)
:on-close $ fn (event) (reset! *store nil) (js/console.error "|Lost connection!")
:on-data on-server-data
:examples $ []
:schema $ :: 'Dynamic
'dispatch! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when
and config/dev? $ not=
-> (nth op 0) (.unwrap-or :unknown)
, :states
js/console.log |Dispatch op
match op
(:states cursor state)
reset! *states $ update-states (deref *states) cursor state
(:effect/connect) (connect!)
_ $ ws-send! op
:examples $ []
:schema $ :: 'Dynamic
'main! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn main! ()
println "|Running mode:" $ if config/dev? |dev |release
if config/dev? $ load-console-formatter!
render-app!
connect!
add-watch *store :changes $ fn (store prev) (render-app!)
add-watch *states :changes $ fn (states prev) (render-app!)
on-page-touch $ fn ()
if (nil? @*store) (connect!)
println "|App started!"
:examples $ []
:schema $ :: 'Dynamic
'mount-target $ %{} 'CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector |.app
:examples $ []
:schema $ :: 'Dynamic
'on-server-data $ %{} 'CodeEntry (:doc |)
:code $ quote
defn on-server-data (data)
match data $
:patch changes
do
when config/dev? $ js/console.log |Changes changes
reset! *store $ patch-twig @*store changes
:examples $ []
:schema $ :: 'Dynamic
'reload! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn reload! () $ if
or (some? client-errors) (some? server-errors)
hud! |error $ str client-errors &newline server-errors
do (hud! |inactive nil) (remove-watch *store :changes) (remove-watch *states :changes) (clear-cache!) (render-app!)
add-watch *store :changes $ fn (store prev) (render-app!)
add-watch *states :changes $ fn (states prev) (render-app!)
println "|Code updated."
:examples $ []
:schema $ :: 'Dynamic
'render-app! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn render-app! () $ render! mount-target
comp-container (app.schema/read-field @*states :states) @*store
, dispatch!
:examples $ []
:schema $ :: 'Dynamic
'simulate-login! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn simulate-login! () $ let
raw $ js/localStorage.getItem (:storage-key config/site)
if (js-present? raw)
do (println "|Found storage.")
dispatch! $ :: :user/log-in
parse-cirru-edn $ unsafe-coerce raw 'String
do $ println "|Found no storage."
:examples $ []
:schema $ :: 'Dynamic
'ssr? $ %{} 'CodeEntry (:doc |)
:code $ quote
def ssr? $ some? (.querySelector js/document |meta.respo-ssr)
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.client $ :require
[] respo.core :refer $ [] render! clear-cache! realize-ssr!
[] respo.cursor :refer $ [] update-states
[] app.comp.container :refer $ [] comp-container
[] cljs.reader :refer $ [] read-string
[] app.schema :as schema
[] app.config :as config
[] ws-edn.client :refer $ [] ws-connect! ws-send!
[] recollect.patch :refer $ [] patch-twig
[] cumulo-util.core :refer $ [] on-page-touch
[] |url-parse :default url-parse
|bottom-tip :default hud!
|./calcit.build-errors :default client-errors
|../js-out/calcit.build-errors :default server-errors
'app.comp.container $ %{} 'FileEntry
:defs $ {}
'comp-container $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-container (states store)
let
state $ app.schema/read-field states :data
session $ app.schema/read-field store :session
router $ app.schema/read-field store :router
router-data $ app.schema/read-field router :data
if (nil? store) (comp-offline)
div
{} $ :style (merge ui/global ui/fullscreen ui/column)
comp-navigation (app.schema/read-field store :logged-in?) (app.schema/read-field store :count)
if (app.schema/read-field store :logged-in?)
case (app.schema/read-field router :name)
:home $ comp-dashboard (>> states :dashboard) router-data
:emotions $ comp-emotions-manager router-data
:edit-emotion $ comp-emotion-form (>> states :form) router-data
:history $ comp-history (>> states :history) (app.schema/read-field router-data :moods) (app.schema/read-field router-data :emotions)
:profile $ comp-profile (app.schema/read-field store :user) router-data
<> router
comp-login states
; comp-status-color $ :color store
when dev? $ comp-inspect |Store store
{} (:bottom 20) (:left 0) (:max-width |100%)
comp-messages
unsafe-coerce
->
get-in store $ [] :session :messages
.unwrap-or $ {}
:: 'Map 'String 'Dynamic
{}
fn (info d!) (d! :session/remove-message info)
; when dev? $ comp-reel (:reel-length store)
{} (:bottom 100) (:background-color :white)
:examples $ []
:schema $ :: 'Dynamic
'comp-offline $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-offline () $ div
{} $ :style
merge
unsafe-coerce ui/global $ :: 'Map 'Tag 'Dynamic
unsafe-coerce ui/fullscreen $ :: 'Map 'Tag 'Dynamic
unsafe-coerce ui/column-dispersive $ :: 'Map 'Tag 'Dynamic
unsafe-coerce
{} $ :background-color :white
:: 'Map 'Tag 'Dynamic
div $ {}
:style $ {} (:height 0)
div $ {}
:style $ {}
:background-image $ str "|url(" (:icon config/site) "|)"
:width 86
:height 86
:background-size :contain
div
{}
:style $ {} (:cursor :pointer) (:line-height |32px)
:on-click $ fn (e d!) (d! :effect/connect nil)
<> "|No connection..." $ {} (:font-family ui/font-fancy) (:font-size 24)
:examples $ []
:schema $ :: 'Dynamic
'comp-status-color $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-status-color (color)
div $ {}
:style $ let
size 24
{} (:width size) (:height size) (:position :absolute) (:bottom 60) (:left 8) (:background-color color) (:border-radius |50%) (:opacity 0.6) (:pointer-events :none)
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
[] hsl.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp <> >> div span button
[] respo.comp.inspect :refer $ [] comp-inspect
[] respo.comp.space :refer $ [] =<
[] app.comp.navigation :refer $ [] comp-navigation
[] app.comp.profile :refer $ [] comp-profile
[] app.comp.login :refer $ [] comp-login
[] respo-message.comp.messages :refer $ [] comp-messages
[] cumulo-reel.comp.reel :refer $ [] comp-reel
[] app.config :refer $ [] dev?
[] app.schema :as schema
[] app.config :as config
[] app.comp.dashboard :refer $ [] comp-dashboard
[] app.comp.emotions :refer $ [] comp-emotions-manager
[] app.comp.history :refer $ [] comp-history
[] app.comp.emotion-form :refer $ [] comp-emotion-form
'app.comp.dashboard $ %{} 'FileEntry
:defs $ {}
'comp-dashboard $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-dashboard (states router-data)
let
cursor $ app.schema/read-field states :cursor
state $ or (app.schema/read-field states :data)
{} (:show-editor? false) (:emotion-id nil) (:draft |)
emotions $ or (app.schema/read-field router-data :emotions) ({})
moods $ or (app.schema/read-field router-data :moods) ({})
div
{} $ :style
{} $ :padding "|8px 16px"
comp-title "|What do you feel now?"
=< nil 16
list-> emotions $ -> (unsafe-coerce emotions 'Map) (.to-list)
.sort-by $ fn (pair)
negate $ assert-type
app.schema/read-field (last pair) :score
, 'Number
.map-pair $ fn (k emotion)
[] k $ comp-emotion emotion nil
fn (e d!)
d! cursor $ merge state
{} (:show-editor? true)
:emotion-id $ app.schema/read-field emotion :id
=< nil 0
div
{} $ :style ui/row-parted
span $ {}
a
{}
:style $ merge ui/link
:on-click $ fn (e d!)
d! :router/change $ {} (:name :emotions)
comp-i :settings 16 $ hsl 200 80 80
=< nil 16
div ({})
a
{} (:style ui/link)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :history)
<> "|View history"
div ({})
list-> ({})
-> (unsafe-coerce moods 'Map) (.to-list)
.sort-by $ fn (pair)
negate $ assert-type
app.schema/read-field (last pair) :time
, 'Number
.map-pair $ fn (k mood)
[] k $ let
emotion-id $ app.schema/read-field mood :emotion-id
div
{} $ :style ui/row
comp-emotion (get emotions emotion-id) nil $ fn (e d!)
div
{} $ :style
merge ui/expand $ {} (:white-space :nowrap) (:text-overflow :ellipsis) (:overflow :hidden)
<> $ app.schema/read-field mood :text
comp-modal
{}
:style $ {} (:width 400) (:max-width |86%)
:render $ fn (on-close)
div
{} $ :style
{} (:min-width 240) (:padding 20)
div
{} $ :style ui/row-middle
<> "|In mood"
=< 8 nil
comp-emotion
get emotions $ app.schema/read-field state :emotion-id
, nil $ fn ()
div ({})
textarea $ {}
:style $ merge ui/textarea
{} (:width |100%) (:min-height 160)
:value $ app.schema/read-field state :draft
:placeholder "|Some notes..."
:on-input $ fn (e d!)
d! cursor $ assoc state :draft (app.schema/read-field e :value)
=< nil 8
div
{} $ :style ui/row-parted
span $ {}
button $ {} (:style ui/button) (:inner-text |Submit)
:on-click $ fn (e d!)
d! :mood/create-one $ {}
:text $ app.schema/read-field state :draft
:emotion-id $ app.schema/read-field state :emotion-id
d! cursor $ -> state (assoc :show-editor? false) (assoc :draft |)
app.schema/read-field state :show-editor?
fn (d!)
d! cursor $ assoc state :show-editor? false
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.dashboard $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp <> list-> span div input a button textarea pre
[] app.config :as config
[] app.comp.emotions :refer $ [] comp-emotion
[] app.comp.kit :refer $ [] comp-title
[] feather.core :refer $ [] comp-i
[] respo-alerts.core :refer $ [] comp-modal
'app.comp.emotion-form $ %{} 'FileEntry
:defs $ {}
'comp-color-picker $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-color-picker (form on-pick)
list-> ({})
-> default-colors $ map
fn (color)
[] color $ div
{}
:style $ let
size 24
{} (:background-color color) (:height size) (:width size) (:border-radius |6px) (:display :inline-block) (:margin "|0 8px 8px 0") (:cursor :pointer)
:on-click $ fn (e d!) (on-pick color d!)
:examples $ []
:schema $ :: 'Dynamic
'comp-emotion-form $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-emotion-form (states data)
let
cursor $ app.schema/read-field states :cursor
form $ or (app.schema/read-field states :data) (or data schema/emotion)
editing? $ some? (app.schema/read-field form :id)
delete-plugin $ use-confirm (>> states :delete)
{} $ :text "|Sure to delete?"
div
{} $ :style
{} $ :padding "|8px 16px"
div ({}) (comp-title "|Emotion details")
=< nil 16
comp-field |Name $ input
{} (:style ui/input)
:value $ app.schema/read-field form :text
:on-input $ fn (e d!)
d! cursor $ assoc form :text (app.schema/read-field e :value)
comp-field |Score $ input
{} (:style ui/input)
:value $ app.schema/read-field form :score
:type |number
:on-input $ fn (e d!)
d! cursor $ assoc form :score (app.schema/read-field e :value)
comp-field |Color $ div
{} $ :style ui/column
input $ {}
:style $ merge ui/input
{} $ :font-family ui/font-code
:value $ app.schema/read-field form :color
:on-input $ fn (e d!)
d! cursor $ assoc form :color (app.schema/read-field e :value)
=< nil 8
comp-color-picker form $ fn (color d!)
d! cursor $ assoc form :color color
=< nil 16
div
{} $ :style ui/row-parted
span $ {}
span ({})
when editing? $ button
{}
:style $ merge ui/button
{} (:color :white)
:background-color $ hsl 10 50 70
:border $ hsl 10 50 60
:inner-text |Delete
:on-click $ fn (e d!)
.show delete-plugin d! $ fn ()
d! :router/change $ {} (:name :emotions)
d! :emotion/remove-one $ app.schema/read-field form :id
when editing? $ =< 8 nil
button $ {} (:style ui/button)
:on-click $ fn (e d!) (d! :emotion/create-one form) (d! cursor nil)
d! :router/change $ {} (:name :emotions)
:inner-text $ if editing? |Save |Create
.render delete-plugin
:examples $ []
:schema $ :: 'Dynamic
'default-colors $ %{} 'CodeEntry (:doc |)
:code $ quote
def default-colors $ [] |#ff9e96 |#e7e5e5 |#baf9c2 |#c6ded2 |#5facf6 |#c390e8 |#ffdd57 |#f79800 |#cf0027
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.emotion-form $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp <> >> list-> span div button input
[] app.config :as config
[] app.schema :as schema
[] respo-alerts.core :refer $ [] use-confirm
[] app.comp.kit :refer $ [] comp-field comp-title
'app.comp.emotions $ %{} 'FileEntry
:defs $ {}
'comp-emotion $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-emotion (emotion style on-click!)
div
{}
:style $ merge ui/center
{}
:background-color $ app.schema/read-field emotion :color
:display :inline-flex
:padding "|0 16px"
:line-height |24px
:height |24px
:margin "|0 8px 8px 0"
:border-radius |8px
:color :white
, style
:on-click on-click!
<> $ app.schema/read-field emotion :text
:examples $ []
:schema $ :: 'Dynamic
'comp-emotions-manager $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-emotions-manager (emotions)
div
{} $ :style
{} $ :padding "|8px 16px"
div
{} $ :style ui/row-middle
<> |Emotions $ {} (:font-family ui/font-fancy) (:font-size 24)
=< 8 nil
a
{}
:on-click $ fn (e d!)
d! :router/change $ {} (:name :edit-emotion) (:data nil)
:style $ {} (:font-size 16)
comp-i :plus 16 $ hsl 200 80 80
=< nil 16
div ({})
list-> ({})
-> (unsafe-coerce emotions 'Map) (.to-list)
.map-pair $ fn (k emotion)
[] k $ comp-emotion emotion nil
fn (e d!)
d! :router/change $ {} (:name :edit-emotion)
:data $ app.schema/read-field emotion :id
=< nil 32
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.emotions $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp <> list-> span div button a
[] app.config :as config
[] feather.core :refer $ [] comp-i
'app.comp.history $ %{} 'FileEntry
:defs $ {}
'comp-history $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-history (states moods emotions)
div
{} $ :style
merge
unsafe-coerce ui/flex $ :: 'Map 'Tag 'Dynamic
unsafe-coerce ui/column $ :: 'Map 'Tag 'Dynamic
unsafe-coerce
{} $ :overflow :auto
:: 'Map 'Tag 'Dynamic
div
{} $ :style
{} (:margin "|8px 0") (:padding "|8px 16px")
comp-title |History
list->
{} $ :style
merge
unsafe-coerce ui/flex $ :: 'Map 'Tag 'Dynamic
unsafe-coerce
{} (:width |100%) (:padding "|8px 16px")
:: 'Map 'Tag 'Dynamic
-> (unsafe-coerce moods 'Map) (.to-list)
.sort-by $ fn (pair)
negate $ assert-type
app.schema/read-field (last pair) :time
, 'Number
.map-pair $ fn (k mood)
[] k $ comp-record
>> states $ app.schema/read-field mood :id
, mood emotions
:examples $ []
:schema $ :: 'Dynamic
'comp-record $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-record (states mood emotions)
let
remove-plugin $ use-confirm (>> states :remove)
{} $ :text "|Sure to delete?"
div
{} (:class-name |)
:style $ merge ui/column
{}
:border-bottom $ str "|1px solid " (hsl 0 0 90)
:padding "|8px 0"
div
{} $ :style ui/row-parted
div
{} $ :style ui/row-middle
comp-emotion
get emotions $ app.schema/read-field mood :emotion-id
, nil nil
comp-hint $ ->
dayjs $ app.schema/read-field mood :time
.!format "|MM-DD HH:mm"
span
{} $ :on-click
fn (e d!)
.show remove-plugin d! $ fn ()
d! :mood/remove-one $ app.schema/read-field mood :id
comp-i :x 14 $ hsl 0 0 80
div $ {}
:inner-text $ app.schema/read-field mood :text
:style $ merge
unsafe-coerce ui/flex $ :: 'Map 'Tag 'Dynamic
unsafe-coerce
{} $ :word-break :break-all
:: 'Map 'Tag 'Dynamic
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.history $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp >> <> list-> span div a
[] app.config :as config
[] app.comp.kit :refer $ [] comp-title
[] app.comp.emotions :refer $ [] comp-emotion
[] |dayjs :default dayjs
[] app.comp.kit :refer $ [] comp-hint
[] feather.core :refer $ [] comp-icon comp-i
[] respo-alerts.core :refer $ [] use-confirm
'app.comp.kit $ %{} 'FileEntry
:defs $ {}
'comp-field $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-field (label child)
div
{} $ :style
merge
unsafe-coerce ui/row $ :: 'Map 'Tag 'Dynamic
unsafe-coerce
{} $ :margin-bottom 16
:: 'Map 'Tag 'Dynamic
div
{} $ :style
{} $ :width 64
<> label
, child
:examples $ []
:schema $ :: 'Dynamic
'comp-hint $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-hint (text)
<> text $ {}
:color $ hsl 0 0 80
:examples $ []
:schema $ :: 'Dynamic
'comp-title $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-title (text)
<> text $ {} (:font-family ui/font-fancy) (:font-size 24)
:color $ hsl 0 0 60
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.kit $ :require
[] respo-ui.core :refer $ [] hsl
[] app.schema :as schema
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp list-> <> span div button
[] respo.comp.space :refer $ [] =<
[] app.config :as config
'app.comp.login $ %{} 'FileEntry
:defs $ {}
'comp-login $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-login (states)
let
cursor $ app.schema/read-field states :cursor
state $ or (app.schema/read-field states :data) initial-state
div
{} $ :style
merge
unsafe-coerce ui/flex $ :: 'Map 'Tag 'Dynamic
unsafe-coerce ui/center $ :: 'Map 'Tag 'Dynamic
div ({})
div
{} $ :style ({})
div ({})
input $ {} (:placeholder |Username)
:value $ app.schema/read-field state :username
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :username (app.schema/read-field e :value)
=< nil 8
div ({})
input $ {} (:placeholder |Password)
:value $ app.schema/read-field state :password
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :password (app.schema/read-field e :value)
=< nil 8
div
{} $ :style
{} $ :text-align :right
span $ {} (:inner-text "|Sign up")
:style $ merge ui/link
:on-click $ on-submit (app.schema/read-field state :username) (app.schema/read-field state :password) true
=< 8 nil
span $ {} (:inner-text "|Log in")
:style $ merge ui/link
:on-click $ on-submit (app.schema/read-field state :username) (app.schema/read-field state :password) false
:examples $ []
:schema $ :: 'Dynamic
'initial-state $ %{} 'CodeEntry (:doc |)
:code $ quote
def initial-state $ {} (:username |) (:password |)
:examples $ []
:schema $ :: 'Dynamic
'on-submit $ %{} 'CodeEntry (:doc |)
:code $ quote
defn on-submit (username password signup?)
fn (e dispatch!)
dispatch! (if signup? :user/sign-up :user/log-in) ([] username password)
js/localStorage.setItem (:storage-key config/site)
format-cirru-edn $ [] username password
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.login $ :require
[] respo.core :refer $ [] defcomp <> div input button span
[] respo.comp.space :refer $ [] =<
[] respo.comp.inspect :refer $ [] comp-inspect
[] respo-ui.core :as ui
[] app.schema :as schema
[] app.config :as config
'app.comp.navigation $ %{} 'FileEntry
:defs $ {}
'comp-navigation $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-navigation (logged-in? count-members)
div
{} $ :style
merge ui/row-center $ {} (:height 48) (:justify-content :space-between) (:padding "|0 16px") (:font-size 16)
:border-bottom $ str "|1px solid " (hsl 0 0 0 0.1)
:font-family ui/font-fancy
div
{}
:on-click $ fn (e d!)
d! :router/change $ {} (:name :home)
:style $ {} (:cursor :pointer)
<>
assert-type (app.schema/read-field config/site :title) 'String
, nil
div
{}
:style $ {} (:cursor |pointer)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :profile)
<> $ if logged-in? |Me |Guest
=< 8 nil
<> count-members
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.navigation $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp <> span div
[] app.config :as config
'app.comp.profile $ %{} 'FileEntry
:defs $ {}
'comp-profile $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-profile (user members)
div
{} $ :style
merge ui/flex $ {} (:padding 16)
div
{} $ :style
{} (:font-family ui/font-fancy) (:font-size 32) (:font-weight 100)
<> $ str "|Hello! " (app.schema/read-field user :name)
=< nil 16
div
{} $ :style ui/row
<> |Members:
=< 8 nil
list->
{} $ :style ui/row
-> (unsafe-coerce members 'Map) (.to-list)
.map-pair $ fn (k username)
[] k $ div
{} $ :style
{} (:padding "|0 8px")
:border $ str "|1px solid " (hsl 0 0 80)
:border-radius |16px
:margin "|0 4px"
<> username
=< nil 48
div ({})
button
{}
:style $ merge ui/button
:on-click $ fn (e d! m!)
.replace js/location $ str js/location.origin |?time= (.now js/Date)
<> |Refresh
=< 16 nil
button
{}
:style $ merge ui/button
{} (:color :red) (:border-color :red)
:on-click $ fn (e dispatch!) (dispatch! :user/log-out nil)
js/localStorage.removeItem $ :storage-key config/site
<> "|Log out"
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.comp.profile $ :require
[] respo-ui.core :refer $ [] hsl
[] app.schema :as schema
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp list-> <> span div button
[] respo.comp.space :refer $ [] =<
[] app.config :as config
'app.config $ %{} 'FileEntry
:defs $ {}
'cdn? $ %{} 'CodeEntry (:doc |)
:code $ quote
def cdn? $ cond
exists? js/window
, false
(exists? js/process) (= |true js/process.env.cdn)
:else false
:examples $ []
:schema $ :: 'Dynamic
'dev? $ %{} 'CodeEntry (:doc |)
:code $ quote
def dev? $ = |dev
-> (get-env |mode) (.unwrap-or |release)
:examples $ []
:schema $ :: 'Dynamic
'site $ %{} 'CodeEntry (:doc |)
:code $ quote
def site $ {} (:port 11011) (:title |Pumila) (:icon |http://cdn-tc.tiye.me/logo/pumila.png) (:storage-key |pumila) (:storage-file |storage.cirru) (:theme |#6EBAEE)
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote (ns app.config)
'app.schema $ %{} 'FileEntry
:defs $ {}
'database $ %{} 'CodeEntry (:doc |)
:code $ quote
def database $ {}
:sessions $ do session ({})
:users $ do user ({})
:examples $ []
:schema $ :: 'Dynamic
'emotion $ %{} 'CodeEntry (:doc |)
:code $ quote
def emotion $ {} (:id nil) (:text |) (:score 0)
:color $ hsl 0 0 90
:examples $ []
:schema $ :: 'Dynamic
'mood $ %{} 'CodeEntry (:doc |)
:code $ quote
def mood $ {} (:id nil) (:emotion-id nil) (:text |) (:time nil)
:examples $ []
:schema $ :: 'Dynamic
'notification $ %{} 'CodeEntry (:doc |)
:code $ quote
def notification $ {} (:id nil) (:kind nil) (:text nil)
:examples $ []
:schema $ :: 'Dynamic
'read-field $ %{} 'CodeEntry (:doc |)
:code $ quote
defn read-field (value field)
if (struct? value) (&struct:get value field) (&map:get value field)
:examples $ []
:schema $ :: 'Fn
{} (:return 'Dynamic)
:args $ [] 'Dynamic 'Tag
'router $ %{} 'CodeEntry (:doc |)
:code $ quote
def router $ {} (:name nil) (:title nil)
:data $ {}
:router nil
:examples $ []
:schema $ :: 'Dynamic
'session $ %{} 'CodeEntry (:doc |)
:code $ quote
def session $ {} (:user-id nil) (:id nil) (:nickname nil)
:router $ do router
{} (:name :home) (:data nil) (:router nil)
:messages $ {}
:examples $ []
:schema $ :: 'Dynamic
'user $ %{} 'CodeEntry (:doc |)
:code $ quote
def user $ {} (:name nil) (:id nil) (:nickname nil) (:avatar nil) (:password nil)
:moods $ do mood ({})
:emotions $ do emotion ({})
:examples $ []
:schema $ :: 'Dynamic
:ns $ %{} 'NsEntry (:doc |)
:code $ quote
ns app.schema $ :require
[] respo.util.format :refer $ [] hsl
'app.server $ %{} 'FileEntry
:defs $ {}
'*client-caches $ %{} 'CodeEntry (:doc |)
:code $ quote
defatom *client-caches $ {}
:examples $ []
:schema $ :: 'Dynamic
'*initial-db $ %{} 'CodeEntry (:doc |)
:code $ quote
defatom *initial-db $ if
path-exists? $ w-log storage-file
do (println "|Found local EDN data")
merge schema/database $ parse-cirru-edn (read-file storage-file)
do (println "|Found no data") schema/database
:examples $ []
:schema $ :: 'Dynamic
'*reader-reel $ %{} 'CodeEntry (:doc |)
:code $ quote (defatom *reader-reel @*reel)
:examples $ []
:schema $ :: 'Dynamic
'*reel $ %{} 'CodeEntry (:doc |)
:code $ quote
defatom *reel $ struct-with reel-schema (:base @*initial-db) (:db @*initial-db)
:examples $ []
:schema $ :: 'Ref 'cumulo-reel.core/ReelState
'dispatch! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn dispatch! (op sid)
let
op-id $ turn-string (generate-id!)
op-time $ -> (get-time!) (.timestamp)
if config/dev? $ println |Dispatch! (str op) sid
if (= op :effect/persist) (persist-db!)
reset! *reel $ reel-reducer @*reel updater op sid op-id op-time config/dev?
:examples $ []
:schema $ :: 'Dynamic
'get-backup-path! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn get-backup-path! () $ let
now $ .extract (get-time!)
join-path calcit-dirname |backups
str $ app.schema/read-field now :month
str (app.schema/read-field now :day) |-snapshot.cirru
:examples $ []
:schema $ :: 'Dynamic
'main! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn main! ()
println "|Running mode:" $ if config/dev? |dev |release
let
p? $ get-env |port
port $ option:fold p?
fn () $ app.schema/read-field config/site :port
fn (raw)
(parse-float raw) .unwrap-or $ app.schema/read-field config/site :port
run-server! port
println $ str "|Server started on port:" port
do (; "|init it before doing multi-threading") (identity @*reader-reel)
set-interval 200 $ fn () (render-loop!)
set-interval 600000 $ fn () (persist-db!)
on-control-c on-exit!
:examples $ []
:schema $ :: 'Dynamic
'on-exit! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn on-exit! () (persist-db!) (; println "|exit code is...") (quit! 0)
:examples $ []
:schema $ :: 'Dynamic
'persist-db! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn persist-db! () $ let
file-content $ format-cirru-edn
assoc
:db $ unsafe-coerce @*reel 'cumulo-reel.core/ReelState
, :sessions $ {}
storage-path storage-file
backup-path $ get-backup-path!
check-write-file! storage-path file-content
check-write-file! backup-path file-content
:examples $ []
:schema $ :: 'Dynamic
'reload! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn reload! () (println "|Code updated..")
if (not config/dev?) (raise "|reloading only happens in dev mode")
clear-twig-caches!
reset! *reel $ refresh-reel @*reel @*initial-db updater
sync-clients! @*reader-reel
:examples $ []
:schema $ :: 'Dynamic
'render-loop! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn render-loop! () $ when
not $ identical? @*reader-reel @*reel
reset! *reader-reel @*reel
sync-clients! @*reader-reel
:examples $ []
:schema $ :: 'Dynamic
'run-server! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn run-server! (port)
wss-serve! (&{} :port port)
fn (data)
match data
(:connect sid)
do
dispatch! (:: :session/connect) sid
println "|New client."
(:message sid msg)
dispatch! (parse-cirru-edn msg) sid
(:disconnect sid)
do (println "|Client closed!")
dispatch! (:: :session/disconnect) sid
_ $ println "|unknown data:" data
:examples $ []
:schema $ :: 'Dynamic
'storage-file $ %{} 'CodeEntry (:doc |)
:code $ quote
def storage-file $ if (empty? calcit-dirname)
str calcit-dirname $ :storage-file config/site
str calcit-dirname |/ $ :storage-file config/site
:examples $ []
:schema $ :: 'Dynamic
'sync-clients! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn sync-clients! (reel)
wss-each! $ fn (sid)
let
db $ app.schema/read-field reel :db
records $ app.schema/read-field reel :records
session $
get-in db $ [] :sessions sid
, .unwrap-or schema/session
old-store $
get @*client-caches sid
, .unwrap-or nil
new-store $ twig-container db session records
changes $ diff-twig old-store new-store
{} $ :key :id
; when config/dev? $ println "|Changes for" sid |: changes (count records)
if
not= changes $ []