Skip to content

Commit bc9c05e

Browse files
committed
fix: polling for hash's block, disable button when haven't written on block yet
1 parent 7eb7905 commit bc9c05e

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

static/root/frontend/js/bebop-app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const BEBOP_OAUTH_RESULT_COOKIE = "bebop_oauth_result";
55
window.API_HOST = "https://explorer.dbhub.org"
66
window.DBID = ""
77
window.HEAD_API = () => `${window.API_HOST}/apiproxy.covenantsql/v2/head/${window.DBID}`
8+
window.SQL_HASH_API = (hash) => `${window.API_HOST}/apiproxy.covenantsql/v1/request/${window.DBID}/${hash}`
89
window.BLOCK_API = (height) => `${window.API_HOST}/apiproxy.covenantsql/v3/count/${window.DBID}/${height}?page=1&size=999`
910

1011
// lowdb
@@ -95,9 +96,7 @@ var BebopApp = new Vue({
9596
console.log(" / / / _ \\ \\ / / _ | '_ \\ / _\` | '_ \\| __\\ \\ // / / /")
9697
console.log("/ /__| (_) \\ V | __| | | | (_| | | | | |__\\ / \\_/ / /___")
9798
console.log("\\____/\\___/ \\_/ \\___|_| |_|\\__,_|_| |_|\\__\\__\\___,_\\____/")
98-
console.log('--- connected')
99-
console.log('')
100-
console.log('--- current lead block for ', DBID)
99+
console.log('--- connected db:', DBID)
101100

102101
fetch(url).then(res => res.json()).then((d) => {
103102
let head = _.get(d, 'data.block', {})

static/root/frontend/js/bebop-comments.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var BebopComments = Vue.component("bebop-comments", {
4747
4848
<div class="avatar-block">
4949
<div class="cqldb comment">
50-
<a target="_blank" :href="comment.requestHash | getCommentSQLRequestHref" v-bind:class="{ disabled: isCommentHashEmpty(comment) }">
50+
<a target="_blank" :href="comment.requestHash | getCommentSQLRequestHref" v-bind:class="{ disabled: !isCommentHashReady(comment) }">
5151
<svg style="transform: translateY(6px);" width="20px" height="20px" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path id="a" d="M0 0h45v45H0z"/></defs><g fill="none" fill-rule="evenodd"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><g mask="url(#b)"><path d="M22.44 2L5 12.08v20.07l17.4 10.1h.06a60.48 60.48 0 0 1-.84-10.59v-1a8.94 8.94 0 1 1 7.85-3.31l.71.45a38.42 38.42 0 0 0 9.72 4.4V12.06L22.44 2zm-8.71 14.19a7.94 7.94 0 0 1 .51-7.32s.06-.09.08 0a14.83 14.83 0 0 0 1.11 3.58c.233.375.497.73.79 1.06a10.49 10.49 0 0 0-2.49 2.68zm17.38-.27a10.49 10.49 0 0 0-2.52-2.55 8 8 0 0 0 .75-1 7.91 7.91 0 0 0 1.1-3.44v-.18c0-.12 0-.07.08 0a7.94 7.94 0 0 1 .59 7.17z" fill="#FFF" fill-rule="nonzero"/></g></g></svg>
5252
CovenantSQL
5353
</a>
@@ -186,6 +186,7 @@ var BebopComments = Vue.component("bebop-comments", {
186186
load: function () {
187187
this.topic = {};
188188
this.topicReady = false;
189+
this.requestHashReady = {};
189190
this.comments = [];
190191
this.commentCount = 0;
191192
this.commentsReady = false;
@@ -200,19 +201,31 @@ var BebopComments = Vue.component("bebop-comments", {
200201
},
201202

202203
// if comment.requestHash is empty, disable the button
203-
isCommentHashEmpty: function (comment) {
204-
return comment.requestHash === ''
204+
isCommentHashReady: function (comment) {
205+
return this.requestHashReady[comment.requestHash] === true
205206
},
206207
getCommentSQLQueries: function () {
207208
// DEPRECATED find possible height by Chenxi 2019-04-24
208-
return
209-
// this.comments.forEach(comment => {
210-
// const timestamp = (new Date(comment.createdAt)).getTime()
211-
// const possibleHeight = this.computeTimeHeight(timestamp)
212-
// console.log('// -- current comment possible height:', possibleHeight)
213-
//
214-
// this.getTimeRelatedBlocks(possibleHeight)
215-
// })
209+
// Add polling to get current requestHash's block by Chenxi 2019-04-25
210+
// set requestHashReady when the block is not emtpy, then stop polling
211+
this.comments.forEach(comment => {
212+
const hash = comment.requestHash
213+
if (hash) {
214+
let interval = setInterval(() => {
215+
let url = window.SQL_HASH_API(hash)
216+
fetch(url).then(res => res.json())
217+
.then(d => {
218+
if (d && d.data) {
219+
clearInterval(interval)
220+
this.requestHashReady[hash] = true
221+
console.log(hash, this.requestHashReady[hash])
222+
}
223+
})
224+
.catch(e => { console.info("get hash's block", e) })
225+
}, 3000)
226+
}
227+
// this.getTimeRelatedBlocks(possibleHeight)
228+
})
216229
},
217230
writeSQL: function (block) {
218231
if (!_.isEmpty(block)) {

0 commit comments

Comments
 (0)