misc_pterodactyl-panel/resources/scripts/components/server/features/Features.tsx

24 lines
744 B
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import type { ComponentType } from 'react';
import { Suspense, useMemo } from 'react';
import features from './index';
import { getObjectKeys } from '@/lib/objects';
2022-11-25 20:25:03 +00:00
type ListItems = [string, ComponentType][];
export default ({ enabled }: { enabled: string[] }) => {
const mapped: ListItems = useMemo(() => {
return getObjectKeys(features)
2022-11-25 20:25:03 +00:00
.filter(key => enabled.map(v => v.toLowerCase()).includes(key.toLowerCase()))
.reduce((arr, key) => [...arr, [key, features[key]]] as ListItems, [] as ListItems);
}, [enabled]);
return (
2022-11-25 20:25:03 +00:00
<Suspense fallback={null}>
{mapped.map(([key, Component]) => (
<Component key={key} />
))}
2022-11-25 20:25:03 +00:00
</Suspense>
);
};