2022-04-25 23:33:32 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { motion } from 'framer-motion';
|
2022-04-27 23:18:50 +02:00
|
|
|
import {
|
|
|
|
|
Grid,
|
|
|
|
|
Group,
|
|
|
|
|
Text,
|
|
|
|
|
Anchor,
|
|
|
|
|
Box,
|
|
|
|
|
AspectRatio,
|
|
|
|
|
createStyles,
|
|
|
|
|
Center,
|
2022-05-02 18:10:56 +02:00
|
|
|
Container,
|
|
|
|
|
SimpleGrid,
|
|
|
|
|
Space,
|
2022-05-04 07:12:22 +02:00
|
|
|
Card,
|
|
|
|
|
useMantineTheme,
|
|
|
|
|
Image,
|
|
|
|
|
Badge,
|
2022-04-27 23:18:50 +02:00
|
|
|
} from '@mantine/core';
|
2022-04-30 21:38:04 +02:00
|
|
|
import { showNotification } from '@mantine/notifications';
|
|
|
|
|
import { AlertCircle, Cross, X } from 'tabler-icons-react';
|
2022-04-25 23:33:32 +02:00
|
|
|
import AppShelfMenu from './AppShelfMenu';
|
|
|
|
|
import AddItemShelfItem from './AddAppShelfItem';
|
2022-05-02 15:09:39 +02:00
|
|
|
import { useConfig } from '../../tools/state';
|
2022-04-30 21:38:04 +02:00
|
|
|
import { pingQbittorrent } from '../../tools/api';
|
2022-05-04 07:12:22 +02:00
|
|
|
import { Config, serviceItem } from '../../tools/types';
|
|
|
|
|
import { SettingsMenuButton } from '../Settings/SettingsMenu';
|
2022-04-25 23:33:32 +02:00
|
|
|
|
|
|
|
|
const useStyles = createStyles((theme) => ({
|
|
|
|
|
main: {
|
2022-04-26 00:14:42 +02:00
|
|
|
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[1],
|
2022-05-02 18:10:56 +02:00
|
|
|
width: 200,
|
|
|
|
|
height: 180,
|
2022-04-25 23:33:32 +02:00
|
|
|
},
|
|
|
|
|
}));
|
2022-04-25 00:11:32 +02:00
|
|
|
|
2022-04-27 03:11:35 +02:00
|
|
|
const AppShelf = (props: any) => {
|
2022-05-02 15:09:39 +02:00
|
|
|
const { config, addService, removeService, setConfig } = useConfig();
|
2022-04-25 23:33:32 +02:00
|
|
|
|
2022-05-02 15:09:39 +02:00
|
|
|
/* A hook that is used to load the config from local storage. */
|
2022-04-25 23:33:32 +02:00
|
|
|
useEffect(() => {
|
2022-05-02 15:09:39 +02:00
|
|
|
const localConfig = localStorage.getItem('config');
|
|
|
|
|
if (localConfig) {
|
|
|
|
|
setConfig(JSON.parse(localConfig));
|
2022-04-25 23:33:32 +02:00
|
|
|
}
|
|
|
|
|
}, []);
|
2022-05-02 15:09:39 +02:00
|
|
|
if (config.services && config.services.length === 0) {
|
|
|
|
|
config.services.forEach((service) => {
|
|
|
|
|
if (service.type === 'qBittorrent') {
|
|
|
|
|
pingQbittorrent(service);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-04-25 23:33:32 +02:00
|
|
|
|
2022-04-25 00:11:32 +02:00
|
|
|
return (
|
2022-05-02 18:10:56 +02:00
|
|
|
<SimpleGrid m="xl" cols={4} spacing="xl">
|
|
|
|
|
{config.services.map((service, i) => (
|
2022-05-04 07:12:22 +02:00
|
|
|
<AppShelfItem service={service} />
|
|
|
|
|
))}
|
|
|
|
|
<AddItemShelfItem />
|
|
|
|
|
</SimpleGrid>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
<motion.div
|
|
|
|
|
onHoverStart={(e) => {
|
|
|
|
|
setHovering(true);
|
|
|
|
|
}}
|
|
|
|
|
onHoverEnd={(e) => {
|
|
|
|
|
setHovering(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Card
|
|
|
|
|
className={classes.main}
|
|
|
|
|
style={{
|
|
|
|
|
boxShadow: hovering ? '0px 0px 3px rgba(0, 0, 0, 0.5)' : '0px 0px 1px rgba(0, 0, 0, 0.5)',
|
|
|
|
|
}}
|
|
|
|
|
radius={'md'}
|
|
|
|
|
>
|
2022-05-02 18:10:56 +02:00
|
|
|
<motion.div
|
2022-05-04 07:12:22 +02:00
|
|
|
animate={{
|
|
|
|
|
opacity: hovering ? 1 : 0,
|
2022-05-02 18:10:56 +02:00
|
|
|
}}
|
|
|
|
|
>
|
2022-05-04 07:12:22 +02:00
|
|
|
<AppShelfMenu name={service.name} removeitem={removeService} />
|
2022-05-02 18:10:56 +02:00
|
|
|
</motion.div>
|
2022-05-04 07:12:22 +02:00
|
|
|
<Card.Section>
|
|
|
|
|
<Center>
|
|
|
|
|
<Text mt={'sm'} weight={500}>
|
|
|
|
|
{service.name}
|
|
|
|
|
</Text>
|
|
|
|
|
</Center>
|
|
|
|
|
</Card.Section>
|
|
|
|
|
<Card.Section>
|
|
|
|
|
<AspectRatio ratio={5 / 3} m="xl">
|
|
|
|
|
<motion.i
|
|
|
|
|
whileHover={{
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
scale: 1.1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
onClick={() => {
|
|
|
|
|
window.open(service.url);
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: '50%',
|
|
|
|
|
marginBottom: 10,
|
|
|
|
|
}}
|
|
|
|
|
src={service.icon}
|
|
|
|
|
/>
|
|
|
|
|
</motion.i>
|
|
|
|
|
</AspectRatio>
|
|
|
|
|
</Card.Section>
|
|
|
|
|
</Card>
|
|
|
|
|
</motion.div>
|
2022-04-25 00:11:32 +02:00
|
|
|
);
|
2022-05-04 07:12:22 +02:00
|
|
|
}
|
2022-04-25 00:11:32 +02:00
|
|
|
|
2022-04-27 03:11:35 +02:00
|
|
|
export default AppShelf;
|