Fix console errors when using shared links

This commit is contained in:
Uku Taht 2021-04-07 11:06:33 +03:00
parent 58cff47b6f
commit 28d293e2d2
3 changed files with 5 additions and 6 deletions

View File

@ -47,7 +47,7 @@ export function serializeQuery(query, extraQuery=[]) {
return '?' + serialize(queryObj)
}
export function get(url, query, ...extraQuery) {
export function get(url, query={}, ...extraQuery) {
const headers = SHARED_LINK_AUTH ? {'X-Shared-Link-Auth': SHARED_LINK_AUTH} : {}
url = url + serializeQuery(query, extraQuery)
return fetch(url, {signal: abortController.signal, headers: headers})

View File

@ -27,6 +27,8 @@ export default class SiteSwitcher extends React.Component {
}
populateSites() {
if (!this.props.loggedIn) return;
fetch('/api/sites')
.then( response => {
if (!response.ok) { throw response }

View File

@ -1,4 +1,5 @@
import React from 'react';
import * as api from '../api'
import { Link } from 'react-router-dom'
import { countFilters } from '../query';
@ -14,11 +15,7 @@ export default class CurrentVisitors extends React.Component {
}
updateCount() {
return fetch(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`)
.then( response => {
if (!response.ok) { throw response }
return response.json()
})
return api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`)
.then((res) => this.setState({currentVisitors: res}))
}