mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
Alova 3 now working
This commit is contained in:
@@ -17,8 +17,7 @@ import {
|
||||
Typography
|
||||
} from '@mui/material';
|
||||
|
||||
// import { useRequest } from 'alova/client' // TODO replace when Alova 3 is released
|
||||
import { useRequest } from 'alova';
|
||||
import { useRequest } from 'alova/client';
|
||||
import { SectionContent, useLayoutTitle } from 'components';
|
||||
import { useI18nContext } from 'i18n/i18n-react';
|
||||
|
||||
@@ -29,44 +28,23 @@ const Help = () => {
|
||||
const { LL } = useI18nContext();
|
||||
useLayoutTitle(LL.HELP_OF(''));
|
||||
|
||||
const { send: getAPI, onSuccess: onGetAPI } = useRequest(
|
||||
(data: APIcall) => API(data),
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
);
|
||||
onGetAPI((event) => {
|
||||
const { send: getAPI } = useRequest((data: APIcall) => API(data), {
|
||||
immediate: false
|
||||
}).onSuccess((event) => {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(event.data, null, 2)], {
|
||||
type: 'text/plain'
|
||||
})
|
||||
);
|
||||
|
||||
anchor.download =
|
||||
'emsesp_' + event.sendArgs[0].device + '_' + event.sendArgs[0].entity + '.txt';
|
||||
'emsesp_' + event.args[0].device + '_' + event.args[0].entity + '.txt';
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(anchor.href);
|
||||
toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
});
|
||||
|
||||
// Alova 3 code...
|
||||
// const { send: getAPI } = useRequest((data: APIcall) => API(data), {
|
||||
// immediate: false
|
||||
// }).onSuccess((event) => {
|
||||
// const anchor = document.createElement('a');
|
||||
// anchor.href = URL.createObjectURL(
|
||||
// new Blob([JSON.stringify(event.data, null, 2)], {
|
||||
// type: 'text/plain'
|
||||
// })
|
||||
// );
|
||||
//
|
||||
// anchor.download =
|
||||
// 'emsesp_' + event.args[0].device + '_' + event.args[0].entity + '.txt';
|
||||
// anchor.click();
|
||||
// URL.revokeObjectURL(anchor.href);
|
||||
// toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
// });
|
||||
|
||||
const callAPI = async (device: string, entity: string) => {
|
||||
await getAPI({ device, entity, id: 0 }).catch((error: Error) => {
|
||||
toast.error(error.message);
|
||||
|
||||
Reference in New Issue
Block a user