Refactor how we recognize routes

Co-authored-by: Stamates <stamates@hotmail.com>
pull/333/head
jimmay5469 7 years ago
parent 836ee81b2f
commit a00ab92179
  1. 3
      apps/explorer_web/assets/js/lib/from_now.js
  2. 23
      apps/explorer_web/assets/js/pages/address.js
  3. 19
      apps/explorer_web/assets/js/router.js
  4. 3
      apps/explorer_web/assets/js/socket.js
  5. 13
      apps/explorer_web/assets/package-lock.json
  6. 1
      apps/explorer_web/assets/package.json
  7. 5
      apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex
  8. 3
      apps/explorer_web/lib/explorer_web/templates/layout/app.html.eex

@ -1,7 +1,8 @@
import $ from 'jquery' import $ from 'jquery'
import moment from 'moment' import moment from 'moment'
import router from '../router'
moment.locale(window.locale) moment.locale(router.locale)
moment.relativeTimeThreshold('M', 12) moment.relativeTimeThreshold('M', 12)
moment.relativeTimeThreshold('d', 30) moment.relativeTimeThreshold('d', 30)

@ -1,16 +1,15 @@
import $ from 'jquery' import $ from 'jquery'
import URI from 'urijs'
import humps from 'humps' import humps from 'humps'
import socket from '../socket' import socket from '../socket'
import router from '../router'
if (window.page === 'address') { router.when('/addresses/:addressHash').then(({ addressHash, blockNumber, filter }) => {
const channel = socket.channel(`addresses:${window.addressHash}`, {}) const channel = socket.channel(`addresses:${addressHash}`, {})
channel.join() channel.join()
.receive('ok', resp => { console.log('Joined successfully', `addresses:${window.addressHash}`, resp) }) .receive('ok', resp => { console.log('Joined successfully', `addresses:${addressHash}`, resp) })
.receive('error', resp => { console.log('Unable to join', `addresses:${window.addressHash}`, resp) }) .receive('error', resp => { console.log('Unable to join', `addresses:${addressHash}`, resp) })
const currentLocation = URI(window.location) if (!blockNumber) {
if(!currentLocation.hasQuery('block_number')) {
const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]') const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]')
if ($emptyTransactionsList) { if ($emptyTransactionsList) {
channel.on('transaction', () => { channel.on('transaction', () => {
@ -27,15 +26,15 @@ if (window.page === 'address') {
transactionHtml transactionHtml
} = humps.camelizeKeys(msg) } = humps.camelizeKeys(msg)
if(currentLocation.query(true).filter === 'to' && toAddressHash !== window.addressHash) { if (filter === 'to' && toAddressHash !== addressHash) {
return; return
} }
if(currentLocation.query(true).filter === 'from' && fromAddressHash !== window.addressHash) { if (filter === 'from' && fromAddressHash !== addressHash) {
return; return
} }
$transactionsList.prepend(transactionHtml) $transactionsList.prepend(transactionHtml)
}) })
} }
} }
} })

@ -0,0 +1,19 @@
import Path from 'path-parser'
import URI from 'urijs'
import humps from 'humps'
const { locale } = Path.createPath('/:locale').partialTest(window.location.pathname)
export default {
locale,
when (pattern) {
return new Promise((resolve) => {
const match = Path.createPath(`/:locale${pattern}`).partialTest(window.location.pathname)
if (match) {
const routeParams = humps.camelizeKeys(match)
const queryParams = humps.camelizeKeys(URI(window.location).query(true))
resolve(Object.assign({}, queryParams, routeParams))
}
})
}
}

@ -1,6 +1,7 @@
import {Socket} from 'phoenix' import {Socket} from 'phoenix'
import router from './router'
const socket = new Socket('/socket', {params: {locale: window.locale}}) const socket = new Socket('/socket', {params: {locale: router.locale}})
socket.connect() socket.connect()
export default socket export default socket

@ -5642,6 +5642,14 @@
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
"dev": true "dev": true
}, },
"path-parser": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/path-parser/-/path-parser-4.1.1.tgz",
"integrity": "sha512-Wa8H3oVxnt8U5qODVpwg/fZgxFgJADywGqyAsMB6NkiLoc+Up+ryZ9r9/wyL026VDy+GCmF3d5BhfPFFKllOlQ==",
"requires": {
"search-params": "2.1.3"
}
},
"path-type": { "path-type": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz",
@ -7187,6 +7195,11 @@
} }
} }
}, },
"search-params": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/search-params/-/search-params-2.1.3.tgz",
"integrity": "sha512-hHxU9ZGWpZ/lrFBIHndSnQae2in7ra+m+tBSoeAahSWDDgOgpZqs4bfaTZpljgNgAgTbjiQoJtZW6FKSsfEcDA=="
},
"select": { "select": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",

@ -26,6 +26,7 @@
"jquery": "^3.3.1", "jquery": "^3.3.1",
"moment": "^2.22.1", "moment": "^2.22.1",
"numeral": "^2.0.6", "numeral": "^2.0.6",
"path-parser": "^4.1.1",
"phoenix": "file:../../../deps/phoenix", "phoenix": "file:../../../deps/phoenix",
"phoenix_html": "file:../../../deps/phoenix_html", "phoenix_html": "file:../../../deps/phoenix_html",
"popper.js": "^1.14.3", "popper.js": "^1.14.3",

@ -1,8 +1,3 @@
<script>
window.page = 'address'
window.addressHash = '<%= @address %>'
</script>
<section> <section>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-md-2 col-lg-1 order-last order-sm-first"> <div class="col-md-2 col-lg-1 order-last order-sm-first">

@ -6,9 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= gettext "POA Network Explorer" %></title> <title><%= gettext "POA Network Explorer" %></title>
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>"> <link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
<script>
window.locale = '<%= @conn.assigns.locale %>'
</script>
</head> </head>
<body> <body>

Loading…
Cancel
Save