Commit 704d8cb70ad1294f388f5fb5149659597e439c45
first pass on better suggestions
mix irving committed on 4/3/2017, 7:07:53 AMParent: fa10ca34011578ba930c05f7c0cfb3fd1c465999
Files changed
about/async/suggest.js | changed |
about/async/suggest.js | ||
---|---|---|
@@ -1,12 +1,13 @@ | ||
1 | 1 … | var nest = require('depnest') |
2 | -var { Struct, map, computed, watch } = require('mutant') | |
2 … | +var { Struct, map, concat, dictToCollection, computed, watch } = require('mutant') | |
3 | 3 … | |
4 | 4 … | exports.gives = nest('about.async.suggest') |
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 | 7 … | 'about.obs': { |
8 | 8 … | name: 'first', |
9 … | + names: 'first', | |
9 | 10 … | imageUrl: 'first' |
10 | 11 … | }, |
11 | 12 … | 'contact.obs.following': 'first', |
12 | 13 … | 'feed.obs.recent': 'first', |
@@ -52,13 +53,52 @@ | ||
52 | 53 … | computed(recentlyUpdated, (items) => Array.from(items).slice(0, 10)), |
53 | 54 … | suggestion, |
54 | 55 … | {idle: true} |
55 | 56 … | ) |
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 … | + | |
57 | 72 … | watch(recentSuggestions) |
58 | 73 … | watch(suggestions) |
59 | 74 … | } |
60 | 75 … | |
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 … | + | |
61 | 101 … | function suggestion (id) { |
62 | 102 … | var name = api.about.obs.name(id) |
63 | 103 … | return Struct({ |
64 | 104 … | title: name, |
Built with git-ssb-web