Files: 591f5b731bb11a2356ab101d2f15710f484e218c / modules / page / html / render / tag.js
2141 bytesRaw
1 | const { Value, computed, map, when, h } = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'about.obs.valueFrom': 'first', |
6 | 'keys.sync.id': 'first', |
7 | 'message.html.render': 'first', |
8 | 'message.obs.get': 'first', |
9 | 'tag.html.tag': 'first', |
10 | 'tag.obs.allTagsFrom': 'first', |
11 | 'tag.obs.taggedMessages': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('page.html.render') |
15 | |
16 | exports.create = function (api) { |
17 | return nest('page.html.render', function channel (path) { |
18 | if (!path.startsWith('/tags')) return |
19 | |
20 | const myId = api.keys.sync.id() |
21 | const tags = map( |
22 | api.tag.obs.allTagsFrom(myId), |
23 | tagId => { |
24 | return { tagId, tagName: api.about.obs.valueFrom(tagId, 'name', myId) } |
25 | } |
26 | ) |
27 | const selectedTagId = Value(path.split('/')[2]) |
28 | const name = computed( |
29 | selectedTagId, |
30 | tagId => tagId |
31 | ? api.about.obs.valueFrom(tagId, 'name', myId) |
32 | : Value('Select A Tag') |
33 | ) |
34 | const tagMessages = computed( |
35 | selectedTagId, |
36 | tagId => tagId |
37 | ? map( |
38 | api.tag.obs.taggedMessages(myId, tagId), |
39 | msgId => api.message.obs.get(msgId) |
40 | ) |
41 | : [] |
42 | ) |
43 | |
44 | var prepend = [ |
45 | h('PageHeading', [ |
46 | h('h1', [ h('strong', 'Tags'), ' from you' ]), |
47 | ]) |
48 | ] |
49 | |
50 | return h('div.SplitView', [ |
51 | h('div.side', [ |
52 | h('h2', 'Your Tags'), |
53 | map( |
54 | tags, |
55 | tag => computed( |
56 | tag, |
57 | ({ tagId, tagName }) => |
58 | h('a', { |
59 | 'ev-click': () => selectedTagId.set(tagId), |
60 | style: { 'margin-bottom': '.3rem', display: 'inline-block' } |
61 | }, api.tag.html.tag({ tagName, tagId }, null)) |
62 | ) |
63 | ) |
64 | ]), |
65 | h('div.main', [ |
66 | h('Scroller',[ |
67 | h('h2', name), |
68 | h('section.messages', [ |
69 | map( |
70 | tagMessages, |
71 | msg => computed(msg, msg => { |
72 | if (msg && !msg.value.missing) { |
73 | return h('div.messagewrapper', api.message.html.render(msg)) |
74 | } |
75 | }) |
76 | ) |
77 | ]) |
78 | ]) |
79 | ]) |
80 | ]) |
81 | }) |
82 | } |
83 |
Built with git-ssb-web