Commit 831b7a455f339b50a009d374af02bbaab45aa0ac
Merge remote-tracking branch 'picknmix/better_suggest' into better_suggest
mix irving committed on 4/6/2017, 8:37:35 AMParent: 822fd812786ca6ef22677d876b8c056c0ad8cc82
Parent: 1e484444d12a810e93c10c563ae3a39a1036ab64
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, lookup, watch, keys, resolve } = 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,35 @@ | |||
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 = 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 … | + | ||
57 | 66 … | watch(recentSuggestions) | |
58 | 67 … | watch(suggestions) | |
59 | 68 … | } | |
60 | 69 … | ||
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 … | + | ||
61 | 84 … | function suggestion (id) { | |
62 | 85 … | var name = api.about.obs.name(id) | |
63 | 86 … | return Struct({ | |
64 | 87 … | title: name, | |
@@ -68,10 +91,17 @@ | |||
68 | 91 … | image: api.about.obs.imageUrl(id), | |
69 | 92 … | showBoth: true | |
70 | 93 … | }) | |
71 | 94 … | } | |
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 … | + } | ||
72 | 103 … | } | |
73 | 104 … | ||
74 | 105 … | function mention (name, id) { | |
75 | 106 … | return `[@${name}](${id})` | |
76 | 107 … | } | |
77 | - |
Built with git-ssb-web