ConceptPortal-public/rsconcept/frontend/src/components/wrap/DataLoader.tsx
2024-05-19 11:05:02 +03:00

38 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { AnimatePresence } from 'framer-motion';
import InfoError, { ErrorData } from '../info/InfoError';
import { CProps } from '../props';
import Loader from '../ui/Loader';
import AnimateFade from './AnimateFade';
interface DataLoaderProps extends CProps.AnimatedDiv {
id: string;
isLoading?: boolean;
error?: ErrorData;
hasNoData?: boolean;
children: React.ReactNode;
}
function DataLoader({ id, isLoading, hasNoData, error, children, ...restProps }: DataLoaderProps) {
return (
<AnimatePresence mode='wait'>
{!isLoading && !error && !hasNoData ? (
<AnimateFade id={id} key={`${id}-data`} {...restProps}>
{children}
</AnimateFade>
) : null}
{!isLoading && !error && hasNoData ? (
<AnimateFade key={`${id}-no-data`} {...restProps}>
Данные не загружены
</AnimateFade>
) : null}
{isLoading ? <Loader key={`${id}-loader`} /> : null}
{error ? <InfoError key={`${id}-error`} error={error} /> : null}
</AnimatePresence>
);
}
export default DataLoader;