mirror of
				https://github.com/ajnart/homarr.git
				synced 2025-11-03 20:15:57 +01:00 
			
		
		
		
	Add module enabler in settings. This loops over all the exported Modules in the components/modules folder and renders them. (Interpreted language magic/ metaclasses)
		
			
				
	
	
		
			28 lines
		
	
	
		
			902 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			902 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { Card, useMantineTheme } from '@mantine/core';
 | 
						|
import { useConfig } from '../../tools/state';
 | 
						|
import { IModule } from './modules';
 | 
						|
 | 
						|
export default function ModuleWrapper(props: any) {
 | 
						|
  const { module }: { module: IModule } = props;
 | 
						|
  const { config } = useConfig();
 | 
						|
  const enabledModules = config.settings.enabledModules ?? [];
 | 
						|
  // Remove 'Module' from enabled modules titles
 | 
						|
  const enabledModulesTitles = enabledModules.map((module) => module.replace('Module', ''));
 | 
						|
  const isShown = enabledModulesTitles.includes(module.title);
 | 
						|
  const theme = useMantineTheme();
 | 
						|
  return (
 | 
						|
    <Card
 | 
						|
      hidden={!isShown}
 | 
						|
      mx="sm"
 | 
						|
      radius="lg"
 | 
						|
      shadow="sm"
 | 
						|
      style={{
 | 
						|
        // Make background color of the card depend on the theme
 | 
						|
        backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : 'white',
 | 
						|
      }}
 | 
						|
    >
 | 
						|
      <module.component />
 | 
						|
    </Card>
 | 
						|
  );
 | 
						|
}
 |