summaryrefslogtreecommitdiff
path: root/desk/web/user.hoon
blob: 5076f0be18cf7b3ba468197023e0bf73f0fd9c77 (plain)
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
/-  *boke, tp=trill-post, cnt=contact
/+  sigil=sigil-sigil, sr=sortug, wall
/=  user  /web/components/user
|_  [who=@p s=state =bowl:gall]
++  css  ^~  %-  trip
'''
#user{
  margin-top: 1rem;

  & .avatar svg{
    margin: auto;
  }
  .button{
    display: block;
    width: max-content;
    margin: auto;
  }
}
'''
++  script  ^~  %-  trip
'''
  const el = document.getElementById("logout");
  el.addEventListener("click", run);
  async function run(){
    // const res = await fetch("/~/logout?redirect=/");
    const res = await fetch("/~/logout");
    if (res) window.location.href = "/";
    console.log(res, "res")
  }
'''
+$  stats  [count=@ud first=@da last=@da]
++  get-stats  ^-  stats
  %+  roll  (tap:gorm:tp feed.s)  |=  [[=pid:tp *] a=stats]
  ?.  .=(ship.pid who)  a
  =.  count.a  +(count.a)
  =.  first.a  
    ?:  .=(first.a *@da)  id.pid
    ?:  (lth id.pid first.a)  id.pid  first.a
  =.  last.a   ?:  (gth id.pid last.a)   id.pid  last.a
  a
  
++  $
  =/  wal  ~(. wall src.bowl)
  =/  contacts  (get-contacts:cnt bowl)
  =/  usr  (user src.bowl contacts 100)
  =/  is-self  .=(src.bowl who)
  =/  stats  get-stats
  =/  subscription  (subscription-type:wal now.bowl)
  

;div#user.blog
  ;style: {css}
  ;h1.tc: User Profile
  ;+  -.usr
  ;h2.tc
    ;+  +.usr
  ==
  ;+  ?:  .=(0 count.stats)  ;p:"No posts"
  ;div.stats
    ;p: Post Count: {(number:string:sr count.stats)}
    ;p: First post: {(date-to-tape:string:sr first.stats "/")}
    ;p: Latest post: {(date-to-tape:string:sr last.stats "/")}
  ==
  ;*  ?.  is-self  ~
      ;*  ?~  subscription
          ;+  ;a.button/"/subscribe":"Subscribe"  ~
      ;+  ;button#logout.button:"Logout"
  ;script:"{script}"

==
--