git ssb

2+

ev / mvd



Commit 8cbf61e71d58d05291bf568722a7edeb856f671b

move views into their own functions

Ev Bogue committed on 5/27/2018, 11:55:01 PM
Parent: 934aacc8386594385eab23772a38b11406625294

Files changed

views.jschanged
views.jsView
@@ -12,17 +12,45 @@
1212 var fs = require('fs')
1313
1414 var compose = require('./compose')
1515
16-function hash () {
17- return window.location.hash.substring(1)
16 +var about = function () {
17 + var screen = document.getElementById('screen')
18 +
19 + var about = require('./about')
20 +
21 + var content = h('div.content', about)
22 +
23 + screen.appendChild(hyperscroll(content))
1824 }
1925
20-module.exports = function () {
21- var src = hash()
26 +var logStream = function () {
27 + var content = h('div.content')
28 + var screen = document.getElementById('screen')
29 + screen.appendChild(hyperscroll(content))
2230
23- if (ref.isFeed(src)) {
24- var content = h('div.content')
31 + function createStream (opts) {
32 + return pull(
33 + More(sbot.createLogStream, opts),
34 + pull.map(function (msg) {
35 + return render(msg)
36 + })
37 + )
38 + }
39 +
40 + pull(
41 + createStream({old: false, limit: 10}),
42 + stream.top(content)
43 + )
44 +
45 + pull(
46 + createStream({reverse: true, live: false, limit: 10}),
47 + stream.bottom(content)
48 + )
49 +}
50 +
51 +var userStream = function (src) {
52 + var content = h('div.content')
2553 var screen = document.getElementById('screen')
2654 screen.appendChild(hyperscroll(content))
2755 function createStream (opts) {
2856 return pull(
@@ -42,106 +70,90 @@
4270 createStream({reverse: true, live: false, limit: 10, id: src}),
4371 stream.bottom(content)
4472 )
4573
74 +}
4675
47- } else if (ref.isMsg(src)) {
48- var content = h('div.content')
49- var screen = document.getElementById('screen')
50- screen.appendChild(hyperscroll(content))
51- sbot.get(src, function (err, data) {
52- if (err) {console.log('could not find message') }
76 +var msgThread = function(src) {
77 + var content = h('div.content')
78 + var screen = document.getElementById('screen')
79 + screen.appendChild(hyperscroll(content))
80 + sbot.get(src, function (err, data) {
81 + if (err) {console.log('could not find message') }
82 + data.value = data
83 + console.log(data)
84 + var root = src
85 + if (data.value.content.root)
86 + root = data.value.content.root
87 + sbot.get(root, function (err, data) {
88 + if (err) { console.log('could not find root')}
5389 data.value = data
54- console.log(data)
55- var root = src
56- if (data.value.content.root)
57- root = data.value.content.root
58- sbot.get(root, function (err, data) {
59- if (err) { console.log('could not find root')}
60- data.value = data
61- data.key = root
62- content.appendChild(render(data))
63- pull(
64- sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
65- pull.drain(function (msg) {
66- console.log(msg)
67- if (msg.value)
68- content.appendChild(render(msg))
69- })
70- )
71- })
90 + data.key = root
91 + content.appendChild(render(data))
92 + pull(
93 + sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
94 + pull.drain(function (msg) {
95 + console.log(msg)
96 + if (msg.value)
97 + content.appendChild(render(msg))
98 + })
99 + )
72100 })
73- }
101 + })
102 +}
74103
75- else if (src == 'about') {
104 +var keyPage = function () {
105 + var screen = document.getElementById('screen')
76106
77- var screen = document.getElementById('screen')
107 + var importKey = h('textarea.import', {placeholder: 'Import a new public/private key', name: 'textarea', style: 'width: 97%; height: 100px;'})
78108
79- var about = require('./about')
80-
81- var content = h('div.content', about)
82-
83- screen.appendChild(hyperscroll(content))
84- }
85-
86- else if (src == 'key') {
87- var screen = document.getElementById('screen')
88-
89- var importKey = h('textarea.import', {placeholder: 'Import a new public/private key', name: 'textarea', style: 'width: 97%; height: 100px;'})
90-
91- var content = h('div.content',
92- h('div.message#key',
93- h('h1', 'Your Key'),
94- h('p', {innerHTML: 'Your public/private key is: <pre><code>' + localStorage[config.caps.shs + '/secret'] + '</code></pre>'},
109 + var content = h('div.content',
110 + h('div.message#key',
111 + h('h1', 'Your Key'),
112 + h('p', {innerHTML: 'Your public/private key is: <pre><code>' + localStorage[config.caps.shs + '/secret'] + '</code></pre>'},
113 + h('button.btn', {onclick: function (e){
114 + localStorage[config.caps.shs +'/secret'] = ''
115 + alert('Your public/private key has been deleted')
116 + e.preventDefault()
117 + location.hash = ""
118 + location.reload()
119 + }}, 'Delete Key')
120 + ),
121 + h('hr'),
122 + h('form',
123 + importKey,
95124 h('button.btn', {onclick: function (e){
96- localStorage[config.caps.shs +'/secret'] = ''
97- alert('Your public/private key has been deleted')
125 + if(importKey.value) {
126 + localStorage[config.caps.shs + '/secret'] = importKey.value.replace(/\s+/g, ' ')
98127 e.preventDefault()
99- location.hash = ""
100- location.reload()
101- }}, 'Delete Key')
102- ),
103- h('hr'),
104- h('form',
105- importKey,
106- h('button.btn', {onclick: function (e){
107- if(importKey.value) {
108- localStorage[config.caps.shs + '/secret'] = importKey.value.replace(/\s+/g, ' ')
109- e.preventDefault()
110- alert('Your public/private key has been updated')
111- }
112- location.hash = ""
113- location.reload()
114- }}, 'Import key'),
115- )
128 + alert('Your public/private key has been updated')
129 + }
130 + location.hash = ""
131 + location.reload()
132 + }}, 'Import key'),
116133 )
117134 )
118-
119- screen.appendChild(hyperscroll(content))
135 + )
120136
121- } else {
122- var content = h('div.content')
123- var screen = document.getElementById('screen')
124- screen.appendChild(hyperscroll(content))
125- function createStream (opts) {
126- return pull(
127- More(sbot.createLogStream, opts),
128- pull.map(function (msg) {
129- return render(msg)
130- })
131- )
132- }
137 + screen.appendChild(hyperscroll(content))
138 +}
133139
134- pull(
135- createStream({old: false, limit: 10}),
136- stream.top(content)
137- )
138140
139- pull(
140- createStream({reverse: true, live: false, limit: 10}),
141- stream.bottom(content)
142- )
141 +function hash () {
142 + return window.location.hash.substring(1)
143 +}
143144
145 +module.exports = function () {
146 + var src = hash()
147 +
148 + if (ref.isFeed(src)) {
149 + userStream(src)
150 + } else if (ref.isMsg(src)) {
151 + msgThread(src)
152 + } else if (src == 'about') {
153 + about()
154 + } else if (src == 'key') {
155 + keyPage()
156 + } else {
157 + logStream()
144158 }
145159 }
146-
147-

Built with git-ssb-web