parent
1814f3ee76
commit
88ab1172bc
@ -1,29 +1,25 @@ |
|||||||
import $ from 'jquery' |
import $ from 'jquery' |
||||||
import _ from 'lodash' |
|
||||||
import humps from 'humps' |
import humps from 'humps' |
||||||
import numeral from 'numeral' |
import numeral from 'numeral' |
||||||
import socket from '../socket' |
import socket from '../socket' |
||||||
|
|
||||||
function tryUpdateIndexedStatus (el, indexedRatio = el.dataset.indexedRatio, indexingFinished = false) { |
function tryUpdateIndexedStatus (el, indexedRatio = el.dataset.indexedRatio, indexingFinished = false) { |
||||||
if (indexingFinished) return $("[data-selector='indexed-status']").remove() |
if (indexingFinished) return $("[data-selector='indexed-status']").remove() |
||||||
|
const blocksPercentComplete = numeral(indexedRatio).format('0%') |
||||||
let indexedText |
let indexedText |
||||||
if (parseInt(indexedRatio) === 1.0) { |
if (blocksPercentComplete === '100%') { |
||||||
indexedText = window.localized['Indexing Tokens'] |
indexedText = window.localized['Indexing Tokens'] |
||||||
} else { |
} else { |
||||||
indexedText = `${numeral(indexedRatio).format('0%')} ${window.localized['Blocks Indexed']}` |
indexedText = `${blocksPercentComplete} ${window.localized['Blocks Indexed']}` |
||||||
} |
} |
||||||
if (indexedText !== el.innerHTML) el.innerHTML = indexedText |
if (indexedText !== el.innerHTML) el.innerHTML = indexedText |
||||||
} |
} |
||||||
|
|
||||||
let currentIndexedRatio |
export function updateIndexStatus (msg = {}) { |
||||||
let indexingFinished |
$('[data-indexed-ratio]').each((i, el) => tryUpdateIndexedStatus(el, msg.ratio, msg.finished)) |
||||||
export function updateIndexStatus (msg) { |
|
||||||
currentIndexedRatio = _.get(msg, 'ratio') |
|
||||||
indexingFinished = _.get(msg, 'finished') |
|
||||||
$('[data-indexed-ratio]').each((i, el) => tryUpdateIndexedStatus(el, currentIndexedRatio, indexingFinished)) |
|
||||||
} |
} |
||||||
updateIndexStatus() |
updateIndexStatus() |
||||||
|
|
||||||
export const indexingChannel = socket.channel(`blocks:indexing`) |
const indexingChannel = socket.channel(`blocks:indexing`) |
||||||
indexingChannel.join() |
indexingChannel.join() |
||||||
indexingChannel.on('index_status', (msg) => updateIndexStatus(humps.camelizeKeys(msg))) |
indexingChannel.on('index_status', (msg) => updateIndexStatus(humps.camelizeKeys(msg))) |
||||||
|
Loading…
Reference in new issue