diff --git a/interface/src/api/ap.ts b/interface/src/api/ap.ts index a314227c2..7ffda7668 100644 --- a/interface/src/api/ap.ts +++ b/interface/src/api/ap.ts @@ -1,14 +1,7 @@ -import { AXIOS, alovaInstance } from './endpoints'; -import type { AxiosPromise } from 'axios'; +import { alovaInstance } from './endpoints'; import type { APSettings, APStatus } from 'types'; -export const readAPStatus = () => alovaInstance.Get('/apStatus'); - -// TODO change APSettings AXIOS to Alova -export function readAPSettings(): AxiosPromise { - return AXIOS.get('/apSettings'); -} -export function updateAPSettings(apSettings: APSettings): AxiosPromise { - return AXIOS.post('/apSettings', apSettings); -} +export const readAPStatus = () => alovaInstance.Get('/rest/apStatus'); +export const readAPSettings = () => alovaInstance.Get('/rest/apSettings'); +export const updateAPSettings = (data: APSettings) => alovaInstance.Post('/rest/apSettings', data); diff --git a/interface/src/api/endpoints.ts b/interface/src/api/endpoints.ts index cd1b4b574..cf2fbe799 100644 --- a/interface/src/api/endpoints.ts +++ b/interface/src/api/endpoints.ts @@ -18,6 +18,14 @@ export const EVENT_SOURCE_ROOT = 'http://' + host + '/es/'; export const alovaInstance = createAlova({ statesHook: ReactHook, timeout: 3000, + localCache: { + GET: { + mode: 'placeholder', + // expire: 60 * 10 * 1000 + // see https://alova.js.org/learning/response-cache/#cache-replaceholder-mode + expire: 2000 + } + }, requestAdapter: xhrRequestAdapter(), beforeRequest(method) { if (localStorage.getItem(ACCESS_TOKEN)) { diff --git a/interface/src/api/mqtt.ts b/interface/src/api/mqtt.ts index a2668193b..d75dc4134 100644 --- a/interface/src/api/mqtt.ts +++ b/interface/src/api/mqtt.ts @@ -1,16 +1,6 @@ -import { AXIOS } from './endpoints'; -import type { AxiosPromise } from 'axios'; +import { alovaInstance } from './endpoints'; import type { MqttSettings, MqttStatus } from 'types'; -// TODO move to alova -export function readMqttStatus(): AxiosPromise { - return AXIOS.get('/mqttStatus'); -} - -export function readMqttSettings(): AxiosPromise { - return AXIOS.get('/mqttSettings'); -} - -export function updateMqttSettings(mqttSettings: MqttSettings): AxiosPromise { - return AXIOS.post('/mqttSettings', mqttSettings); -} +export const readMqttStatus = () => alovaInstance.Get('/rest/mqttStatus'); +export const readMqttSettings = () => alovaInstance.Get('/rest/mqttSettings'); +export const updateMqttSettings = (data: MqttSettings) => alovaInstance.Post('/rest/mqttSettings', data); diff --git a/interface/src/api/network.ts b/interface/src/api/network.ts index 2c50bfdf2..03bb7ead6 100644 --- a/interface/src/api/network.ts +++ b/interface/src/api/network.ts @@ -1,25 +1,11 @@ -import { AXIOS } from './endpoints'; -import type { AxiosPromise } from 'axios'; +import { alovaInstance } from './endpoints'; import type { WiFiNetworkList, NetworkSettings, NetworkStatus } from 'types'; -// TODO move to alova -export function readNetworkStatus(): AxiosPromise { - return AXIOS.get('/networkStatus'); -} - -export function scanNetworks(): AxiosPromise { - return AXIOS.get('/scanNetworks'); -} - -export function listNetworks(): AxiosPromise { - return AXIOS.get('/listNetworks'); -} - -export function readNetworkSettings(): AxiosPromise { - return AXIOS.get('/networkSettings'); -} - -export function updateNetworkSettings(wifiSettings: NetworkSettings): AxiosPromise { - return AXIOS.post('/networkSettings', wifiSettings); -} +export const readNetworkStatus = () => alovaInstance.Get('/rest/networkStatus'); +export const scanNetworks = () => alovaInstance.Get('/rest/scanNetworks'); +export const listNetworks = () => alovaInstance.Get('/rest/listNetworks'); +export const readNetworkSettings = () => + alovaInstance.Get('/rest/networkSettings', { name: 'networkSettings' }); +export const updateNetworkSettings = (wifiSettings: NetworkSettings) => + alovaInstance.Post('/rest/networkSettings', wifiSettings); diff --git a/interface/src/api/ntp.ts b/interface/src/api/ntp.ts index c0cd94283..74da189d1 100644 --- a/interface/src/api/ntp.ts +++ b/interface/src/api/ntp.ts @@ -1,20 +1,11 @@ -import { AXIOS } from './endpoints'; -import type { AxiosPromise } from 'axios'; +import { alovaInstance } from './endpoints'; import type { NTPSettings, NTPStatus, Time } from 'types'; -// TODO move to Alova -export function readNTPStatus(): AxiosPromise { - return AXIOS.get('/ntpStatus'); -} +export const readNTPStatus = () => alovaInstance.Get('/rest/ntpStatus'); +export const readNTPSettings = () => + alovaInstance.Get('/rest/ntpSettings', { + name: 'ntpSettings' + }); +export const updateNTPSettings = (data: NTPSettings) => alovaInstance.Post('/rest/ntpSettings', data); -export function readNTPSettings(): AxiosPromise { - return AXIOS.get('/ntpSettings'); -} - -export function updateNTPSettings(ntpSettings: NTPSettings): AxiosPromise { - return AXIOS.post('/ntpSettings', ntpSettings); -} - -export function updateTime(time: Time): AxiosPromise