Fix #311 - Avoid updating remote db address if it hasn't changed

This commit is contained in:
Claus Wahlers 2018-02-21 01:51:14 -03:00
parent 476781fd1e
commit 9d1be0d312
3 changed files with 32 additions and 11 deletions

View File

@ -20,6 +20,15 @@ body {
padding: 0.5em; padding: 0.5em;
} }
#output-header > p {
margin: 0;
font-style: italic;
}
#output {
padding-top: 1em;
}
#writerText { #writerText {
padding-top: 0.5em; padding-top: 0.5em;
} }

View File

@ -45,7 +45,10 @@
<input id="readonly" type="checkbox" checked> Read-only <input id="readonly" type="checkbox" checked> Read-only
<br><br> <br><br>
<div id="status">Init</div> <div id="status">Init</div>
<div>
<header id="output-header"></header>
<div id="output"></div> <div id="output"></div>
</div>
<div id="writerText"></div> <div id="writerText"></div>
<script type="text/javascript" src="lib/orbitdb.min.js" charset="utf-8"></script> <script type="text/javascript" src="lib/orbitdb.min.js" charset="utf-8"></script>

View File

@ -5,7 +5,8 @@ const creatures = [
'🐼', '🐰', '🐶', '🐥' '🐼', '🐰', '🐶', '🐥'
] ]
const elm = document.getElementById("output") const outputHeaderElm = document.getElementById("output-header")
const outputElm = document.getElementById("output")
const statusElm = document.getElementById("status") const statusElm = document.getElementById("status")
const dbnameField = document.getElementById("dbname") const dbnameField = document.getElementById("dbname")
const dbAddressField = document.getElementById("dbaddress") const dbAddressField = document.getElementById("dbaddress")
@ -26,6 +27,7 @@ const main = (IPFS, ORBITDB) => {
let count = 0 let count = 0
let interval = Math.floor((Math.random() * 300) + (Math.random() * 2000)) let interval = Math.floor((Math.random() * 300) + (Math.random() * 2000))
let updateInterval let updateInterval
let dbType, dbAddress
// If we're building with Webpack, use the injected IPFS module. // If we're building with Webpack, use the injected IPFS module.
// Otherwise use 'Ipfs' which is exposed by ipfs.min.js // Otherwise use 'Ipfs' which is exposed by ipfs.min.js
@ -123,7 +125,8 @@ const main = (IPFS, ORBITDB) => {
const resetDatabase = async (db) => { const resetDatabase = async (db) => {
writerText.innerHTML = "" writerText.innerHTML = ""
elm.innerHTML = "" outputElm.innerHTML = ""
outputHeaderElm.innerHTML = ""
clearInterval(updateInterval) clearInterval(updateInterval)
@ -238,11 +241,18 @@ const main = (IPFS, ORBITDB) => {
const result = query(db) const result = query(db)
const output = ` if (dbType !== db.type || dbAddress !== db.address) {
<h2>${db.type.toUpperCase()}</h2> dbType = db.type;
<h3 id="remoteAddress">${db.address}</h3> dbAddress = db.address;
<div><i>Copy this address and use the 'Open Remote Database' in another browser to replicate this database between peers.</i></div>
<br> outputHeaderElm.innerHTML = `
<h2>${dbType.toUpperCase()}</h2>
<h3 id="remoteAddress">${dbAddress}</h3>
<p>Copy this address and use the 'Open Remote Database' in another browser to replicate this database between peers.</p>
`
}
outputElm.innerHTML = `
<div><b>Peer ID:</b> ${orbitdb.id}</div> <div><b>Peer ID:</b> ${orbitdb.id}</div>
<div><b>Peers (database/network):</b> ${databasePeers.length} / ${networkPeers.length}</div> <div><b>Peers (database/network):</b> ${databasePeers.length} / ${networkPeers.length}</div>
<div><b>Oplog Size:</b> ${db._replicationInfo.progress} / ${db._replicationInfo.max}</div> <div><b>Oplog Size:</b> ${db._replicationInfo.progress} / ${db._replicationInfo.max}</div>
@ -258,7 +268,6 @@ const main = (IPFS, ORBITDB) => {
</div> </div>
</div> </div>
` `
elm.innerHTML = output
} }
openButton.addEventListener('click', openDatabase) openButton.addEventListener('click', openDatabase)