-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompact.cirru
More file actions
1612 lines (1611 loc) · 71 KB
/
compact.cirru
File metadata and controls
1612 lines (1611 loc) · 71 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 "|file is generated - never edit directly; learn cr edit/tree workflows before changing") (:package |app)
:configs $ {} (:init-fn |app.client/main!) (:reload-fn |app.client/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/ |recollect/ |memof/ |respo-ui.calcit/ |ws-edn.calcit/ |cumulo-util.calcit/ |respo-message.calcit/ |cumulo-reel.calcit/ |respo-feather.calcit/ |alerts.calcit/
:entries $ {}
:server $ {} (:init-fn |app.server/main!) (:reload-fn |app.server/reload!) (:version |0.0.0)
:modules $ [] |recollect/ |memof/ |cumulo-util.calcit/ |cumulo-reel.calcit/ |calcit.std/ |calcit-wss/
:files $ {}
|app.client $ %{} :FileEntry
:defs $ {}
|*states $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defatom *states $ {}
:states $ {}
:cursor $ []
:examples $ []
|*store $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defatom *store $ :: :initial
:examples $ []
|connect! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn connect! () $ let
url-obj $ url-parse js/location.href true
host $ either (-> url-obj .-query .-host) js/location.hostname
port $ either (-> url-obj .-query .-port) (:port config/site)
ws-connect!
if config/dev? (str "\"ws://" host "\":" port) "\"wss://diary.chenyong.life/ws"
{}
:on-open $ fn (event) (simulate-login!)
:on-close $ fn (event)
reset! *store $ :: :offline
js/console.error "\"Lost connection!"
:on-data on-server-data
:examples $ []
|dispatch! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn dispatch! (op)
when
and config/dev? $ not= (nth op 0) :states
println "\"Dispatch" op
tag-match op
:states cursor s
reset! *states $ update-states @*states cursor s
(:effect/connect) (connect!)
_ $ ws-send! op
:examples $ []
|main! $ %{} :CodeEntry (:doc |) (:schema nil)
: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
= @*store $ :: :offline
connect!
visibility-heartbeat $ fn ()
if (map? @*store)
ws-send! $ :: :effect/ping
println "\"App started!"
:examples $ []
|mount-target $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
def mount-target $ js/document.querySelector "\".app"
:examples $ []
|on-server-data $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn on-server-data (data)
tag-match data
:patch changes
do
when config/dev? $ js/console.log "\"Changes" changes
reset! *store $ patch-twig @*store changes
(:effect/pong) :ok
:examples $ []
|reload! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn reload! () $ if
or (some? client-errors) (some? server-errors)
hud! "\"error" $ str client-errors &newline server-errors
do (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!)
hud! "\"ok~" "\"Ok"
:examples $ []
|render-app! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn render-app! () $ render! mount-target
comp-container (:states @*states) @*store
, dispatch!
:examples $ []
|simulate-login! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn simulate-login! () $ let
raw $ js/localStorage.getItem (:storage-key config/site)
if (some? raw)
do (println "\"Found storage.")
dispatch! $ :: :user/log-in (parse-cirru-edn raw)
if
<
.!getHours $ new js/Date
, 4
dispatch! $ :: :session/set-cursor (util/get-yesterday!)
dispatch! $ :: :session/set-cursor (util/get-today!)
do $ println "\"Found no storage."
:examples $ []
: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
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 visibility-heartbeat
"\"url-parse" :default url-parse
"\"bottom-tip" :default hud!
"\"./calcit.build-errors" :default client-errors
"\"../js-out/calcit.build-errors" :default server-errors
app.util :as util
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-container (states store)
case-default store
let
state $ :data states
session $ :session store
router $ :router store
router-data $ :data router
div
{} $ :class-name (str-spaced css/preset css/global css/fullscreen css/row)
comp-navigation (:logged-in? store) (:count store)
if (:logged-in? store)
case-default (:name router) (<> router)
:home $ comp-month (:today store) (:cursor session) (:diary store) (:data router)
:data $ comp-data-gather (:data router)
:diary $ comp-diary (>> states :diary) (:cursor session) (:diary store)
:profile $ comp-profile (:user store) (:data router)
comp-login states
comp-status-color $ :color store
when dev? $ comp-inspect |Store store
{} (:bottom 0) (:left 0) (:max-width |100%)
comp-messages
get-in store $ [] :session :messages
{}
fn (info d!) (d! :session/remove-message info)
when dev? $ comp-reel (:reel-length store) ({})
(:: :initial) (comp-offline :initial)
(:: :offline) (comp-offline :offline)
:examples $ []
|comp-offline $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-offline (state)
div
{} $ :class-name (str-spaced css/global css/fullscreen css/center)
span
{}
:style $ {} (:cursor :pointer)
:on-click $ fn (e d!) (d! :effect/connect nil)
<>
if (= state :offline) "|Socket broken! Click to retry." "\"Loading..."
{} (:font-family ui/font-fancy) (:font-weight 100) (:font-size 32)
:examples $ []
|comp-status-color $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-status-color (color)
div $ {} (:class-name css-status-color)
:style $ {} (:background-color color)
:examples $ []
|css-status-color $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-status-color $ {}
"\"$0" $ {} (:width 16) (:height 16) (:position :absolute) (:top 16) (:right 16) (:border-radius "\"8px") (:opacity 0.8) (:transition-duration "\"240ms")
"\"$0:hover" $ {} (:transform "\"scale(1.1)")
:examples $ []
|style-body $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
def style-body $ {} (:padding "|8px 16px")
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
hsl.core :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp <> >> div span button
respo.css :refer $ defstyle
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.comp.month :refer $ comp-month
app.comp.diary :refer $ comp-diary
app.comp.data-gather :refer $ comp-data-gather
|app.comp.data-gather $ %{} :FileEntry
:defs $ {}
|comp-data-gather $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-data-gather (diaries)
div
{}
:class-name $ str-spaced css/expand css/column
:style $ {} (:padding 16)
:color $ hsl 0 0 80
textarea $ {}
:class-name $ str-spaced css/expand css/textarea
:value $ format-cirru-edn
-> diaries (.to-list) (.sort-by first)
:style $ {} (:width "\"auto") (:height 400) (:font-family ui/font-code) (:white-space :pre)
div
{} $ :style
{} $ :padding "\"16px 0"
button $ {} (:class-name css/button-primary) (:inner-text "\"Copy")
:on-click $ fn (e d!)
copy! $ format-cirru-edn
-> diaries (.to-list) (.sort-by first)
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.data-gather $ :require
respo-ui.core :refer $ hsl
respo-ui.css :as css
respo-ui.core :as ui
respo.comp.space :refer $ =<
respo.core :refer $ defcomp <> list-> span div a textarea button
"\"copy-to-clipboard" :default copy!
|app.comp.diary $ %{} :FileEntry
:defs $ {}
|comp-diary $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-diary (states date-info diary)
let
date $ format-to-date date-info
original-state $ :data states
cursor $ :cursor states
state $ or original-state
{} $ :text
or (:text diary) "\""
div
{}
:class-name $ str-spaced css/row css/flex
:style $ {} (:padding "\"32px 80px") (:overflow :auto)
div
{} $ :class-name css/expand
div
{} $ :style
{} $ :flex-shrink 0
<> date $ str-spaced css/font-fancy style-date-preview
=< nil 8
comp-records states diary date
=< 32 nil
div
{}
:class-name $ str-spaced css/flex css/column
:style $ {} (:flex 2)
div
{} (:class-name css/row-parted)
:style $ {} (:height 40)
div
{} $ :class-name css/row-middle
<> "\"Short review" $ {} (:font-size 20) (:font-family ui/font-fancy)
:color $ hsl 0 0 80
div
{} $ :class-name css/row-middle
when
and
blank? $ :food diary
blank? $ :sleep diary
blank? $ :pains diary
button $ {} (:class-name css/button) (:inner-text "|Like last day")
:style $ {} (:margin-left 16)
:on-click $ fn (e d!)
d! :diary/copy-yesterday $ {} (:date-info date-info)
when
not= (:text diary) (:text state)
button $ {} (:class-name css/button-primary) (:inner-text "\"Save")
:style $ {} (:margin-left 16)
:on-click $ fn (e d!)
when
not $ blank? (:text state)
d! :diary/add-one $ merge diary
{}
:text $ :text state
:date date
d! cursor nil
let
lost-copy "\"diary-lost-copy"
js/localStorage.setItem lost-copy $ :text state
js/console.info "\"Latest diary saved to" $ to-lispy-string lost-copy
when
not= (:text diary) (:text state)
a
{} (:class-name css/link)
:style $ {} (:margin-left 16)
:on-click $ fn (e d!) (d! cursor nil)
<> "\"Reset"
textarea $ {}
:value $ :text state
:placeholder "\"Some diary"
:class-name $ str-spaced css/flex css/textarea
:style $ {} (:min-height 320) (:flex-shrink 0)
:on-input $ fn (e d!)
d! cursor $ assoc state :text (:value e)
:examples $ []
|comp-guide $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-guide (text)
div
{} $ :class-name css-guide
<> text
:examples $ []
|comp-records $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-records (states diary date)
div
{} $ :style
{} $ :flex-shrink 0
let
plugin $ use-prompt (>> states :food)
{} (:text "\"What have you eaten:")
:initial $ or (:food diary) "\""
div
{} $ :class-name css-record-layout
comp-guide "\"What did you eat?"
render-content (:food diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :food) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :sleep)
{} (:text "\"How did you sleep:")
:initial $ or (:sleep diary) "\""
div
{} $ :class-name css-record-layout
comp-guide "\"How did you sleep?"
render-content (:sleep diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :sleep) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :mood)
{} (:text "\"What's the feelings today:")
:initial $ or (:mood diary) "\""
div
{} (:class-name css-record-layout)
:style $ merge
{} $ :align-items :start
comp-guide "\"How you feel?"
render-content (:mood diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :mood) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :place)
{} (:text "\"Where have you been today:")
:initial $ or (:place diary) "\""
div
{} (:class-name css-record-layout)
:style $ {} (:align-items :center)
comp-guide "\"Where you went?"
render-content (:place diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :place) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :highlight)
{} (:text "\"Highlights of this day:")
:initial $ or (:highlight diary) "\""
div
{} (:class-name css-record-layout)
:style $ {} (:align-items :center)
comp-guide "\"What's the highlights?"
render-content (:highlight diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :highlight) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :met)
{} (:text "\"Met with people:")
:initial $ or (:met diary) "\""
div
{} (:class-name css-record-layout)
:style $ {} (:align-items :center)
comp-guide "\"People met?"
render-content (:met diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :met) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :exercise)
{} (:text "\"Performed exercises:")
:initial $ or (:exercise diary) "\""
div
{} (:class-name css-record-layout)
:style $ {} (:align-items :center)
comp-guide "\"Exercises?"
render-content (:exercise diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :exercise) (:date date) (:data data)
.render plugin
let
plugin $ use-prompt (>> states :pains)
{} (:text "\"Pains:")
:initial $ or (:pains diary) "\""
div
{} (:class-name css-record-layout)
:style $ {} (:align-items :center)
comp-guide "\"Pains?"
render-content (:pains diary)
fn (e d!)
.show plugin d! $ fn (data)
d! :diary/change $ {} (:field :pains) (:date date) (:data data)
.render plugin
:examples $ []
|css-guide $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-guide $ {}
"\"$0" $ {}
:color $ hsl 0 0 60
:margin-right 32
:min-width 160
:text-align :left
:examples $ []
|css-record-layout $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-record-layout $ {}
"\"$0" $ {} (:margin-bottom 20)
:examples $ []
|render-content $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn render-content (x on-click)
span
{}
:style $ {} (:margin-left 24) (:cursor :pointer)
:on-click on-click
if (blank? x) (comp-empty) (<> x)
:examples $ []
|style-date-preview $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-date-preview $ {}
"\"&" $ {} (:font-size 32) (:font-weight 100)
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.diary $ :require
respo.core :refer $ defcomp <> div input button >> span textarea a
respo.css :refer $ defstyle
respo-ui.core :refer $ hsl
respo-ui.css :as css
respo.comp.space :refer $ =<
respo.comp.inspect :refer $ comp-inspect
respo-ui.core :as ui
app.schema :as schema
app.style :as style
app.config :as config
app.util :refer $ format-to-date
app.comp.empty :refer $ comp-empty
clojure.string :as string
respo-alerts.core :refer $ use-prompt
|app.comp.empty $ %{} :FileEntry
:defs $ {}
|comp-empty $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-empty () $ div
{} $ :style
{} (:display :inline-block)
:color $ hsl 0 0 80
<> "\"Empty"
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.empty $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.comp.space :refer $ [] =<
[] respo.core :refer $ [] defcomp <> list-> span div a
|app.comp.login $ %{} :FileEntry
:defs $ {}
|comp-login $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-login (states)
let
cursor $ :cursor states
state $ or (:data states) initial-state
div
{} $ :class-name (str-spaced css/flex css/center)
div
{} (:class-name css/column)
:style $ {} (:align-items :center)
div ({}) (<> "\"Very tiny app for adding diaries.")
=< nil 16
div ({})
div ({})
input $ {} (:placeholder |Username) (:class-name css/input)
:value $ :username state
:on-input $ fn (e d!)
d! cursor $ assoc state :username (:value e)
=< nil 8
div ({})
input $ {} (:placeholder |Password) (:class-name css/input)
:value $ :password state
:on-input $ fn (e d!)
d! cursor $ assoc state :password (:value e)
=< nil 8
div
{} $ :style
{} $ :text-align :right
span $ {} (:inner-text "|Sign up") (:class-name css/link)
:on-click $ on-submit (:username state) (:password state) true
=< 8 nil
span $ {} (:inner-text "|Log in") (:class-name css/link)
:on-click $ on-submit (:username state) (:password state) false
:examples $ []
|initial-state $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
def initial-state $ {} (:username |) (:password |)
:examples $ []
|on-submit $ %{} :CodeEntry (:doc |) (:schema nil)
: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 $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.login $ :require
respo.core :refer $ defcomp <> div input button span
respo.css :refer $ defstyle
respo.comp.space :refer $ =<
respo.comp.inspect :refer $ comp-inspect
respo-ui.core :as ui
respo-ui.css :as css
app.schema :as schema
app.style :as style
app.config :as config
|app.comp.month $ %{} :FileEntry
:defs $ {}
|comp-cell $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-cell (col row first-day today-info cursor overview)
let
offset $ + (* 7 col) row
this-day $ .!plus first-day
js-object $ :days offset
today $ .!fromObject DateTime (to-js-data today-info)
same-month? $ = (.-month this-day) (:month cursor)
today? $ same-day? this-day today
selected? $ and
= (.-month this-day) (:month cursor)
= (.-day this-day) (:day cursor)
info $ get overview (.!toFormat this-day "\"yyyy-MM-dd")
preview-mood $ :mood info
preview-highlight $ :highlight info
div
{}
:class-name $ str-spaced css-cell-size css/center css-day-cell
:style $ merge
{} $ :color
if same-month? (hsl 0 0 30) (hsl 0 0 80)
if selected? $ {}
:background-color $ hsl 170 80 94
:transform "\"scale(1.1)"
if today? $ {}
:background-color $ hsl 30 80 97
if (is-holiday? this-day)
{} $ :border-bottom
str "\"4px solid " $ hsl 200 80 80
:on-click $ fn (e d!)
d! :session/set-cursor $ {}
:year $ .-year this-day
:month $ .-month this-day
:day $ .-day this-day
div
{} (:class-name css/column)
:style $ {} (:width "\"100%")
<> (.!toFormat this-day "\"d")
merge
{} (:font-size 16)
:color $ hsl 0 0 60
if (some? info)
{} $ :font-weight 500
if
and (blank? preview-mood) (blank? preview-highlight)
{} $ :font-size 20
<> preview-mood style-preview
<> preview-highlight style-preview
:examples $ []
|comp-diary-preview $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-diary-preview (cursor-date diary)
div
{}
:class-name $ str-spaced css/flex css/column
:style $ {} (:padding "\"16px 32px") (:height "\"100%")
div
{} (:class-name css/row)
:style $ {} (:align-items :center) (:flex-shrink 0)
<> (.!toFormat cursor-date "\"yyyy-MM-dd") (str-spaced css/font-fancy style-date-main)
=< 8 nil
if
some? $ :time diary
<>
.!toFormat
.!fromMillis DateTime $ :time diary
, "\"(yyyy-MM-dd hh:mm)"
str-spaced css/font-fancy style-date-hint
comp-divider "\"32px 0"
if (some? diary)
div
{}
:class-name $ str-spaced css/column css/flex
:style $ {} (:overflow :auto)
div ({})
<> $ :food diary
div ({})
<> $ :sleep diary
div ({})
<> $ :mood diary
div ({})
<> $ :place diary
div ({})
<> $ :highlight diary
div ({})
<> $ :met diary
div ({})
<> $ :exercise diary
div ({})
<> $ :pains diary
comp-divider "\"32px 0"
div ({})
<> $ :text diary
comp-divider "\"32px 0"
=< nil 16
if (some? diary)
div ({})
button
{} (:class-name css/button)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :diary)
<> "\"Edit diary"
div ({})
button
{} (:class-name css/button-primary)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :diary)
<> "\"Add diary"
:examples $ []
|comp-divider $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-divider (padding)
div $ {}
:style $ {}
:background-color $ hsl 0 0 90
:height 1
:margin padding
:examples $ []
|comp-month $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-month (today cursor diary overview)
let
cursor-date $ .!fromObject DateTime (to-js-data cursor)
month-1st $ .!fromObject DateTime
to-js-data $ assoc cursor :day 1
days-length $ get-days-by (:year cursor) (:month cursor)
useful-days $ + days-length (.-weekday month-1st) -1
columns $ if
= 0 $ .rem useful-days 7
/ useful-days 7
.!ceil js/Math $ / useful-days 7
day-cell-1st $ .!plus month-1st
js-object $ :days
negate $ dec (.-weekday month-1st)
div
{} $ :class-name (str-spaced css/column css/expand)
div
{} $ :class-name (str-spaced css/row css/expand)
div
{} $ :style
{} (:padding "\"16px 8px") (:display :inline-block)
div
{} (:class-name css/row-parted)
:style $ {} (:padding "\"0 16px")
a
{} (:class-name css-month-switch)
:on-click $ fn (e d!) (on-change-month! cursor -1 d!)
comp-i :chevron-left 16 $ hsl 200 80 70
<> (.!toFormat cursor-date "\"yyyy-MM") (str-spaced css/font-fancy style-month-header)
a
{} (:class-name css-month-switch)
:on-click $ fn (e d!) (on-change-month! cursor 1 d!)
comp-i :chevron-right 16 $ hsl 200 80 70
comp-weekdays
list->
{} $ :class-name css/column
-> (range columns)
map $ fn (x)
[] x $ list->
{} $ :class-name css/row
-> (range 7)
map $ fn (y)
[] y $ comp-cell x y day-cell-1st today cursor overview
div $ {}
:style $ {} (:width 1)
:background-color $ hsl 0 0 90
comp-diary-preview cursor-date diary
comp-month-footer
:examples $ []
|comp-month-footer $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn comp-month-footer () $ div
{} (:class-name css/row-middle)
:style $ {}
:border-top $ str "\"1px solid " (hsl 0 0 90)
list->
{} (:class-name css/row)
:style $ {} (:padding "\"0px 16px")
-> (range 1 13)
map $ fn (n)
[] n $ span
{} (:inner-text n)
:class-name $ str-spaced css/center css-month-entry
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:month n)
div
{} $ :class-name css/row-middle
span $ {} (:inner-text "\"2026") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2026)
span $ {} (:inner-text "\"2025") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2025)
span $ {} (:inner-text "\"2024") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2024)
span $ {} (:inner-text "\"2023") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2023)
span $ {} (:inner-text "\"2022") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2022)
span $ {} (:inner-text "\"2021") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2021)
span $ {} (:inner-text "\"2020") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2020)
span $ {} (:inner-text "\"2019") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2019)
span $ {} (:inner-text "\"2018") (:class-name css-year-entry)
:on-click $ fn (e d!)
d! :session/merge-cursor $ {} (:year 2018)
:examples $ []
|comp-weekdays $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-weekdays () $ list->
{} $ :class-name (str-spaced css/row style-week-header)
-> ([] "\"Mon" "\"Tue" "\"Wed" "\"Thu" "\"Fri" "\"Sat" "\"Sun")
map $ fn (x)
[] x $ div
{} $ :class-name (str-spaced css-cell-size css-week-note)
<> x
:examples $ []
|css-cell-size $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-cell-size $ {}
"\"$0" $ {} (:width 92) (:height 84) (:margin 6) (:vertical-align :middle) (:text-align :center)
:examples $ []
|css-day-cell $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-day-cell $ {}
"\"$0" $ {} (:cursor :pointer) (:font-family ui/font-fancy) (:font-size 14) (:font-weight 300) (:position :relative) (:overflow :hidden) (:border-radius "\"16px") (:transition-duration "\"200ms")
:border $ str "\"1px solid " (hsl 0 0 94)
:border-top-color :transparent
:border-left-color :transparent
:border-right-color :transparent
"\"$0:hover" $ {}
:background-color $ hsl 0 0 98
:transform "\"scale(1.06)"
:examples $ []
|css-month-entry $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-month-entry $ {}
"\"$0" $ {} (:font-family ui/font-fancy) (:line-height "\"40px") (:width 40) (:font-size 16) (:font-weight 100) (:cursor :pointer)
:examples $ []
|css-month-switch $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-month-switch $ {}
"\"$0" $ {} (:width 40) (:text-align :center) (:cursor :pointer)
:examples $ []
|css-week-note $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-week-note $ {}
"\"$0" $ {}
:color $ hsl 0 0 80
:font-family ui/font-fancy
:height 32
:line-height "\"32px"
:examples $ []
|css-year-entry $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-year-entry $ {}
"\"$0" $ {} (:cursor :pointer) (:width 60) (:text-align :center)
:examples $ []
|inline $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defmacro inline (path)
read-file $ str "\"holidays/" path
:examples $ []
|is-holiday? $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn is-holiday? (day)
let
d $ .!toFormat day "\"yyyy-MM-dd"
cond
includes? (:holiday special-days) d
, true
(includes? (:workingday special-days) d)
, false
true $ includes? (#{} 6 7) (aget day "\"weekday")
:examples $ []
|on-change-month! $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defn on-change-month! (cursor offset d!)
let
year $ :year cursor
month $ :month cursor
day $ :day cursor
next-cursor $ cond
and (= month 1) (= offset -1)
{}
:year $ - year 1
:month 12
:day day
(and (= month 12) (= offset 1))
{}
:year $ + year 1
:month 1
:day day
true $ let
next-month $ + month offset
count-days $ get-days-by year next-month
{} (:year year) (:month next-month)
:day $ js/Math.min count-days day
d! :session/set-cursor next-cursor
:examples $ []
|special-days $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
def special-days $ let
data $ concat
parse-cirru-edn $ inline "\"2018.cirru"
parse-cirru-edn $ inline "\"2019.cirru"
parse-cirru-edn $ inline "\"2020.cirru"
parse-cirru-edn $ inline "\"2021.cirru"
parse-cirru-edn $ inline "\"2026.cirru"
{}
:workingday $ union &
-> data
filter $ fn (x)
= :workingday $ :type x
map $ fn (x) (:days x)
:holiday $ union &
-> data
filter $ fn (x)
= :holiday $ :type x
map $ fn (x) (:days x)
:examples $ []
|style-date-hint $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-date-hint $ {}
"\"&" $ {} (:font-size 12) (:font-weight 100)
:color $ hsl 0 0 72
:examples $ []
|style-date-main $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-date-main $ {}
"\"&" $ {} (:font-size 16) (:font-weight 300)
:examples $ []
|style-month-header $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-month-header $ {}
"\"&" $ {} (:font-size 16) (:font-weight 300)
:examples $ []
|style-preview $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-preview $ {}
"\"&" $ {} (:font-size 12) (:white-space :nowrap) (:text-overflow :ellipsis) (:display :inline-block) (:overflow :hidden) (:width "\"100%")
:examples $ []
|style-week-header $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle style-week-header $ {}
"\"&" $ {}
:border-bottom $ str "\"1px solid " (hsl 0 0 94)
:border-top $ str "\"1px solid " (hsl 0 0 94)
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.month $ :require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.comp.space :refer $ =<
respo.core :refer $ defcomp <> list-> span div a button
respo.css :refer $ defstyle
"\"luxon" :refer $ DateTime
app.util :refer $ get-days-by same-day?
app.comp.empty :refer $ comp-empty
feather.core :refer $ comp-i
|app.comp.navigation $ %{} :FileEntry
:defs $ {}
|comp-navigation $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-navigation (logged-in? count-members)
div
{} $ :class-name (str-spaced css/column-parted css-nav)
div
{} $ :class-name css/column
span $ {} (:inner-text "\"Diary")
:style $ {} (:cursor :pointer)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :home)
div ({})
span $ {} (:inner-text "\"Data")
:style $ {} (:cursor :pointer) (:margin-bottom 16) (:display :inline-block)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :data)
div
{}
:style $ {} (:cursor |pointer)
:on-click $ fn (e d!)
d! :router/change $ {} (:name :profile)
<> $ if logged-in? |Me |Guest
=< 8 nil
<> count-members
:examples $ []
|css-nav $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defstyle css-nav $ {}
"\"$0" $ {} (:width 64) (:padding "|16px 0") (:font-size 16)
:border-right $ str "|1px solid " (hsl 0 0 0 0.05)
:font-family ui/font-fancy
:align-items :center
:background-color $ hsl 0 0 97
:examples $ []
:ns $ %{} :NsEntry (:doc |)
:code $ quote
ns app.comp.navigation $ :require
respo-ui.core :refer $ hsl
respo.css :refer $ defstyle
respo-ui.css :as css
respo-ui.core :as ui
respo.comp.space :refer $ =<
respo.core :refer $ defcomp <> span div
|app.comp.profile $ %{} :FileEntry
:defs $ {}
|comp-profile $ %{} :CodeEntry (:doc |) (:schema nil)
:code $ quote
defcomp comp-profile (user members)
div
{} (:class-name css/flex)
:style $ {} (:padding 16)
div
{} (:class-name css/font-fancy)
:style $ {} (:font-size 32) (:font-weight 100)
<> $ str "|Hello! " (:name user)
=< nil 16
div
{} $ :class-name css/row
<> "\"Members:"
=< 8 nil
list->
{} $ :class-name css/row
-> members (.to-list)
.map-pair $ fn (k username)
[] k $ div
{} $ :class-name css-member-label
<> username
=< nil 48