-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
1444 lines (1443 loc) · 65.1 KB
/
compact.cirru
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
{} (:package |app)
:configs $ {} (:init-fn |app.client/main!) (:reload-fn |app.client/reload!) (:version nil)
: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/ |respo-markdown.calcit/
:entries $ {}
:server $ {} (:init-fn |app.server/main!) (:port 6001) (:reload-fn |app.server/reload!)
:modules $ [] |lilac/ |recollect/ |memof/ |cumulo-util.calcit/ |cumulo-reel.calcit/ |calcit.std/ |calcit-wss/
:files $ {}
|app.client $ %{} :FileEntry
:defs $ {}
|*states $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *states $ {}
:states $ {}
:cursor $ []
|*store $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *store $ :: :initial
|connect! $ %{} :CodeEntry (:doc |)
: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://timegrass.topix.im/ws"
{}
:on-open $ fn (event) (simulate-login!)
:on-close $ fn (event)
reset! *store $ :: :offline
js/console.error "\"Lost connection!"
:on-data on-server-data
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when
and config/dev? $ not= (nth op 0) :states
js/console.log "\"Dispatch" op
tag-match op
:states cursor s
reset! *states $ update-states @*states cursor s
(:effect/connect) (connect!)
_ $ ws-send! op
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! () (.!extend dayjs week-of-year)
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!"
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector "\".app"
|on-server-data $ %{} :CodeEntry (:doc |)
: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
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if
or $ some? client-errors
hud! "\"error" $ str client-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."
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () $ render! mount-target
comp-container (:states @*states) @*store
, dispatch!
|simulate-login! $ %{} :CodeEntry (:doc |)
: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)
do $ println "\"Found no storage."
:ns $ %{} :CodeEntry (: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
"\"dayjs" :default dayjs
"\"dayjs/plugin/weekOfYear" :default week-of-year
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-container (states store)
case-default store
let
state $ :data states
session $ :session store
router $ :router store
router-data $ :data router
div
{} $ :class-name css-container
comp-navigation (:logged-in? store) (:count store) (:name router)
if (:logged-in? store)
case-default (:name router)
<> $ str "\"404 page:" router
:home $ comp-overview (>> states :overview) (:today store)
get-in router $ [] :data :tasks
:history $ comp-history (>> states :history)
get-in router $ [] :data :week
get-in router $ [] :data :tasks
:notes $ comp-notes-page (>> states :notes) (:data router)
get-in session $ [] :router :data
:profile $ comp-profile (:user store) (:data router)
comp-login $ >> states :login
comp-status-color $ :color store
when dev? $ comp-inspect |Store store
{} (:bottom 0) (:left 0) (:z-index 9999)
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)
|comp-offline $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-offline (state)
div
{} $ :class-name css-offline
div $ {}
:style $ {} (:height 0)
div $ {}
:style $ {}
:background-image $ str "\"url(" (:icon config/site) "\")"
:width 128
:height 128
:background-size :contain
span
{}
:style $ {} (:cursor :pointer)
:on-click $ fn (e d!) (d! :effect/connect nil)
<>
if (= :initial state) "\"Loading..." "|Socket broken! Click to retry."
{} (:font-family ui/font-fancy) (:font-weight 100) (:font-size 24)
|comp-status-color $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-status-color (color)
div $ {} (:class-name css-status-color)
:style $ {} (:background-color color)
|css-container $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-container $ {}
"\"$0" $ merge ui/global ui/fullscreen ui/column
|css-offline $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-offline $ {}
"\"$0" $ merge ui/global ui/fullscreen ui/column-dispersive
{} $ :background-color (:theme config/site)
|css-status-color $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-status-color $ {}
"\"$0" $ {} (:width 16) (:height 16) (:position :absolute) (:bottom 16) (:right 8) (:border-radius "\"8px") (:opacity 0.8) (:transition-duration "\"200ms") (:opacity 0.5)
"\"$0:hover" $ {} (:opacity 0.7)
|style-body $ %{} :CodeEntry (:doc |)
:code $ quote
def style-body $ {} (:padding "|8px 16px")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
hsl.core :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.css :refer $ defstyle
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.comp.overview :refer $ comp-overview
app.config :as config
app.comp.history :refer $ comp-history
app.comp.notes-page :refer $ comp-notes-page
|app.comp.history $ %{} :FileEntry
:defs $ {}
|comp-done-task $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-done-task (states task)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :show-menu? false
div
{} (:class-name css-done-task)
:style $ merge
{} $ :padding "\"4px 8px"
when (:show-menu? state)
{} $ :background-color (hsl 0 0 94)
:on-click $ fn (e d!)
d! cursor $ assoc state :show-menu? true
<>
-> (:finished-time task) dayjs $ .!format "\"HH:mm"
{} (:min-width 32)
:color $ hsl 0 0 80
:font-size 12
:display :inline-block
=< 4 nil
span
{} $ :style
merge ui/flex $ {} (:line-height "\"24px")
<> $ :text task
comp-modal-menu
{} (:title "\"Operations")
:style $ {} (:width 320)
:items $ [] (:: :item :put-back "\"Put back")
:show-menu? state
fn (d!)
d! cursor $ assoc state :show-menu? false
fn (item d!)
d! cursor $ assoc state :show-menu? false
when
= :put-back $ nth item 1
d! :task/put-back $ :id task
|comp-history $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-history (states data finished-tasks)
let
year $ :year data
week $ :week data
div
{} (:class-name css/flex)
:style $ {} (:padding "\"16px 16px") (:overflow :auto)
div
{} $ :style
{} (:max-width 800) (:margin :auto)
div
{} (:class-name css/row-parted)
:style $ {} (:margin "\"8px 0")
<> (str "\"Histories of " week "\"th week in " year)
{} (:font-family ui/font-fancy) (:font-size 16)
:color $ hsl 0 0 50
div
{} $ :class-name css/row
comp-icon :arrow-left
{} (:font-size 16)
:color $ hsl 200 80 80
:cursor :pointer
fn (e d!)
d! :router/change $ {} (:name :history)
:data $ let
change-year? $ <= week 1
y $ if change-year? (dec year) year
w $ if change-year? 53 (dec week)
d $ -> (dayjs) (.!year y) (.!week w)
{} (:year y) (:week w)
:start $ .!format (.!startOf d "\"week")
:end $ .!format (.!endOf d "\"week")
=< 8 nil
comp-icon :arrow-right
{} (:font-size 16)
:color $ hsl 200 80 80
:cursor :pointer
fn (e d!)
d! :router/change $ {} (:name :history)
:data $ let
change-year? $ >= week 53
y $ if change-year? (inc year) year
w $ if change-year? 1 (inc week)
d $ -> (dayjs) (.!year y) (.!week w)
{} (:year y) (:week w)
:start $ .!format (.!startOf d "\"week")
:end $ .!format (.!endOf d "\"week")
if (empty? finished-tasks)
div
{} (:class-name css/center)
:style $ {} (:height 80)
<> "\"No tasks." $ {} (:font-family ui/font-fancy)
:color $ hsl 0 0 80
let
grouped-tasks $ -> finished-tasks (.to-list) (.map last)
group-by $ fn (task)
.!format
dayjs $ :finished-time task
, "\"YYYY-MM-DD"
list-> ({})
-> grouped-tasks (.to-list)
.sort $ fn (x y)
&compare (first y) (first x)
.map-pair $ fn (date-string task-list)
[] date-string $ div
{} (:class-name css/column)
:style $ {} (:margin-top 16)
let
the-day $ dayjs date-string
div
{} $ :class-name css/row-parted
span
{} $ :class-name css/font-fancy
<> $ .!format the-day "\"ddd"
=< 12 nil
<> $ .!format the-day "\"MM-DD"
=< nil 4
list-> ({})
-> task-list
.sort-by $ fn (task)
negate $ :finished-time task
.map $ fn (task)
[] (:id task)
comp-done-task
>> states $ :id task
, task
|css-done-task $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-done-task $ {}
"\"$0" $ {} (:transition-duration "\"200ms")
"\"$0:hover" $ {}
:background-color $ hsl 0 0 80 0.2
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.history $ :require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.css :refer $ defstyle
respo.comp.space :refer $ =<
respo.core :refer $ defcomp <> >> list-> span div
app.config :as config
respo-alerts.core :refer $ comp-modal-menu
"\"dayjs" :default dayjs
feather.core :refer $ comp-icon
|app.comp.login $ %{} :FileEntry
:defs $ {}
|comp-login $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-login (states)
let
cursor $ :cursor states
state $ or (:data states) initial-state
div
{} $ :style (merge ui/flex ui/center)
div ({})
div
{} $ :style ({})
div ({})
input $ {} (:placeholder |Username)
:value $ :username state
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :username (:value e)
=< nil 8
div ({})
input $ {} (:placeholder |Password)
:value $ :password state
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :password (:value e)
=< nil 8
div
{} $ :style
{} $ :text-align :right
span $ {} (:inner-text "|Sign up")
:style $ merge style/link
:on-click $ on-submit (:username state) (:password state) true
=< 8 nil
span $ {} (:inner-text "|Log in")
:style $ merge style/link
:on-click $ on-submit (:username state) (:password state) false
|initial-state $ %{} :CodeEntry (:doc |)
:code $ quote
def initial-state $ {} (:username |) (:password |)
|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
:ns $ %{} :CodeEntry (: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.style :as style
[] app.config :as config
|app.comp.navigation $ %{} :FileEntry
:defs $ {}
|comp-navigation $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-navigation (logged-in? count-members page)
div
{} $ :class-name css-navbar
div
{} (:class-name css/row-parted)
:style $ {} (:max-width 840) (:width "\"100%") (:margin :auto)
div
{} $ :class-name css/row-center
render-entry "\"Timegrass"
fn () $ {} (:name :home)
= page :home
=< 16 nil
render-entry "\"Finished"
fn () $ {} (:name :history)
:data $ let
now $ dayjs
month $ .!month now
week-date now
{}
:year $ .!year now
:week $ .!week week-date
:start $ .!format (.!startOf week-date "\"week")
:end $ .!format (.!endOf week-date "\"week")
= page :history
=< 16 nil
render-entry "\"Notes"
fn () $ {} (:name :notes)
:data $ let
now $ dayjs
{}
:year $ .!year now
:month $ .!month now
= page :notes
div
{}
:style $ {} (:cursor |pointer) (:user-select :none)
:tab-index 0
:on-click $ fn (e d!)
d! :router/change $ {} (:name :profile)
<> $ if logged-in? |Me |Guest
=< 8 nil
<> count-members
|css-entry $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-entry $ {}
"\"$0" $ {} (:opacity 0.6) (:user-select :none) (:transition-duration "\"200ms")
"\"$0:hover" $ {} (:opacity 0.8)
|css-navbar $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-navbar $ {}
"\"$0" $ merge ui/row-center
{} (:height 48) (:padding "\"0 16px") (:font-size 16)
:border-bottom $ str "\"1px solid " (hsl 0 0 0 0.1)
:font-family ui/font-fancy
:background-color $ :theme config/site
:color :white
|render-entry $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-entry (title get-route highlighted?)
div
{} (:class-name css-entry)
:style $ merge
{} $ :cursor :pointer
if highlighted? $ {} (:opacity 1)
:on-click $ fn (e d!)
d! :router/change $ get-route
:tab-index 0
<> title nil
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.navigation $ :require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo.css :refer $ defstyle
respo-ui.css :as css
respo.comp.space :refer $ =<
respo.core :refer $ defcomp <> >> span div
app.config :as config
respo-alerts.core :refer $ comp-prompt
"\"dayjs" :default dayjs
|app.comp.notes-page $ %{} :FileEntry
:defs $ {}
|comp-note $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-note (states note)
let
edit-plugin $ use-prompt (>> states :edit)
{} (:text "\"Update note:") (:multiline? true)
:initial $ :text note
remove-plugin $ use-confirm (>> states :remove)
{} $ :text "\"Sure to delete note?"
div
{}
:class-name $ str-spaced css/column css-note
:style $ {}
:border-top $ str "\"1px solid " (hsl 0 0 94)
:padding "\"4px 8px"
div
{} $ :class-name css/row-parted
<>
-> (:time note) dayjs $ .!format "\"HH:mm"
{} (:font-family ui/font-fancy)
:color $ hsl 0 0 70
:font-size 12
=< 8 nil
div
{} $ :class-name css/row-middle
comp-icon :edit
&{} :font-size 16 :curspr :pointer :color $ hsl 200 80 80
fn (e d!)
.show edit-plugin d! $ fn (result)
d! :note/edit $ {}
:id $ :id note
:text result
=< 8 nil
comp-icon :delete
&{} :font-size 16 :cursor :pointer :color $ hsl 10 80 60
fn (e d!)
.show remove-plugin d! $ fn ()
d! :note/remove $ :id note
<> $ :text note
.render edit-plugin
.render remove-plugin
|comp-notes-page $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-notes-page (states notes info)
let
year $ :year info
month $ :month info
add-plugin $ use-prompt (>> states :add)
{} (:text "\"Add note about today's work:") (:multiline? true)
div
{} (:class-name css/expand)
:style $ {} (:padding 16)
div
{} $ :style
{} (:max-width 800) (:margin :auto)
div
{} (:class-name css/row-parted)
:style $ {} (:margin "\"8px 0")
span
{} $ :class-name css/row-middle
<> "\"Notes" $ {}
:color $ hsl 0 0 50
:font-family ui/font-fancy
:font-size 16
=< 16 nil
comp-icon :plus
&{} :font-size 16 :color (hsl 200 80 80) :cursor :pointer
fn (e d!)
.show add-plugin d! $ fn (result) (d! :note/add result)
div
{} $ :class-name css/row-middle
comp-icon :arrow-left
{} (:font-size 16)
:color $ hsl 200 80 80
:cursor :pointer
fn (e d!)
d! :router/change $ {} (:name :notes)
:data $ if (<= month 0)
{}
:year $ dec year
:month 11
{} (:year year)
:month $ dec month
=< 8 nil
comp-icon :arrow-right
{} (:font-size 16)
:color $ hsl 200 80 80
:cursor :pointer
fn (e d!)
d! :router/change $ {} (:name :notes)
:data $ if (>= month 11)
{}
:year $ inc year
:month 0
{} (:year year)
:month $ inc month
=< 8 nil
<>
str (inc month) "\"th month of " year "\"."
{} (:font-family ui/font-fancy)
:color $ hsl 0 0 50
if (empty? notes)
div
{} (:class-name css/center)
:style $ {} (:min-height 120)
<> "\"No notes" $ {} (:font-family ui/font-fancy)
:color $ hsl 0 0 80
let
grouped-notes $ -> notes (.to-list)
.group-by $ fn (pair)
->
:time $ last pair
, dayjs $ .!format "\"MM-DD"
.to-list
.sort $ fn (x y)
&compare (first y) (first x)
list-> ({})
-> grouped-notes (.to-list)
.map-pair $ fn (date notes-in-day)
[] date $ div
{} $ :style
{} $ :margin-top 16
div
{} (:class-name css/font-fancy)
:style $ {} (:font-size 14) (:font-weight 500)
<> $ -> (str year "\"-" date) dayjs (.!format "\"ddd")
=< 12 nil
<> $ str date
list->
{} $ :class-name css/column
-> notes-in-day
.sort-by $ fn (pair)
negate $ :time (last pair)
.map-pair $ fn (k note)
[] k $ comp-note (>> states k) note
=< nil 160
.render add-plugin
|css-note $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-note $ {}
"\"$0" $ {} (:transition-duration "\"200ms")
"\"$0:hover" $ {}
:background-color $ hsl 0 0 80 0.2
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.notes-page $ :require
respo-ui.core :refer $ hsl
respo.css :refer $ defstyle
respo-ui.css :as css
app.schema :as schema
respo-ui.core :as ui
respo.core :refer $ defcomp list-> >> <> span div button a
respo.comp.space :refer $ =<
app.config :as config
respo-alerts.core :refer $ use-prompt use-confirm
feather.core :refer $ comp-i comp-icon
"\"dayjs" :default dayjs
|app.comp.overview $ %{} :FileEntry
:defs $ {}
|comp-no-tasks $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-no-tasks () $ div
{}
:class-name $ str-spaced css/center css/font-fancy
:style $ {}
:color $ hsl 0 0 80
<> "\"No tasks"
|comp-overview $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-overview (states today tasks)
let
working-tasks $ -> tasks (.to-map)
filter $ fn (pair)
not $ :pending? (last pair)
pending-tasks $ -> tasks (.to-map)
filter $ fn (pair)
:pending? $ last pair
create-plugin $ use-prompt (>> states :create)
{} $ :text "\"Create new task:"
cursor $ :cursor states
state $ or (:data states)
{} $ :show-later? false
div
{} (:class-name css/expand)
:style $ {} (:padding 16)
div
{} $ :style
{} (:max-width 800) (:margin :auto)
div
{} $ :class-name css/row-parted
comp-title "\"Doing" $ comp-icon :plus
&{} :font-size 14 :color (hsl 200 80 80) :cursor :pointer
fn (e d!)
.show create-plugin d! $ fn (result) (d! :task/create-working result)
comp-global-keydown ({})
fn (e d!)
if
and (:meta? e)
= "\"i" $ :key e
.show create-plugin d! $ fn (result) (d! :task/create-working result)
div
{}
:class-name $ str-spaced css/row-middle css/font-fancy
:style $ {}
:color $ hsl 0 0 60
<> $ .!format (dayjs today) "\"ddd"
=< 8 nil
<> $ str
.!week $ dayjs today
, "\"th week"
=< 16 nil
<> today
if (empty? working-tasks) (comp-no-tasks)
list-> ({})
-> working-tasks (.to-list)
.sort-by $ fn (pair)
let
task $ last pair
negate $ or (:touched-time task) (:created-time task)
.map-pair $ fn (k task)
[] k $ comp-task
>> states $ :id task
, task :working
when
not $ empty? pending-tasks
div ({})
comp-title "\"Later" nil $ fn (e d!)
d! cursor $ update state :show-later? not
if (:show-later? state)
list-> ({})
-> pending-tasks (.to-list)
.sort-by $ fn (pair)
let
task $ last pair
negate $ or (:touched-time task) (:created-time task)
.map-pair $ fn (k task)
[] k $ comp-task
>> states $ :id task
, task :pending
div
{}
:style $ {} (:font-size 16)
:on-click $ fn (e d!)
d! cursor $ update state :show-later? not
<>
str (count pending-tasks) "\" future tasks. Click to show."
{} (:font-family ui/font-fancy) (:font-weight 300) (:cursor :pointer)
.render create-plugin
|comp-task $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-task (states task mode)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :menu? false
update-plugin $ use-prompt (>> states :drafter)
{} (:text "\"Task content:")
:initial $ :text task
:placeholder "\"task..."
:button-text "\"Edit"
delete-plugin $ use-confirm (>> states :delete)
{} $ :text "\"Sure to remove task:"
div
{} (:class-name css-task-base)
:style $ merge
when
or $ :menu? state
{} $ :background-color (hsl 0 0 94)
:on-click $ fn (e d!)
d! cursor $ assoc state :menu? true
:on-dragend $ fn (e d!)
d! :task/touch-working $ :id task
:draggable true
div
{} $ :style ui/flex
<> (:text task) ({})
comp-modal-menu
{} (:title "\"Operations")
:style $ {} (:width 320)
:items $ [] (:: :item :done "\"Done")
:: :item :pend $ if (= mode :pending) "\"Do it now" "\"Do it later"
:: :item :touch "\"Up"
:: :item :copy "\"Copy"
:: :item :edit "\"Edit"
:: :item :remove "\"Remove"
:menu? state
fn (d!)
d! cursor $ assoc state :menu? false
fn (item d!)
let
new-state $ assoc state :menu? false
result $ nth item 1
js/console.log item
case-default result (d! cursor new-state)
:done $ do
d! :task/finish-working $ :id task
d! cursor new-state
:edit $ do (d! cursor new-state)
.show update-plugin d! $ fn (text)
d! :task/update-working $ {}
:id $ :id task
:text text
:copy $ do
copy! $ :text task
d! cursor new-state
:remove $ do (d! cursor new-state)
.show delete-plugin d! $ fn ()
d! :task/remove-working $ :id task
:pend $ do
d! :task/pend $ :id task
d! cursor new-state
:touch $ do
d! :task/touch-working $ :id task
d! cursor new-state
.render update-plugin
.render delete-plugin
|comp-title $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-title (title child ? on-click)
div
{} (:class-name css-title)
:style $ if (fn? on-click)
{} $ :cursor :pointer
:on-click $ fn (e d!)
if (fn? on-click) (on-click e d!)
<> title
=< 16 nil
, child
|css-task-base $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-task-base $ {}
"\"$0" $ {}
:border-bottom $ str "\"1px solid " (hsl 0 0 90)
:line-height "\"24px"
:padding "\"8px 8px"
:overflow :auto
:user-select :none
:transition-duration "\"200ms"
"\"$0:hover" $ {}
:background-color $ hsl 0 0 80 0.1
|css-title $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-title $ {}
"\"$0" $ merge ui/row-middle
{} (:margin "\"8px 0") (:font-family ui/font-fancy)
:color $ hsl 0 0 50
:font-size 16
:font-weight 300
|effect-focus $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-focus () (action el *local)
case action
:mount $ -> el (.querySelector "\"input") (.focus)
do
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.overview $ :require
respo-ui.core :refer $ hsl
respo-ui.css :as css
respo.css :refer $ defstyle
app.schema :as schema
respo-ui.core :as ui
respo.core :refer $ defcomp list-> >> <> span div button textarea input a defeffect
respo.comp.space :refer $ =<
app.config :as config
app.style :as style
respo-alerts.core :refer $ comp-prompt comp-modal comp-modal-menu use-prompt use-confirm
feather.core :refer $ comp-i comp-icon
"\"dayjs" :default dayjs
"\"copy-text-to-clipboard" :default copy!
respo.comp.global-keydown :refer $ comp-global-keydown
|app.comp.profile $ %{} :FileEntry
:defs $ {}
|comp-profile $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-profile (user members)
div
{} (:class-name css/flex)
:style $ {} (:padding 16)
div
{} $ :style
{} (:max-width 800) (:margin :auto)
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
div ({})
button
{} (:class-name css/button)
:on-click $ fn (e d!)
js/location.replace $ str js/location.origin "\"?time=" (.now js/Date)
<> "\"Refresh"
=< 16 nil
button
{} (:class-name css/button)
:style $ {} (:color :red) (:border-color :red)
:on-click $ fn (e d!) (d! :user/log-out nil)
js/localStorage.removeItem $ :storage-key config/site
<> "\"Log out"
|css-member-label $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-member-label $ {}
"\"$0" $ {} (:padding "\"0 8px")
:border $ str "\"1px solid " (hsl 0 0 80)
:border-radius "\"16px"
:margin "\"0 4px"
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.profile $ :require
respo-ui.core :refer $ hsl
respo-ui.css :as css
app.schema :as schema
respo-ui.core :as ui
respo.core :refer $ defcomp list-> <> span div button
respo.css :refer $ defstyle
respo.comp.space :refer $ =<
app.config :as config
|app.config $ %{} :FileEntry
:defs $ {}
|dev? $ %{} :CodeEntry (:doc |)
:code $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ %{} :CodeEntry (:doc |)
:code $ quote
def site $ {} (:port 11009) (:title "\"Timegrass") (:icon "\"http://cdn.tiye.me/logo/timegrass.png") (:dev-ui "\"http://localhost:8100/main.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main.css") (:cdn-url "\"http://cdn.tiye.me/timegrass/") (:theme "\"#51C766") (:storage-key "\"timegrass") (:storage-file "\"storage.cirru")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.config)
|app.schema $ %{} :FileEntry
:defs $ {}
|complain $ %{} :CodeEntry (:doc |)
:code $ quote
def complain $ {} (:id nil) (:text "\"") (:time nil)
|database $ %{} :CodeEntry (:doc |)
:code $ quote
def database $ {}
:sessions $ do session ({})
:users $ do user ({})
:today "\"2018-08-07"
|note $ %{} :CodeEntry (:doc |)
:code $ quote
def note $ {} (:id nil) (:time nil) (:updated-time nil) (:text nil)
|notification $ %{} :CodeEntry (:doc |)
:code $ quote
def notification $ {} (:id nil) (:kind nil) (:text nil)
|router $ %{} :CodeEntry (:doc |)
:code $ quote
def router $ {} (:name nil) (:title nil)
:data $ {}
:router nil
|session $ %{} :CodeEntry (:doc |)
:code $ quote
def session $ {} (:user-id nil) (:id nil) (:nickname nil)
:router $ {} (:name :home) (:data nil) (:router nil)
:messages $ {}
|task $ %{} :CodeEntry (:doc |)
:code $ quote
def task $ {} (:id nil) (:text "\"") (:detail "\"") (:pending? false) (:created-time nil) (:touched-time nil) (:finished-time nil) (:archived-time nil)
|user $ %{} :CodeEntry (:doc |)
:code $ quote
def user $ {} (:name nil) (:id nil) (:nickname nil) (:avatar nil) (:password nil)
:tasks $ {}
:working $ do task ({})
:pending $ {}
:finished $ {}
:notes $ do note ({})
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.schema)
|app.server $ %{} :FileEntry
:defs $ {}
|*client-caches $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *client-caches $ {}
|*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
|*reader-reel $ %{} :CodeEntry (:doc |)
:code $ quote (defatom *reader-reel @*reel)
|*reel $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *reel $ merge reel-schema
{} (:base @*initial-db) (:db @*initial-db)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op sid)