Skip to content

Commit

Permalink
Refactoring and finishing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aphelionz committed Feb 15, 2017
1 parent 443610e commit f3a5e72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
15 changes: 14 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
</head>
<div class="overlay"></div>
<ipfs-api></ipfs-api>
<ip-app></ip-app>
<ip-app id="app"></ip-app>

<script>
if(window.location.hash) {
document.getElementById('app').key = window.location.hash.substr(1);
}

document.body.addEventListener('file-added', function(e) {
window.location = "/#" + e.detail;
document.getElementById('app').key = window.location.hash.substr(1);
document.getElementById('app').isUploading = false;
document.getElementById('app').hasContent = false;
});
</script>
</body>
</html>
20 changes: 9 additions & 11 deletions src/ip-app/ip-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ <h1>the interplanetary pastebin</h1>
notify: true,
type: Boolean,
value: false
},
key: {
notify: true,
type: String,
observer: "_keyChanged"
}
},

Expand All @@ -65,27 +70,20 @@ <h1>the interplanetary pastebin</h1>
}.bind(this));
},

_keyChanged: function() {
document.body.dispatchEvent(new CustomEvent('get-file', { detail: this.key }));
},

showButton: function() { this.hasContent = true; },

uploadForever: function() {
this.isUploading = true;
document.body.dispatchEvent(new CustomEvent('add-file', {
detail: this.$.paste.value
}));

document.body.addEventListener('file-added', function(e) {
window.location = "/#" + e.detail;
window.location.reload();
}.bind(this))
},

ready: function() {
if(window.location.hash) {
document.body.dispatchEvent(new CustomEvent('get-file', {
detail: window.location.hash.substr(1)
}));
}

setInterval(this._getPeers.bind(this), 10000);
this._getPeers();

Expand Down
9 changes: 7 additions & 2 deletions test/ip-app/ip-app_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@
document.body.addEventListener('add-file', test);
});

test('file added updates hash and reloads page');
test('document with hash dispatches get-file event');
test('key change dispatches get-file event', function(done) {
var element = fixture('basic');
document.body.addEventListener('get-file', function() {
done();
});
element.key = "lalalal";
});
});
</script>
</body>
Expand Down

0 comments on commit f3a5e72

Please sign in to comment.