git ssb

2+

mixmix / ticktack



Tree: 856796486d48c7b494769019a74b9b843471ee41

Files: 856796486d48c7b494769019a74b9b843471ee41 / contact / html / block.js

1809 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 return nest('contact.html.block', block)
17
18 function block (feed) {
19 const strings = api.translations.sync.strings()
20 const myId = api.keys.sync.id()
21
22 if (feed === myId) return
23
24 const { blockers } = api.contact.obs
25 const theirBlockers = blockers(feed)
26 const youBlockThem = computed(theirBlockers, blockers => blockers.includes(myId))
27 const { unblock, block } = api.contact.async
28 const className = when(youBlockThem, '-blocking')
29
30 const isOpen = Value(false)
31
32 const blockAndClose = (feed) => {
33 block(feed)
34 isOpen.set(false)
35 }
36
37 const confirmationDialog = h('div.dialog', [
38 h('div.message', strings.userShow.action.blockConfirmationMessage),
39 h('div.actions', [
40 h('Button', {'ev-click': () => isOpen.set(false)}, strings.userShow.action.cancel),
41 h('Button -primary', {'ev-click': () => blockAndClose(feed)}, strings.userShow.action.block)
42 ])
43 ])
44
45 const lb = api.app.html.lightbox(confirmationDialog, isOpen)
46
47 return h('Block', { className }, [
48 when(theirBlockers.sync,
49 when(youBlockThem,
50 h('Button', { 'ev-click': () => unblock(feed) }, strings.userShow.action.unblock),
51 h('Button', { 'ev-click': () => isOpen.set(true) }, strings.userShow.action.block)
52 ),
53 h('Button', { disabled: 'disabled' }, strings.loading)
54 ),
55 lb
56 ])
57 }
58}
59

Built with git-ssb-web