Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import css from "../css/app.css"
import "./polyfills/closest"
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
import "phoenix_html"

const triggers = document.querySelectorAll('[data-dropdown-trigger]')
Expand Down
9 changes: 8 additions & 1 deletion assets/js/dashboard/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {formatISO} from './date'

let abortController = new AbortController()

function serialize(obj) {
var str = [];
for (var p in obj)
Expand All @@ -9,6 +11,11 @@ function serialize(obj) {
return str.join("&");
}

export function cancelAll() {
abortController.abort()
abortController = new AbortController()
}

export function serializeQuery(query, extraQuery=[]) {
query = Object.assign({}, query, {
date: query.date ? formatISO(query.date) : undefined,
Expand All @@ -22,7 +29,7 @@ export function serializeQuery(query, extraQuery=[]) {

export function get(url, query, ...extraQuery) {
url = url + serializeQuery(query, extraQuery)
return fetch(url)
return fetch(url, {signal: abortController.signal})
.then( response => {
if (!response.ok) { throw response }
return response.json()
Expand Down
2 changes: 2 additions & 0 deletions assets/js/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Countries from './stats/countries'
import Devices from './stats/devices'
import Conversions from './stats/conversions'
import {parseQuery} from './query'
import * as api from './api'

class Stats extends React.Component {
constructor(props) {
Expand All @@ -20,6 +21,7 @@ class Stats extends React.Component {

componentDidUpdate(prevProps) {
if (prevProps.location.search !== this.props.location.search) {
api.cancelAll()
this.setState({query: parseQuery(this.props.location.search, this.props.site)})
}
}
Expand Down
Loading