git ssb

16+

Dominic / patchbay



Commit 704d8cb70ad1294f388f5fb5149659597e439c45

first pass on better suggestions

mix irving committed on 4/3/2017, 7:07:53 AM
Parent: fa10ca34011578ba930c05f7c0cfb3fd1c465999

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, watch } = 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,52 @@
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 = computed(contacts, contacts => {
59 + var result = {}
60 + contacts.forEach(contact => {
61 + result[contact] = api.about.obs.names(contact)
62 + })
63 +
64 + return result
65 + })
66 +
67 + const mapableSuggestions = dictToCollection(suggestionsRecord)
68 + suggestions = concat(
69 + map(mapableSuggestions, pluralSuggestions, {idle: true})
70 + )
71 +
5772 watch(recentSuggestions)
5873 watch(suggestions)
5974 }
6075
76 +
77 + function pluralSuggestions (item) {
78 + const { key, value } = item
79 +
80 + const id = key()
81 + const names = computed(value, v => Object.keys(v))
82 +
83 + return map(names, name => {
84 + const subtitle = computed([api.about.obs.name(id)], commonName => {
85 + return name.toLowerCase() === commonName.toLowerCase()
86 + ? id.substring(0, 10)
87 + : `${commonName} ${id.substring(0, 10)}`
88 + })
89 +
90 + return Struct({
91 + title: name,
92 + id,
93 + subtitle,
94 + value: computed([name, id], mention),
95 + image: api.about.obs.imageUrl(id),
96 + showBoth: true
97 + })
98 + })
99 + }
100 +
61101 function suggestion (id) {
62102 var name = api.about.obs.name(id)
63103 return Struct({
64104 title: name,

Built with git-ssb-web