Always use `httpClient` to call APIs
This commit is contained in:
parent
8383527aab
commit
5f6f74ff2d
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { fetchUtils, useTranslate } from 'react-admin'
|
import { useTranslate } from 'react-admin'
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
Badge,
|
Badge,
|
||||||
|
@ -68,13 +68,12 @@ const ActivityPanel = () => {
|
||||||
|
|
||||||
const handleMenuOpen = (event) => setAnchorEl(event.currentTarget)
|
const handleMenuOpen = (event) => setAnchorEl(event.currentTarget)
|
||||||
const handleMenuClose = () => setAnchorEl(null)
|
const handleMenuClose = () => setAnchorEl(null)
|
||||||
const triggerScan = (full) => () =>
|
const triggerScan = (full) => () => subsonic.startScan({ fullScan: full })
|
||||||
fetch(subsonic.url('startScan', null, { fullScan: full }))
|
|
||||||
|
|
||||||
// Get updated status on component mount
|
// Get updated status on component mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUtils
|
subsonic
|
||||||
.fetchJson(subsonic.url('getScanStatus'))
|
.getScanStatus()
|
||||||
.then((resp) => resp.json['subsonic-response'])
|
.then((resp) => resp.json['subsonic-response'])
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.status === 'ok') {
|
if (data.status === 'ok') {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { fetchUtils } from 'react-admin'
|
|
||||||
import { baseUrl } from '../utils'
|
import { baseUrl } from '../utils'
|
||||||
|
import { httpClient } from '../dataProvider'
|
||||||
|
|
||||||
const url = (command, id, options) => {
|
const url = (command, id, options) => {
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
|
@ -19,36 +19,40 @@ const url = (command, id, options) => {
|
||||||
params.append(k, options[k])
|
params.append(k, options[k])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const url = `/rest/${command}?${params.toString()}`
|
return `/rest/${command}?${params.toString()}`
|
||||||
return baseUrl(url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrobble = (id, submit) =>
|
const scrobble = (id, submit) =>
|
||||||
fetchUtils.fetchJson(url('scrobble', id, { submission: submit }))
|
httpClient(url('scrobble', id, { submission: submit }))
|
||||||
|
|
||||||
const star = (id) => fetchUtils.fetchJson(url('star', id))
|
const star = (id) => httpClient(url('star', id))
|
||||||
|
|
||||||
const unstar = (id) => fetchUtils.fetchJson(url('unstar', id))
|
const unstar = (id) => httpClient(url('unstar', id))
|
||||||
|
|
||||||
const download = (id) => (window.location.href = url('download', id))
|
const setRating = (id, rating) => httpClient(url('setRating', id, { rating }))
|
||||||
|
|
||||||
|
const download = (id) => (window.location.href = baseUrl(url('download', id)))
|
||||||
|
|
||||||
|
const startScan = (options) => httpClient(url('startScan', null, options))
|
||||||
|
|
||||||
|
const getScanStatus = () => httpClient(url('getScanStatus'))
|
||||||
|
|
||||||
const getCoverArtUrl = (record, size) => {
|
const getCoverArtUrl = (record, size) => {
|
||||||
const options = {
|
const options = {
|
||||||
...(record.updatedAt && { _: record.updatedAt }),
|
...(record.updatedAt && { _: record.updatedAt }),
|
||||||
...(size && { size }),
|
...(size && { size }),
|
||||||
}
|
}
|
||||||
return url('getCoverArt', record.coverArtId || 'not_found', options)
|
return baseUrl(url('getCoverArt', record.coverArtId || 'not_found', options))
|
||||||
}
|
}
|
||||||
|
|
||||||
const setRating = (id, rating) =>
|
|
||||||
fetchUtils.fetchJson(url('setRating', id, { rating }))
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
url,
|
url,
|
||||||
getCoverArtUrl,
|
|
||||||
scrobble,
|
scrobble,
|
||||||
download,
|
download,
|
||||||
star,
|
star,
|
||||||
unstar,
|
unstar,
|
||||||
setRating,
|
setRating,
|
||||||
|
startScan,
|
||||||
|
getScanStatus,
|
||||||
|
getCoverArtUrl,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue