git ssb

2+

mixmix / ticktack



Tree: bf250c5c301cdcd83a84b88c89dd0d55db5fb8d7

Files: bf250c5c301cdcd83a84b88c89dd0d55db5fb8d7 / contact / html / block.js

1812 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, computed, when, map, Value } = require('mutant')
3
4exports.gives = nest('contact.html.block')
5
6exports.needs = nest({
7 'contact.async.block': 'first',
8 'contact.async.unblock': 'first',
9 'contact.obs.blockers': 'first',
10 'keys.sync.id': 'first',
11 'translations.sync.strings': 'first',
12 'app.html.lightbox': 'first'
13})
14
15exports.create = (api) => {
16
17 return nest('contact.html.block', block)
18
19 function block (feed) {
20 const strings = api.translations.sync.strings()
21 const myId = api.keys.sync.id()
22
23 if (feed === myId) return
24
25 const { blockers } = api.contact.obs
26 const theirBlockers = blockers(feed)
27 const youBlockThem = computed(theirBlockers, blockers => blockers.includes(myId))
28 const { unblock, block } = api.contact.async
29 const className = when(youBlockThem, '-blocking')
30
31 const isOpen = Value(false)
32
33 const blockAndClose = (feed) => {
34 block(feed)
35 isOpen.set(false)
36 }
37
38 const confirmationDialog = h("div.dialog", [
39 h("div.message",strings.userShow.action.blockConfirmationMessage),
40 h("div.actions", [
41 h('Button', {'ev-click': () => isOpen.set(false)}, strings.userShow.action.cancel),
42 h('Button -primary', {'ev-click': () => blockAndClose(feed)}, strings.userShow.action.block)
43 ])
44 ])
45
46 const lb = api.app.html.lightbox(confirmationDialog, isOpen)
47
48 return h('Block', { className }, [
49 when(theirBlockers.sync,
50 when(youBlockThem,
51 h('Button', { 'ev-click': () => unblock(feed) }, strings.userShow.action.unblock),
52 h('Button', { 'ev-click': () => isOpen.set(true) }, strings.userShow.action.block)
53 ),
54 h('Button', { disabled: 'disabled' }, strings.loading )
55 ),
56 lb
57 ])
58 }
59}
60
61

Built with git-ssb-web