forked from arj03/ssb-browser-example
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-app.js
75 lines (67 loc) · 2.07 KB
/
create-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-FileCopyrightText: 2021 Anders Rune Jensen <[email protected]>
//
// SPDX-License-Identifier: LGPL-3.0-only
module.exports = function () {
const pull = require('pull-stream')
const ssbSingleton = require('ssb-browser-core/ssb-singleton')
return {
el: '#app',
template: `
<div id="app">
<h2>Create a new app</h2>
<div>
<input id="title" type="text" v-model="title" placeholder="app title">
<button class="link" v-on:click="test">Test</button>
<button class="link" v-on:click="create">Create</button>
</div>
<br>
<textarea class="source" v-model="source"></textarea>
<div id="testapp"></div>
</div>`,
data: function() {
return {
title: '',
source: ''
}
},
methods: {
test: function() {
const fixedSource = this.source.replace('id="app"', 'id="testapp"')
let code = new Function('pull', 'ssbSingleton', fixedSource)
new Vue(code(pull, ssbSingleton)).$mount('#testapp')
// scroll down to app
window.scrollTo(0, document.body.scrollHeight)
},
create: function() {
ssbSingleton.getSimpleSSBEventually(
(err, SSB) => {
SSB.metafeeds.findOrCreate((err, metafeed) => {
const details = {
feedpurpose: '8K/applications',
feedformat: 'classic',
}
SSB.metafeeds.findOrCreate(
metafeed,
(f) => f.feedpurpose === details.feedpurpose,
details,
(err, appFeed) => {
SSB.db.publishAs(appFeed.keys, {
type: '8K/application',
title: this.title,
source: this.source
}, (err, msg) => {
if (err) console.log(err)
else alert("App created!")
})
}
)
})
}
)
},
created: function () {
document.title = '8K - create app'
}
}
}
}