Files
EMS-ESP32/interface/src/contexts/features/FeaturesLoader.tsx
2023-06-17 13:06:31 +02:00

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;