Commit 565af159eaf7a2f0d880ff7e4286e19e59da7ae7
new way of routing
Ev Bogue committed on 5/16/2018, 4:30:42 PMParent: a7a118a87904589a2808d74928225f4ed7832b17
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -1,25 +1,113 @@ | ||
1 | +var pull = require('pull-stream') | |
2 | +var sbot = require('./scuttlebot') | |
3 | +var hyperscroll = require('hyperscroll') | |
4 | +var More = require('pull-more') | |
5 | +var stream = require('hyperloadmore/stream') | |
1 | 6 | var h = require('hyperscript') |
7 | +var render = require('./render') | |
2 | 8 | |
3 | -var views = require('./views') | |
4 | - | |
5 | 9 | var ref = require('ssb-ref') |
6 | 10 | |
7 | 11 | document.head.appendChild(h('style', require('./style.css.json'))) |
8 | 12 | |
9 | -var src = window.location.hash.substring(1) | |
13 | +function hash () { | |
14 | + return window.location.hash.substring(1) | |
15 | +} | |
10 | 16 | |
17 | +var content = h('div.content') | |
18 | + | |
19 | +var screen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}) | |
20 | + | |
21 | +function route () { | |
22 | + var src = hash() | |
23 | + | |
24 | + if (ref.isFeed(src)) { | |
25 | + var content = h('div.content') | |
26 | + var screen = document.getElementById('screen') | |
27 | + screen.appendChild(hyperscroll(content)) | |
28 | + function createStream (opts) { | |
29 | + return pull( | |
30 | + More(sbot.userStream, opts, ['value', 'sequence']), | |
31 | + pull.map(function (msg) { | |
32 | + return h('div', render(msg)) | |
33 | + }) | |
34 | + ) | |
35 | + } | |
36 | + | |
37 | + pull( | |
38 | + createStream({old: false, limit: 10, id: src}), | |
39 | + stream.top(content) | |
40 | + ) | |
41 | + | |
42 | + pull( | |
43 | + createStream({reverse: true, live: false, limit: 10, id: src}), | |
44 | + stream.bottom(content) | |
45 | + ) | |
46 | + | |
47 | + | |
48 | + } else if (ref.isMsg(src)) { | |
49 | + var content = h('div.content') | |
50 | + var screen = document.getElementById('screen') | |
51 | + screen.appendChild(hyperscroll(content)) | |
52 | + sbot.get(src, function (err, data) { | |
53 | + if (err) {console.log('could not find message') } | |
54 | + data.value = data | |
55 | + console.log(data) | |
56 | + var root = src | |
57 | + if (data.value.content.root) | |
58 | + root = data.value.content.root | |
59 | + sbot.get(root, function (err, data) { | |
60 | + if (err) { console.log('could not find root')} | |
61 | + data.value = data | |
62 | + data.key = root | |
63 | + content.appendChild(h('div', render(data))) | |
64 | + pull( | |
65 | + sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}), | |
66 | + pull.drain(function (msg) { | |
67 | + console.log(msg) | |
68 | + if (msg.value) | |
69 | + content.appendChild(h('div', render(msg))) | |
70 | + }) | |
71 | + ) | |
72 | + }) | |
73 | + }) | |
74 | + } else { | |
75 | + var content = h('div.content') | |
76 | + var screen = document.getElementById('screen') | |
77 | + screen.appendChild(hyperscroll(content)) | |
78 | + function createStream (opts) { | |
79 | + return pull( | |
80 | + More(sbot.createLogStream, opts), | |
81 | + pull.map(function (msg) { | |
82 | + return h('div', render(msg)) | |
83 | + }) | |
84 | + ) | |
85 | + } | |
86 | + | |
87 | + pull( | |
88 | + createStream({old: false, limit: 10}), | |
89 | + stream.top(content) | |
90 | + ) | |
91 | + | |
92 | + pull( | |
93 | + createStream({reverse: true, live: false, limit: 10}), | |
94 | + stream.bottom(content) | |
95 | + ) | |
96 | + | |
97 | + } | |
98 | +} | |
99 | + | |
100 | +document.body.appendChild(screen) | |
101 | +route() | |
102 | + | |
11 | 103 | window.onhashchange = function () { |
12 | - window.location.reload() | |
104 | + //var content = h('div.content') | |
105 | + var screen = document.getElementById('screen') | |
106 | + var newscreen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}) | |
107 | + | |
108 | + //if(_screen != null) | |
109 | + console.log(screen) | |
110 | + screen.parentNode.replaceChild(newscreen, screen) | |
111 | + route() | |
13 | 112 | } |
14 | 113 | |
15 | -if (src == 'raw') { | |
16 | - views.rawstream() | |
17 | -} else if (ref.isFeed(src)) { | |
18 | - views.userstream(src) | |
19 | -} else if (ref.isMsg(src)) { | |
20 | - views.get(src) | |
21 | -} else if (src == 'compose') { | |
22 | - views.compose() | |
23 | -} else { | |
24 | - views.logstream() | |
25 | -} |
Built with git-ssb-web