git ssb

16+

Dominic / patchbay



Commit 831b7a455f339b50a009d374af02bbaab45aa0ac

Merge remote-tracking branch 'picknmix/better_suggest' into better_suggest

mix irving committed on 4/6/2017, 8:37:35 AM
Parent: 822fd812786ca6ef22677d876b8c056c0ad8cc82
Parent: 1e484444d12a810e93c10c563ae3a39a1036ab64

Files changed

about/async/suggest.jschanged
about/async/suggest.jsView
@@ -1,12 +1,13 @@
11 var nest = require('depnest')
2-var { Struct, map, computed, watch } = require('mutant')
2 +var { Struct, map, concat, dictToCollection, computed, lookup, watch, keys, resolve } = require('mutant')
33
44 exports.gives = nest('about.async.suggest')
55
66 exports.needs = nest({
77 'about.obs': {
88 name: 'first',
9 + names: 'first',
910 imageUrl: 'first'
1011 },
1112 'contact.obs.following': 'first',
1213 'feed.obs.recent': 'first',
@@ -52,13 +53,35 @@
5253 computed(recentlyUpdated, (items) => Array.from(items).slice(0, 10)),
5354 suggestion,
5455 {idle: true}
5556 )
56- suggestions = map(contacts, suggestion, {idle: true})
57 +
58 + const suggestionsRecord = lookup(contacts, contact => {
59 + return [contact, keys(api.about.obs.names(contact))]
60 + })
61 +
62 + suggestions = concat(
63 + map(dictToCollection(suggestionsRecord), pluralSuggestions, {idle: true})
64 + )
65 +
5766 watch(recentSuggestions)
5867 watch(suggestions)
5968 }
6069
70 + function pluralSuggestions (item) {
71 + const id = resolve(item.key)
72 + return map(item.value, name => {
73 + return Struct({
74 + id,
75 + title: name,
76 + subtitle: subtitle(id, name),
77 + value: computed([name, id], mention),
78 + image: api.about.obs.imageUrl(id),
79 + showBoth: true
80 + })
81 + })
82 + }
83 +
6184 function suggestion (id) {
6285 var name = api.about.obs.name(id)
6386 return Struct({
6487 title: name,
@@ -68,10 +91,17 @@
6891 image: api.about.obs.imageUrl(id),
6992 showBoth: true
7093 })
7194 }
95 +
96 + function subtitle (id, name) {
97 + return computed([api.about.obs.name(id)], commonName => {
98 + return name.toLowerCase() === commonName.toLowerCase()
99 + ? id.substring(0, 10)
100 + : `${commonName} ${id.substring(0, 10)}`
101 + })
102 + }
72103 }
73104
74105 function mention (name, id) {
75106 return `[@${name}](${id})`
76107 }
77-

Built with git-ssb-web