This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
60 lines (52 loc) · 1.72 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>holochainClient test</title>
<meta charset="UTF-8"/>
</head>
<body>
<form id="form">
<input type="text" id="message"/>
<input type="submit" value="Send" />
</form>
<button id="info">Get info</button>
<button id="close">Close WS connection</button>
<div id="output"></div>
<script type="text/javascript" src="dist/hc-web-client-0.5.2.browser.min.js"></script>
<script type="text/javascript">
const holochainUrl = 'ws://localhost:3000/'
window.holochainClient.connect(holochainUrl).then(({call, close}) => {
document.getElementById('form').addEventListener('submit', e => {
e.preventDefault()
// First, get instance info...
call('info/instances')().then(info => {
const instance = getInstance(info, 'the_dna_hash', 'the_agent_hash')
const zomeName = 'blog'
const functionName = 'create_post'
const params = {
content: document.querySelector('#message').value,
in_reply_to: 'in reply to'
}
const createPost = call(instance, zomeName, functionName)
createPost(params)
})
}).catch(console.log('hcClient error: ', e));
document.getElementById('info').addEventListener('click', e => {
call('info/instances')().then(data => console.log(data))
})
document.getElementById('close').addEventListener('click', e => {
close()
})
})
function getInstance(info, dna, agent) {
const entry = Object.entries(info)
.find(([id, value]) => value.dna === dna && value.agent === agent)
if (entry) {
return entry[1].id
} else {
return null
}
}
</script>
</body>
</html>