git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: c9ba3630ee9b32a904d47de7b87c1e101e5d59c5

Files: c9ba3630ee9b32a904d47de7b87c1e101e5d59c5 / modules / page / html / render / tag.js

1997 bytesRaw
1const { Value, computed, map, when, h } = require('mutant')
2var nest = require('depnest')
3
4exports.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
14exports.gives = nest('page.html.render')
15
16exports.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', map(
52 tags,
53 tag => computed(
54 tag,
55 ({ tagId, tagName }) =>
56 h('a', {
57 'ev-click': () => selectedTagId.set(tagId)
58 }, api.tag.html.tag({ tagName, tagId }, null))
59 )
60 )),
61 h('div.main', [
62 h('Scroller',[
63 h('h2', name),
64 h('section.messages', [
65 map(
66 tagMessages,
67 msg => computed(msg, msg => {
68 if (msg && !msg.value.missing) {
69 return h('div.messagewrapper', api.message.html.render(msg))
70 }
71 })
72 )
73 ])
74 ])
75 ])
76 ])
77 })
78}
79

Built with git-ssb-web