2022-11-25 20:25:03 +00:00
|
|
|
import type { ComponentType } from 'react';
|
|
|
|
import { Suspense, useMemo } from 'react';
|
|
|
|
|
2022-06-12 15:56:00 +00:00
|
|
|
import features from './index';
|
2022-06-26 18:34:09 +00:00
|
|
|
import { getObjectKeys } from '@/lib/objects';
|
2022-06-12 15:56:00 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
type ListItems = [string, ComponentType][];
|
2022-06-12 15:56:00 +00:00
|
|
|
|
|
|
|
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);
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [enabled]);
|
2022-06-12 15:56:00 +00:00
|
|
|
|
|
|
|
return (
|
2022-11-25 20:25:03 +00:00
|
|
|
<Suspense fallback={null}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{mapped.map(([key, Component]) => (
|
|
|
|
<Component key={key} />
|
|
|
|
))}
|
2022-11-25 20:25:03 +00:00
|
|
|
</Suspense>
|
2022-06-12 15:56:00 +00:00
|
|
|
);
|
|
|
|
};
|