diff --git a/ui/src/layout/ActivityPanel.js b/ui/src/layout/ActivityPanel.js index d950a5938..1c937a60e 100644 --- a/ui/src/layout/ActivityPanel.js +++ b/ui/src/layout/ActivityPanel.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' -import { fetchUtils, useTranslate } from 'react-admin' +import { useTranslate } from 'react-admin' import { Popover, Badge, @@ -68,13 +68,12 @@ const ActivityPanel = () => { const handleMenuOpen = (event) => setAnchorEl(event.currentTarget) const handleMenuClose = () => setAnchorEl(null) - const triggerScan = (full) => () => - fetch(subsonic.url('startScan', null, { fullScan: full })) + const triggerScan = (full) => () => subsonic.startScan({ fullScan: full }) // Get updated status on component mount useEffect(() => { - fetchUtils - .fetchJson(subsonic.url('getScanStatus')) + subsonic + .getScanStatus() .then((resp) => resp.json['subsonic-response']) .then((data) => { if (data.status === 'ok') { diff --git a/ui/src/subsonic/index.js b/ui/src/subsonic/index.js index ca4ac5c7a..176122e21 100644 --- a/ui/src/subsonic/index.js +++ b/ui/src/subsonic/index.js @@ -1,5 +1,5 @@ -import { fetchUtils } from 'react-admin' import { baseUrl } from '../utils' +import { httpClient } from '../dataProvider' const url = (command, id, options) => { const params = new URLSearchParams() @@ -19,36 +19,40 @@ const url = (command, id, options) => { params.append(k, options[k]) }) } - const url = `/rest/${command}?${params.toString()}` - return baseUrl(url) + return `/rest/${command}?${params.toString()}` } 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 options = { ...(record.updatedAt && { _: record.updatedAt }), ...(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 { url, - getCoverArtUrl, scrobble, download, star, unstar, setRating, + startScan, + getScanStatus, + getCoverArtUrl, }