mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-11 10:19:55 +03:00
33 lines
753 B
TypeScript
33 lines
753 B
TypeScript
import { useRequest } from 'alova';
|
|
|
|
import { FeaturesContext } from '.';
|
|
import type { FC } from 'react';
|
|
|
|
import type { RequiredChildrenProps } from 'utils';
|
|
import * as FeaturesApi from 'api/features';
|
|
import { ApplicationError, LoadingSpinner } from 'components';
|
|
|
|
const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
|
|
const { data: features, error } = useRequest(FeaturesApi.readFeatures);
|
|
|
|
if (features) {
|
|
return (
|
|
<FeaturesContext.Provider
|
|
value={{
|
|
features
|
|
}}
|
|
>
|
|
{props.children}
|
|
</FeaturesContext.Provider>
|
|
);
|
|
}
|
|
|
|
if (error) {
|
|
return <ApplicationError message={error?.message} />;
|
|
}
|
|
|
|
return <LoadingSpinner height="100vh" />;
|
|
};
|
|
|
|
export default FeaturesLoader;
|