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

@@ -25,7 +25,8 @@ import {
import * as NetworkApi from 'api/network';
import * as SystemApi from 'api/system';
import { updateState, useRequest } from 'alova/client';
import { updateState, useRequest } from 'alova';
// import { updateState, useRequest } from 'alova/client'; // TODO replace when Alova 3 is released
import type { ValidateFieldsError } from 'async-validator';
import {
BlockFormControlLabel,

View File

@@ -5,7 +5,8 @@ import { Button } from '@mui/material';
import * as NetworkApi from 'api/network';
import { updateState, useRequest } from 'alova/client';
// import { updateState, useRequest } from 'alova/client'; // TODO replace when Alova 3 is released
import { updateState, useRequest } from 'alova';
import { ButtonRow, FormLoader, SectionContent } from 'components';
import { useI18nContext } from 'i18n/i18n-react';
@@ -20,22 +21,18 @@ const WiFiNetworkScanner = () => {
const [errorMessage, setErrorMessage] = useState<string>();
// is called on page load to start network scan
const { send: scanNetworks } = useRequest(NetworkApi.scanNetworks).onComplete(
() => {
pollCount.current = 0;
setErrorMessage(undefined);
void updateState(NetworkApi.listNetworks(), () => undefined);
void getNetworkList();
}
);
const { data: networkList, send: getNetworkList } = useRequest(
NetworkApi.listNetworks,
{
immediate: false
}
).onSuccess((event) => {
// is called when network scan is completed
const { send: scanNetworks, onComplete: onCompleteScanNetworks } = useRequest(
NetworkApi.scanNetworks
);
const {
data: networkList,
send: getNetworkList,
onSuccess: onSuccessNetworkList
} = useRequest(NetworkApi.listNetworks, {
immediate: false
});
onSuccessNetworkList((event) => {
if (!event.data) {
const completedPollCount = pollCount.current + 1;
if (completedPollCount < NUM_POLLS) {
@@ -48,6 +45,42 @@ const WiFiNetworkScanner = () => {
}
});
onCompleteScanNetworks(() => {
pollCount.current = 0;
setErrorMessage(undefined);
updateState('listNetworks', () => undefined);
void getNetworkList();
});
// Alova 3 code...
// const { send: scanNetworks } = useRequest(NetworkApi.scanNetworks).onComplete(
// () => {
// pollCount.current = 0;
// setErrorMessage(undefined);
// void updateState(NetworkApi.listNetworks(), () => undefined);
// void getNetworkList();
// }
// );
// const { data: networkList, send: getNetworkList } = useRequest(
// NetworkApi.listNetworks,
// {
// immediate: false
// }
// ).onSuccess((event) => {
// // is called when network scan is completed
// if (!event.data) {
// const completedPollCount = pollCount.current + 1;
// if (completedPollCount < NUM_POLLS) {
// pollCount.current = completedPollCount;
// setTimeout(getNetworkList, POLLING_FREQUENCY);
// } else {
// setErrorMessage(LL.PROBLEM_LOADING());
// pollCount.current = 0;
// }
// }
// });
const renderNetworkScanner = () => {
if (!networkList) {
return (

View File

@@ -17,7 +17,7 @@ import type { Theme } from '@mui/material';
import { MessageBox } from 'components';
import { useI18nContext } from 'i18n/i18n-react';
import type { WiFiNetwork } from 'types';
import type { WiFiNetwork, WiFiNetworkList } from 'types';
import { WiFiEncryptionType } from 'types';
import { WiFiConnectionContext } from './WiFiConnectionContext';
@@ -57,7 +57,7 @@ const networkQualityHighlight = ({ rssi }: WiFiNetwork, theme: Theme) => {
return theme.palette.success.main;
};
function WiFiNetworkSelector({ networkList }) {
const WiFiNetworkSelector = ({ networkList }: { networkList: WiFiNetworkList }) => {
const { LL } = useI18nContext();
const theme = useTheme();
@@ -95,6 +95,6 @@ function WiFiNetworkSelector({ networkList }) {
}
return <List>{networkList.networks.map(renderNetwork)}</List>;
}
};
export default WiFiNetworkSelector;