|
|
@ -7,9 +7,9 @@ import { updateAllAges } from '../lib/from_now' |
|
|
|
import { initRedux, prependWithClingBottom } from '../utils' |
|
|
|
import { initRedux, prependWithClingBottom } from '../utils' |
|
|
|
|
|
|
|
|
|
|
|
export const initialState = { |
|
|
|
export const initialState = { |
|
|
|
|
|
|
|
blockNumbers: [], |
|
|
|
beyondPageOne: null, |
|
|
|
beyondPageOne: null, |
|
|
|
channelDisconnected: false, |
|
|
|
channelDisconnected: false, |
|
|
|
currentBlockNumber: null, |
|
|
|
|
|
|
|
newBlock: null, |
|
|
|
newBlock: null, |
|
|
|
replaceBlock: null, |
|
|
|
replaceBlock: null, |
|
|
|
skippedBlockNumbers: [] |
|
|
|
skippedBlockNumbers: [] |
|
|
@ -18,13 +18,9 @@ export const initialState = { |
|
|
|
export function reducer (state = initialState, action) { |
|
|
|
export function reducer (state = initialState, action) { |
|
|
|
switch (action.type) { |
|
|
|
switch (action.type) { |
|
|
|
case 'PAGE_LOAD': { |
|
|
|
case 'PAGE_LOAD': { |
|
|
|
let blockNumber = parseInt(state.currentBlockNumber) |
|
|
|
|
|
|
|
if (!action.beyondPageOne) { |
|
|
|
|
|
|
|
blockNumber = parseInt(action.highestBlockNumber) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
beyondPageOne: action.beyondPageOne, |
|
|
|
beyondPageOne: action.beyondPageOne, |
|
|
|
currentBlockNumber: blockNumber |
|
|
|
blockNumbers: action.blockNumbers |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
case 'CHANNEL_DISCONNECTED': { |
|
|
|
case 'CHANNEL_DISCONNECTED': { |
|
|
@ -35,23 +31,29 @@ export function reducer (state = initialState, action) { |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
|
let skippedBlockNumbers = state.skippedBlockNumbers.slice(0) |
|
|
|
|
|
|
|
let replaceBlock = null |
|
|
|
|
|
|
|
const blockNumber = parseInt(action.msg.blockNumber) |
|
|
|
const blockNumber = parseInt(action.msg.blockNumber) |
|
|
|
if (blockNumber > state.currentBlockNumber + 1) { |
|
|
|
if (_.includes(state.blockNumbers, blockNumber)) { |
|
|
|
for (let i = state.currentBlockNumber + 1; i < action.msg.blockNumber; i++) { |
|
|
|
return Object.assign({}, state, { |
|
|
|
skippedBlockNumbers.push(i) |
|
|
|
newBlock: action.msg.blockHtml, |
|
|
|
|
|
|
|
replaceBlock: blockNumber, |
|
|
|
|
|
|
|
skippedBlockNumbers: _.without(state.skippedBlockNumbers, blockNumber) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else if (blockNumber < _.last(state.blockNumbers)){ |
|
|
|
|
|
|
|
return state |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
let skippedBlockNumbers = state.skippedBlockNumbers.slice(0) |
|
|
|
|
|
|
|
if (blockNumber > state.blockNumbers[0] + 1) { |
|
|
|
|
|
|
|
for (let i = state.blockNumbers[0] + 1; i < blockNumber; i++) { |
|
|
|
|
|
|
|
skippedBlockNumbers.push(i) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (_.indexOf(skippedBlockNumbers, blockNumber) != -1) { |
|
|
|
return Object.assign({}, state, { |
|
|
|
skippedBlockNumbers = _.without(skippedBlockNumbers, blockNumber) |
|
|
|
blockNumbers: _.chain([blockNumber]).union(skippedBlockNumbers, state.blockNumbers).orderBy([],['desc']).value(), |
|
|
|
replaceBlock = blockNumber |
|
|
|
newBlock: action.msg.blockHtml, |
|
|
|
|
|
|
|
replaceBlock: null, |
|
|
|
|
|
|
|
skippedBlockNumbers |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
return Object.assign({}, state, { |
|
|
|
|
|
|
|
currentBlockNumber: blockNumber > state.currentBlockNumber ? blockNumber : state.currentBlockNumber, |
|
|
|
|
|
|
|
newBlock: action.msg.blockHtml, |
|
|
|
|
|
|
|
replaceBlock, |
|
|
|
|
|
|
|
skippedBlockNumbers |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
return state |
|
|
|
return state |
|
|
@ -65,7 +67,7 @@ if ($blockListPage.length) { |
|
|
|
const state = store.dispatch({ |
|
|
|
const state = store.dispatch({ |
|
|
|
type: 'PAGE_LOAD', |
|
|
|
type: 'PAGE_LOAD', |
|
|
|
beyondPageOne: !!humps.camelizeKeys(URI(window.location).query(true)).blockNumber, |
|
|
|
beyondPageOne: !!humps.camelizeKeys(URI(window.location).query(true)).blockNumber, |
|
|
|
highestBlockNumber: $('[data-selector="block-number"]').filter(':first').text() |
|
|
|
blockNumbers: $('[data-selector="block-number"]').map((index, el) => parseInt(el.innerText)).toArray() |
|
|
|
}) |
|
|
|
}) |
|
|
|
if (!state.beyondPageOne) { |
|
|
|
if (!state.beyondPageOne) { |
|
|
|
const blocksChannel = socket.channel(`blocks:new_block`, {}) |
|
|
|
const blocksChannel = socket.channel(`blocks:new_block`, {}) |
|
|
@ -81,20 +83,18 @@ if ($blockListPage.length) { |
|
|
|
const $blocksList = $('[data-selector="blocks-list"]') |
|
|
|
const $blocksList = $('[data-selector="blocks-list"]') |
|
|
|
|
|
|
|
|
|
|
|
if (state.channelDisconnected) $channelDisconnected.show() |
|
|
|
if (state.channelDisconnected) $channelDisconnected.show() |
|
|
|
if (oldState.newBlock !== state.newBlock) { |
|
|
|
if (oldState.newBlock !== state.newBlock || (state.replaceBlock && oldState.replaceBlock !== state.replaceBlock)) { |
|
|
|
if (oldState.skippedBlockNumbers !== state.skippedBlockNumbers) { |
|
|
|
if (state.replaceBlock && oldState.replaceBlock !== state.replaceBlock) { |
|
|
|
const newSkippedBlockNumbers = _.difference(state.skippedBlockNumbers, oldState.skippedBlockNumbers) |
|
|
|
const $replaceBlock = $(`[data-block-number="${state.replaceBlock}"]`) |
|
|
|
if (state.replaceBlock) { |
|
|
|
$replaceBlock.addClass('shrink-out') |
|
|
|
const $placeHolder = $(`[data-selector="place-holder"][data-block-number="${state.replaceBlock}"] div.tile`) |
|
|
|
setTimeout(() => $replaceBlock.replaceWith(state.newBlock), 400) |
|
|
|
$placeHolder.addClass('shrink-out') |
|
|
|
} else { |
|
|
|
setTimeout(() => $placeHolder.replaceWith(state.newBlock), 400) |
|
|
|
if (oldState.skippedBlockNumbers !== state.skippedBlockNumbers) { |
|
|
|
} else { |
|
|
|
const newSkippedBlockNumbers = _.difference(state.skippedBlockNumbers, oldState.skippedBlockNumbers) |
|
|
|
_.map(newSkippedBlockNumbers, (skippedBlockNumber) => { |
|
|
|
_.map(newSkippedBlockNumbers, (skippedBlockNumber) => { |
|
|
|
prependWithClingBottom($blocksList, placeHolderBlock(skippedBlockNumber)) |
|
|
|
prependWithClingBottom($blocksList, placeHolderBlock(skippedBlockNumber)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
prependWithClingBottom($blocksList, state.newBlock) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
prependWithClingBottom($blocksList, state.newBlock) |
|
|
|
prependWithClingBottom($blocksList, state.newBlock) |
|
|
|
} |
|
|
|
} |
|
|
|
updateAllAges() |
|
|
|
updateAllAges() |
|
|
|