Alova 3 now working

This commit is contained in:
proddy
2024-08-10 11:39:31 +02:00
parent bb98042957
commit a718f8ed0d
31 changed files with 117 additions and 409 deletions

View File

@@ -65,8 +65,7 @@ export const readDeviceEntities = (id: number) =>
alovaInstance.Get<DeviceEntity[]>(`/rest/deviceEntities`, {
params: { id },
responseType: 'arraybuffer',
// transform(data) { // TODO alova 3
transformData(data) {
transform(data) {
return (data as DeviceEntity[]).map((de: DeviceEntity) => ({
...de,
o_m: de.m,
@@ -89,8 +88,7 @@ export const writeDeviceName = (data: { id: number; name: string }) =>
// SettingsScheduler
export const readSchedule = () =>
alovaInstance.Get<ScheduleItem[]>('/rest/schedule', {
// transform(data) { // TODO alova 3
transformData(data) {
transform(data) {
return (data as Schedule).schedule.map((si: ScheduleItem) => ({
...si,
o_id: si.id,
@@ -110,8 +108,7 @@ export const writeSchedule = (data: Schedule) =>
// Modules
export const readModules = () =>
alovaInstance.Get<ModuleItem[]>('/rest/modules', {
// transform(data) { // TODO alova 3
transformData(data) {
transform(data) {
return (data as Modules).modules.map((mi: ModuleItem) => ({
...mi,
o_enabled: mi.enabled,
@@ -128,8 +125,7 @@ export const writeModules = (data: {
// SettingsEntities
export const readCustomEntities = () =>
alovaInstance.Get<EntityItem[]>('/rest/customEntities', {
// transform(data) { // TODO alova 3
transformData(data) {
transform(data) {
return (data as Entities).entities.map((ei: EntityItem) => ({
...ei,
o_id: ei.id,

View File

@@ -1,4 +1,4 @@
import { xhrRequestAdapter } from '@alova/adapter-xhr';
import { type AlovaXHRResponse, xhrRequestAdapter } from '@alova/adapter-xhr';
import { createAlova } from 'alova';
import ReactHook from 'alova/react';
@@ -8,10 +8,13 @@ export const ACCESS_TOKEN = 'access_token';
export const alovaInstance = createAlova({
statesHook: ReactHook,
timeout: 3000, // 3 seconds but throwing a timeout error
localCache: null,
// TODO Alova v3 code...
// cacheFor: null,
timeout: 3000, // 3 seconds before throwing a timeout error
cacheFor: {
GET: {
mode: 'memory',
expire: 60 * 10 * 1000 // 60 seconds in cache
}
},
requestAdapter: xhrRequestAdapter(),
beforeRequest(method) {
if (localStorage.getItem(ACCESS_TOKEN)) {
@@ -21,7 +24,7 @@ export const alovaInstance = createAlova({
},
responded: {
onSuccess: async (response) => {
onSuccess: async (response: AlovaXHRResponse) => {
// if (response.status === 202) {
// throw new Error('Wait'); // wifi scan in progress
// } else

View File

@@ -24,29 +24,15 @@ export const fetchLog = () => alovaInstance.Post('/rest/fetchLog');
export const fetchLogES = () => alovaInstance.Get('/es/log');
// Get versions from github
// Alova 3 code...
// export const getStableVersion = () =>
// alovaInstanceGH.Get('latest', {
// transform(response: { data: { name: string } }) {
// return response.data.name.substring(1);
// }
// });
// export const getDevVersion = () =>
// alovaInstanceGH.Get('tags/latest', {
// transform(response: { data: { name: string } }) {
// return response.data.name.split(/\s+/).splice(-1)[0].substring(1);
// }
// });
export const getStableVersion = () =>
alovaInstanceGH.Get('latest', {
transformData(response: { data: { name: string } }) {
transform(response: { data: { name: string } }) {
return response.data.name.substring(1);
}
});
export const getDevVersion = () =>
alovaInstanceGH.Get('tags/latest', {
transformData(response: { data: { name: string } }) {
transform(response: { data: { name: string } }) {
return response.data.name.split(/\s+/).splice(-1)[0].substring(1);
}
});