default Alova v2

This commit is contained in:
proddy
2024-08-10 10:22:14 +02:00
parent efa9718081
commit bb98042957
38 changed files with 574 additions and 287 deletions

View File

@@ -17,9 +17,8 @@ import {
Typography
} from '@mui/material';
import { readSystemStatus } from 'api/system';
import { useRequest } from 'alova/client';
// import { useRequest } from 'alova/client' // TODO replace when Alova 3 is released
import { useRequest } from 'alova';
import { SectionContent, useLayoutTitle } from 'components';
import { useI18nContext } from 'i18n/i18n-react';
@@ -30,24 +29,43 @@ const Help = () => {
const { LL } = useI18nContext();
useLayoutTitle(LL.HELP_OF(''));
const { send: getAPI } = useRequest((data: APIcall) => API(data), {
immediate: false
}).onSuccess((event) => {
const { send: getAPI, onSuccess: onGetAPI } = useRequest(
(data: APIcall) => API(data),
{
immediate: false
}
);
onGetAPI((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';
'emsesp_' + event.sendArgs[0].device + '_' + event.sendArgs[0].entity + '.txt';
anchor.click();
URL.revokeObjectURL(anchor.href);
toast.info(LL.DOWNLOAD_SUCCESSFUL());
});
const { data, loading } = useRequest(readSystemStatus);
// 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) => {
@@ -55,15 +73,8 @@ const Help = () => {
});
};
// TODO remove debug testing useRequest preact hook
console.log('loading: ' + loading + ' data2: ' + data);
if (loading) {
return <div>Loading...</div>;
}
return (
<>
<div>version is {data.emsesp_version}</div>
<SectionContent>
<List sx={{ borderRadius: 3, border: '2px solid grey' }}>
<ListItem>