import React, { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; import { Text, AspectRatio, createStyles, SimpleGrid, Card, useMantineTheme, Image, Group, Space, } from '@mantine/core'; import AppShelfMenu from './AppShelfMenu'; import AddItemShelfItem from './AddAppShelfItem'; import { useConfig } from '../../tools/state'; import { pingQbittorrent } from '../../tools/api'; import { serviceItem } from '../../tools/types'; const useStyles = createStyles((theme) => ({ main: { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[1], //TODO: #3 Fix this temporary fix and make the width and height dynamic / responsive width: 200, height: 180, }, })); const AppShelf = (props: any) => { const { config, addService, removeService, setConfig } = useConfig(); /* A hook that is used to load the config from local storage. */ useEffect(() => { const localConfig = localStorage.getItem('config'); if (localConfig) { setConfig(JSON.parse(localConfig)); } }, []); if (config.services && config.services.length === 0) { config.services.forEach((service) => { if (service.type === 'qBittorrent') { pingQbittorrent(service); } }); } return ( {config.services.map((service, i) => ( ))} ); }; export function AppShelfItem(props: any) { const { service }: { service: serviceItem } = props; const theme = useMantineTheme(); const { removeService } = useConfig(); const { classes } = useStyles(); const [hovering, setHovering] = useState(false); return ( { setHovering(true); }} onHoverEnd={(e) => { setHovering(false); }} > {service.name} { window.open(service.url); }} style={{ maxWidth: '50%', marginBottom: 10, }} src={service.icon} /> ); } export default AppShelf;