git ssb

16+

Dominic / patchbay



Commit f4403f27a548f4b7a08d65c2c8e8664b2594fff1

fixup

mix irving committed on 4/24/2017, 11:43:03 AM
Parent: b7d7f86afc99c01161ac2e00a2decf8ecb85246e

Files changed

app/html/app.jschanged
app/html/menu.jschanged
app/html/search-bar.jschanged
app/html/tabs.jschanged
app/sync/addPage.jschanged
app/sync/catch-keyboard-shortcut.jschanged
app/sync/goTo.jschanged
message/html/render/follow.jschanged
package.jsonchanged
app/html/app.jsView
@@ -1,8 +1,7 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
33 const insertCss = require('insert-css')
4-const Tabs = require('hypertabs')
54
65 exports.gives = nest('app.html.app')
76
87 exports.needs = nest({
@@ -13,9 +12,9 @@
1312 html: {
1413 error: 'first',
1514 externalConfirm: 'first',
1615 tabs: 'first',
17- page: 'first',
16 + page: 'first'
1817 },
1918 sync: {
2019 addPage: 'first',
2120 catchKeyboardShortcut: 'first'
app/html/menu.jsView
@@ -5,19 +5,23 @@
55
66 exports.needs = nest('app.html.menuItem', 'map')
77
88 exports.create = function (api) {
9- return nest('app.html.menu', menu)
9 + var _menu
1010
11- function menu (handleClick) {
11 + return nest('app.html.menu', function menu (handleClick) {
12 + if (_menu) return _menu
13 +
1214 var state = Value('')
1315
14- return h('Menu', {
16 + _menu = h('Menu', {
1517 classList: [ state ],
1618 'ev-mouseover': () => state.set('-active'),
1719 'ev-mouseout': () => state.set('')
1820 }, [
1921 h('div', api.app.html.menuItem(handleClick))
2022 ])
21- }
23 +
24 + return _menu
25 + })
2226 }
2327
app/html/search-bar.jsView
@@ -4,16 +4,20 @@
44
55 exports.gives = nest('app.html.searchBar')
66
77 exports.needs = nest({
8 + 'app.sync.goTo': 'first',
89 'about.async.suggest': 'first',
910 'channel.async.suggest': 'first'
1011 })
1112
1213 exports.create = function (api) {
13- return nest('app.html.searchBar', searchBar)
14 + var _search
1415
15- function searchBar (go) {
16 + return nest('app.html.searchBar', function searchBar () {
17 + if (_search) return _search
18 +
19 + const goTo = api.app.sync.goTo
1620 const getProfileSuggestions = api.about.async.suggest()
1721 const getChannelSuggestions = api.channel.async.suggest()
1822
1923 const input = h('input', {
@@ -21,9 +25,9 @@
2125 placeholder: '?search, @name, #channel',
2226 'ev-keyup': ev => {
2327 switch (ev.keyCode) {
2428 case 13: // enter
25- if (go(input.value.trim(), !ev.ctrlKey)) {
29 + if (goTo(input.value.trim(), !ev.ctrlKey)) {
2630 input.blur()
2731 }
2832 return
2933 case 27: // escape
@@ -32,19 +36,18 @@
3236 return
3337 }
3438 }
3539 })
36- input.go = go // crude navigation api
3740 input.addEventListener('suggestselect', ev => {
3841 input.value = ev.detail.id // HACK : this over-rides the markdown value
3942
40- // if (go(input.value.trim(), !ev.ctrlKey))
43 + // if (goTo(input.value.trim(), !ev.ctrlKey))
4144 // input.blur()
4245 })
43- const search = h('SearchBar', input)
4446
45- search.input = input
46- search.activate = (sigil, ev) => {
47 + _search = h('SearchBar', input)
48 + _search.input = input
49 + _search.activate = (sigil, ev) => {
4750 input.focus()
4851 ev.preventDefault()
4952 if (input.value[0] === sigil) {
5053 input.selectionStart = 1
@@ -61,8 +64,8 @@
6164 cb(null, getChannelSuggestions(inputText.slice(1)))
6265 }
6366 }, {cls: 'SuggestBox'})
6467
65- return search
66- }
68 + return _search
69 + })
6770 }
6871
app/html/tabs.jsView
@@ -3,72 +3,44 @@
33 const Tabs = require('hypertabs')
44
55 exports.gives = nest({
66 app: {
7- 'html.tabs': true,
8- sync: {
9- 'goTo': true,
10- 'addPage': true
11- }
7 + 'html.tabs': true
128 }
139 })
1410
1511 exports.needs = nest({
1612 'app.html': {
1713 menu: 'first',
1814 page: 'first',
1915 searchBar: 'first'
20- }
16 + },
17 + 'app.sync.addPage': 'first'
2118 })
2219
2320 exports.create = function (api) {
24-
2521 var _tabs
2622
2723 function tabs (initialTabs = []) {
2824 if (_tabs) return _tabs
2925
30- const search = api.app.html.searchBar(goTo)
31- const menu = api.app.html.menu(goTo)
26 + const search = api.app.html.searchBar()
27 + const menu = api.app.html.menu()
3228 const onSelect = (indexes) => {
3329 search.input.value = _tabs.get(indexes[0]).content.id
3430 }
3531 _tabs = Tabs(onSelect, {
36- append: h('div.navExtra', [ search, menu ])
32 + append: h('div.navExtra', [ search, menu ])
3733 })
34 + _tabs.getCurrent = () => _tabs.get(_tabs.selected[0])
3835
39- initialTabs.forEach(p => addPage(p))
36 + // # TODO: review - this works but is strange
37 + initialTabs.forEach(p => api.app.sync.addPage(p))
4038 _tabs.select(0)
4139 return _tabs
4240 }
4341
44- function goTo (path, change) {
45- tabs()
46- if (_tabs.has(path)) {
47- _tabs.select(path)
48- return true
49- }
50-
51- addPage(path, true, false)
52- return change
53- }
54-
55- function addPage (link, change, split) {
56- tabs()
57- const page = api.app.html.page(link)
58- if (!page) return
59-
60- page.id = page.id || link
61- _tabs.add(page, change, split)
62- }
63-
6442 return nest({
65- app: {
66- 'html.tabs': tabs,
67- sync: {
68- goTo,
69- addPage
70- }
71- }
43 + 'app.html.tabs': tabs
7244 })
7345 }
7446
app/sync/addPage.jsView
@@ -8,11 +8,9 @@
88 })
99
1010 exports.create = function (api) {
1111 return nest({
12- 'app.sync': {
13- addPage
14- }
12 + 'app.sync': { addPage }
1513 })
1614
1715 // TODO : make it so error catching doesn't need this, move it into goTo
1816 function addPage (link, change, split) {
@@ -25,5 +23,4 @@
2523 tabs.add(page, change, split)
2624 }
2725 }
2826
29-
app/sync/catch-keyboard-shortcut.jsView
@@ -1,24 +1,36 @@
11 const nest = require('depnest')
22
33 exports.gives = nest('app.sync.catchKeyboardShortcut')
44
5 +exports.needs = nest({
6 + 'app.html': {
7 + searchBar: 'first',
8 + tabs: 'first'
9 + },
10 + 'app.sync': {
11 + goTo: 'first'
12 + }
13 +})
14 +
515 exports.create = function (api) {
616 return nest('app.sync.catchKeyboardShortcut', catchKeyboardShortcut)
717
8- function catchKeyboardShortcut (root, opts) {
18 + function catchKeyboardShortcut (root) {
919 var gPressed = false
1020
21 + var tabs = api.app.html.tabs()
22 + var search = api.app.html.searchBar()
23 + var goTo = api.app.sync.goTo
24 +
1125 root.addEventListener('keydown', (ev) => {
1226 isTextFieldEvent(ev)
1327 ? textFieldShortcuts(ev)
14- : genericShortcuts(ev, opts)
28 + : genericShortcuts(ev, { tabs, search, goTo })
1529 })
1630 }
1731 }
1832
19-// TODO build better apis for navigation, search, and publishing
20-
2133 function isTextFieldEvent (ev) {
2234 const tag = ev.target.nodeName
2335 return (tag === 'INPUT' || tag === 'TEXTAREA')
2436 }
@@ -28,30 +40,30 @@
2840 ev.target.publish() // expects the textField to have a publish method
2941 }
3042 }
3143
32-function genericShortcuts (ev, { tabs, search }) {
44 +function genericShortcuts (ev, { tabs, goTo, search }) {
3345 // Messages
3446 if (ev.keyCode === 71) { // gg = scroll to top
3547 if (!gPressed) {
3648 gPressed = true
3749 return
3850 }
39- tabs.get(tabs.selected[0]).firstChild.scroll('first')
51 + tabs.getCurrent().firstChild.scroll('first')
4052 }
4153 gPressed = false
4254
4355 switch (ev.keyCode) {
4456
4557 // Messages (cont'd)
4658 case 74: // j = older
47- return tabs.get(tabs.selected[0]).firstChild.scroll(1)
59 + return tabs.getCurrent().firstChild.scroll(1)
4860 case 75: // k = newer
49- return tabs.get(tabs.selected[0]).firstChild.scroll(-1)
61 + return tabs.getCurrent().firstChild.scroll(-1)
5062 case 13: // enter = open
51- return goToMessage(ev, tabs)
63 + return goToMessage(ev, { tabs, goTo })
5264 case 79: // o = open
53- return goToMessage(ev, tabs)
65 + return goToMessage(ev, { tabs, goTo })
5466 case 192: // ` = toggle raw message view
5567 return toggleRawMessage(ev)
5668
5769 // Tabs
@@ -84,28 +96,25 @@
8496 return
8597 }
8698 }
8799
88-function goToMessage (ev, tabs) {
100 +function goToMessage (ev, { tabs, goTo }) {
89101 const msg = ev.target
90102 if (!msg.classList.contains('Message')) return
91103
92- // this uses a crudely exported nav api
93- const search = document.querySelector('input[type=search]')
94-
95104 const { root, id } = msg.dataset
96- if (!root) return search.go(id)
105 + if (!root) return goTo(id)
97106
98- search.go(root)
107 + goTo(root)
99108 scrollDownToMessage(id, tabs)
100109 }
101110
102111 function scrollDownToMessage (id, tabs) {
103- tabs.get(tabs.selected[0]).firstChild.scroll('first')
112 + tabs.getCurrent().firstChild.scroll('first')
104113 locateKey()
105114
106115 function locateKey () {
107- const msg = tabs.get(tabs.selected[0]).querySelector(`[data-id='${id}']`)
116 + const msg = tabs.getCurrent().querySelector(`[data-id='${id}']`)
108117 if (msg === null) return setTimeout(locateKey, 100)
109118
110119 ;(msg.scrollIntoViewIfNeeded || msg.scrollIntoView).call(msg)
111120 msg.focus()
app/sync/goTo.jsView
@@ -3,28 +3,21 @@
33 exports.gives = nest({ 'app.sync.goTo': true })
44
55 exports.needs = nest({
66 'app.html.tabs': 'first',
7- 'app.sync.addPage': 'first'
7 + 'app.sync.addPage': 'first'
88 })
99
1010 exports.create = function (api) {
11- return nest({
12- 'app.sync': {
13- goTo
14- }
15- })
16-
17- function goTo (path, change) {
11 + return nest('app.sync.goTo', function goTo (path, change) {
1812 const tabs = api.app.html.tabs()
1913
2014 if (tabs.has(path)) {
2115 tabs.select(path)
2216 return true
2317 }
2418
25- addPage(path, true, false)
19 + api.app.sync.addPage(path, true, false)
2620 return change
27- }
28-
21 + })
2922 }
3023
message/html/render/follow.jsView
@@ -1,6 +1,7 @@
11 const nest = require('depnest')
22 const extend = require('xtend')
3 +const { isFeed } = require('ssb-ref')
34
45 exports.gives = nest('message.html.render')
56
67 exports.needs = nest({
@@ -16,9 +17,9 @@
1617
1718 function follow (msg, opts) {
1819 const { type, contact, following } = msg.value.content
1920 if (type !== 'contact') return
20- if (!contact) return
21 + if (!isFeed(contact)) return
2122
2223 const element = api.message.html.layout(msg, extend({
2324 content: renderContent({ contact, following }),
2425 layout: 'mini'
package.jsonView
@@ -52,9 +52,9 @@
5252 "patchcore": "^0.5.0",
5353 "pull-abortable": "^4.1.1",
5454 "pull-cat": "^1.1.11",
5555 "pull-next": "1.0.0",
56- "pull-scroll": "^1.0.3",
56 + "pull-scroll": "^1.0.4",
5757 "pull-stream": "^3.5.0",
5858 "read-directory": "^2.0.0",
5959 "setimmediate": "^1.0.5",
6060 "ssb-horcrux": "0.1.2",

Built with git-ssb-web