Commit 0b0275502152a806a995b36fd4d29e8c3df1195e
wip - addressbook search starting to work
mix committed on 1/25/2018, 4:30:47 AMParent: 8c00d2692c05faece6e79ee8158e2cbf6612e078
Files changed
app/html/app.js | changed |
app/html/sideNav/sideNavDiscovery.js | changed |
app/html/topNav/topNavBlog.js | changed |
app/html/topNav/zz_topNavBack.js | changed |
app/html/topNav/topNavAddressBook.js | added |
app/html/topNav/topNavAddressBook.mcss | added |
app/index.js | changed |
app/page/addressBook.js | changed |
app/page/addressBook.mcss | changed |
blog/html/blog.js | changed |
app/html/app.js | ||
---|---|---|
@@ -28,8 +28,9 @@ | ||
28 | 28 | |
29 | 29 | view = Value() |
30 | 30 | var app = h('App', view) |
31 | 31 | api.history.obs.location()(renderLocation) |
32 | + api.history.obs.location()(loc => console.log('location:', loc)) | |
32 | 33 | |
33 | 34 | startApp() |
34 | 35 | |
35 | 36 | return app |
app/html/sideNav/sideNavDiscovery.js | ||
---|---|---|
@@ -76,13 +76,15 @@ | ||
76 | 76 | LevelTwoSideNav() |
77 | 77 | ]) |
78 | 78 | |
79 | 79 | function LevelOneSideNav () { |
80 | - function isDiscoverSideNav (loc) { | |
80 | + function isDiscoverLocation (loc) { | |
81 | 81 | const PAGES_UNDER_DISCOVER = ['blogIndex', 'blogShow', 'userShow'] |
82 | 82 | |
83 | - return PAGES_UNDER_DISCOVER.includes(location.page) | |
84 | - || get(location, 'value.private') === undefined | |
83 | + if (PAGES_UNDER_DISCOVER.includes(location.page)) return true | |
84 | + if (location.page === 'threadNew') return false | |
85 | + if (get(location, 'value.private') === undefined) return true | |
86 | + return false | |
85 | 87 | } |
86 | 88 | |
87 | 89 | const prepend = [ |
88 | 90 | // Nearby |
@@ -90,9 +92,9 @@ | ||
90 | 92 | map(nearby, feedId => Option({ |
91 | 93 | notifications: notifications(feedId), |
92 | 94 | imageEl: api.about.html.avatar(feedId, 'small'), |
93 | 95 | label: api.about.obs.name(feedId), |
94 | - selected: location.feed === feedId, | |
96 | + selected: location.feed === feedId && !isDiscoverLocation(location), | |
95 | 97 | location: computed(recentMsgCache, recent => { |
96 | 98 | const lastMsg = recent.find(msg => msg.value.author === feedId) |
97 | 99 | return lastMsg |
98 | 100 | ? Object.assign(lastMsg, { feed: feedId }) |
@@ -110,9 +112,9 @@ | ||
110 | 112 | imageEl: h('i', [ |
111 | 113 | h('img', { src: path.join(__dirname, '../../../assets', 'discover.png') }) |
112 | 114 | ]), |
113 | 115 | label: strings.blogIndex.title, |
114 | - selected: isDiscoverSideNav(location), | |
116 | + selected: isDiscoverLocation(location), | |
115 | 117 | location: { page: 'blogIndex' }, |
116 | 118 | }) |
117 | 119 | ] |
118 | 120 |
app/html/topNav/topNavBlog.js | ||
---|---|---|
@@ -5,17 +5,15 @@ | ||
5 | 5 | exports.gives = nest('app.html.topNav') |
6 | 6 | |
7 | 7 | exports.needs = nest({ |
8 | 8 | 'history.sync.push': 'first', |
9 | - 'history.sync.back': 'first', | |
10 | 9 | 'translations.sync.strings': 'first', |
11 | 10 | }) |
12 | 11 | |
13 | 12 | exports.create = (api) => { |
14 | 13 | return nest('app.html.topNav', (location) => { |
15 | 14 | const strings = api.translations.sync.strings() |
16 | 15 | const goTo = (loc) => () => api.history.sync.push(loc) |
17 | - const back = () => api.history.sync.back() | |
18 | 16 | |
19 | 17 | if (!['blogIndex', 'blogSearch'].includes(location.page)) return |
20 | 18 | |
21 | 19 | return h('TopNav -blog', [ |
@@ -32,18 +30,7 @@ | ||
32 | 30 | h('div.right', [ |
33 | 31 | h('Button -strong', { 'ev-click': () => api.history.sync.push({ page: 'blogNew' }) }, strings.blogNew.actions.writeBlog), |
34 | 32 | ]) |
35 | 33 | ]) |
36 | - | |
37 | - return h('TopNav -back', [ | |
38 | - h('div.left', [ | |
39 | - h('div.-back', { 'ev-click': back }, [ | |
40 | - h('i.fa.fa-chevron-left'), | |
41 | - strings.blogIndex.title | |
42 | - ]), | |
43 | - ]), | |
44 | - h('div.right', [ | |
45 | - ]) | |
46 | - ]) | |
47 | 34 | }) |
48 | 35 | } |
49 | 36 |
app/html/topNav/zz_topNavBack.js | ||
---|---|---|
@@ -4,9 +4,8 @@ | ||
4 | 4 | |
5 | 5 | exports.gives = nest('app.html.topNav') |
6 | 6 | |
7 | 7 | exports.needs = nest({ |
8 | - 'history.sync.push': 'first', | |
9 | 8 | 'history.sync.back': 'first', |
10 | 9 | 'translations.sync.strings': 'first', |
11 | 10 | }) |
12 | 11 |
app/html/topNav/topNavAddressBook.js | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h, computed, when } = require('mutant') | |
3 | +const get = require('lodash/get') | |
4 | + | |
5 | +exports.gives = nest('app.html.topNav') | |
6 | + | |
7 | +exports.needs = nest({ | |
8 | + 'translations.sync.strings': 'first', | |
9 | +}) | |
10 | + | |
11 | +exports.create = (api) => { | |
12 | + return nest('app.html.topNav', (location, input) => { | |
13 | + if (location.page !== 'addressBook') return | |
14 | + | |
15 | + const strings = api.translations.sync.strings() | |
16 | + | |
17 | + return h('TopNav -addressBook', [ | |
18 | + h('div.search', [ | |
19 | + h('i.fa.fa-search'), | |
20 | + h('input', { | |
21 | + placeholder: strings.userFind.action.findAUser, | |
22 | + autofocus: 'autofocus', | |
23 | + 'ev-input': e => input.set(e.target.value) | |
24 | + }), | |
25 | + ]) | |
26 | + ]) | |
27 | + }) | |
28 | +} | |
29 | + |
app/html/topNav/topNavAddressBook.mcss | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 | +TopNav -addressBook { | |
2 | + div.search { | |
3 | + $backgroundPrimaryText | |
4 | + | |
5 | + margin-bottom: .5rem | |
6 | + | |
7 | + display: flex | |
8 | + align-items: center | |
9 | + | |
10 | + i.fa-search { | |
11 | + margin-left: .8rem | |
12 | + } | |
13 | + | |
14 | + input { | |
15 | + flex-grow: 1 | |
16 | + | |
17 | + $fontBasic | |
18 | + margin: .6rem | |
19 | + | |
20 | + border: none | |
21 | + outline: none | |
22 | + } | |
23 | + } | |
24 | + | |
25 | +} | |
26 | + |
app/index.js | ||
---|---|---|
@@ -10,8 +10,9 @@ | ||
10 | 10 | link: require('./html/link'), |
11 | 11 | lightbox: require('./html/lightbox'), |
12 | 12 | blogCard: require('./html/blogCard'), |
13 | 13 | topNav: { |
14 | + topNavAddressBook: require('./html/topNav/topNavAddressBook'), | |
14 | 15 | topNavBlog: require('./html/topNav/topNavBlog'), |
15 | 16 | topNavBack: require('./html/topNav/zz_topNavBack'), |
16 | 17 | }, |
17 | 18 | scroller: require('./html/scroller'), |
app/page/addressBook.js | ||
---|---|---|
@@ -1,14 +1,23 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | -const { h } = require('mutant') | |
2 | +const { h, Value, computed, map } = require('mutant') | |
3 | 3 | const pull = require('pull-stream') |
4 | 4 | |
5 | 5 | exports.gives = nest('app.page.addressBook') |
6 | 6 | |
7 | +//declare consts to avoid magic-string errors | |
8 | +const FRIENDS = 'friends' | |
9 | +const FOLLOWING = 'following' | |
10 | +const FOLLOWERS = 'followers' | |
11 | +const SEARCH = 'search' | |
12 | + | |
7 | 13 | exports.needs = nest({ |
8 | - 'app.html.blogNav': 'first', | |
14 | + 'about.html.avatar': 'first', | |
15 | + 'about.async.suggest': 'first', | |
16 | + 'app.html.topNav': 'first', | |
9 | 17 | // 'app.html.scroller': 'first', |
10 | 18 | 'app.html.sideNav': 'first', |
19 | + 'app.html.topNav': 'first', | |
11 | 20 | 'contact.obs.relationships': 'first', |
12 | 21 | 'history.sync.push': 'first', |
13 | 22 | 'keys.sync.id': 'first', |
14 | 23 | 'translations.sync.strings': 'first', |
@@ -21,15 +30,36 @@ | ||
21 | 30 | const strings = api.translations.sync.strings() |
22 | 31 | const myKey = api.keys.sync.id() |
23 | 32 | const relationships = api.contact.obs.relationships(myKey) |
24 | 33 | |
25 | - | |
34 | + const SECTIONS = [FRIENDS, FOLLOWING, FOLLOWERS, SEARCH] | |
35 | + const section = location.section || FRIENDS | |
36 | + if (!SECTIONS.includes(section)) throw new Error('AddressBook location must include valid section, got:', location) | |
26 | 37 | |
38 | + const input = Value() | |
39 | + | |
40 | + const suggester = api.about.async.suggest() | |
41 | + const users = computed(input, input => suggester(input)) | |
42 | + // might further prune this based on section | |
43 | + | |
44 | + | |
45 | + // const goTo = (loc) => () => api.history.sync.push(loc) | |
46 | + | |
27 | 47 | return h('Page -addressBook', [ |
28 | 48 | api.app.html.sideNav(location, relationships), |
29 | - h('div.content', [ | |
30 | - 'pageNav', | |
31 | - '//// content here ////' | |
49 | + h('Scroller.content', [ | |
50 | + h('section.top', [ | |
51 | + api.app.html.topNav(location, input), | |
52 | + ]), | |
53 | + h('section.content', [ | |
54 | + h('div.results', map(users, user => { | |
55 | + return h('div.result', [ | |
56 | + api.about.html.avatar(user.id), | |
57 | + h('div.alias', user.title), | |
58 | + h('pre.key', user.id), | |
59 | + ]) | |
60 | + })), | |
61 | + ]) | |
32 | 62 | ]) |
33 | 63 | ]) |
34 | 64 | }) |
35 | 65 | } |
app/page/addressBook.mcss | ||
---|---|---|
@@ -1,23 +1,48 @@ | ||
1 | -Page -blogIndex { | |
2 | - div.content.Scroller { | |
1 | +Page -addressBook { | |
2 | + div.Scroller.content { | |
3 | 3 | padding: 0 |
4 | 4 | |
5 | 5 | section.top { |
6 | 6 | position: sticky |
7 | 7 | } |
8 | 8 | |
9 | 9 | section.content { |
10 | - div.BlogCard { | |
11 | - flex-basis: 100% | |
12 | - border-bottom: 1px solid rgba(0,0,0, .1) | |
10 | + div.results { | |
11 | + $maxWidthSmaller | |
12 | + | |
13 | + div.result { | |
14 | + $backgroundPrimaryText | |
15 | + | |
16 | + padding: .5rem | |
17 | + | |
18 | + display: flex | |
19 | + align-items: center | |
20 | + | |
21 | + img { | |
22 | + $circleSmall | |
23 | + margin-right: 1rem | |
24 | + } | |
25 | + | |
26 | + div.alias { | |
27 | + flex-grow: 1 | |
28 | + margin-right: 1rem | |
29 | + } | |
30 | + | |
31 | + pre.key { | |
32 | + color: #999 | |
33 | + | |
34 | + } | |
35 | + | |
36 | + :hover { | |
37 | + background-color: #eee | |
38 | + | |
39 | + } | |
40 | + } | |
13 | 41 | } |
14 | 42 | } |
15 | 43 | |
16 | 44 | section.bottom { |
17 | - div.Button { | |
18 | - margin: 1rem 0 | |
19 | - } | |
20 | 45 | } |
21 | 46 | } |
22 | 47 | } |
23 | 48 |
Built with git-ssb-web