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,
|
|
|
|
|
Image,
|
|
|
|
|
Anchor,
|
|
|
|
|
Box,
|
|
|
|
|
AspectRatio,
|
|
|
|
|
createStyles,
|
|
|
|
|
Center,
|
|
|
|
|
} 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-02 15:09:39 +02:00
|
|
|
import { Config } from '../../tools/types';
|
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-04-25 23:33:32 +02:00
|
|
|
textAlign: 'center',
|
|
|
|
|
padding: theme.spacing.xl,
|
|
|
|
|
borderRadius: theme.radius.md,
|
|
|
|
|
|
|
|
|
|
'&:hover': {
|
2022-04-26 00:14:42 +02:00
|
|
|
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[2],
|
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
|
|
|
const { classes } = useStyles();
|
2022-04-25 00:11:32 +02:00
|
|
|
const [hovering, setHovering] = useState('none');
|
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-04-30 21:38:04 +02:00
|
|
|
<Grid m="xl" gutter="xl">
|
2022-05-02 15:09:39 +02:00
|
|
|
{config.services
|
|
|
|
|
? config.services.map((service, i) => (
|
|
|
|
|
<Grid.Col lg={2} sm={3} key={i}>
|
|
|
|
|
<motion.div
|
|
|
|
|
onHoverStart={(e) => {
|
|
|
|
|
setHovering(service.name);
|
|
|
|
|
}}
|
|
|
|
|
onHoverEnd={(e) => {
|
|
|
|
|
setHovering('none');
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<AspectRatio ratio={4 / 3}>
|
|
|
|
|
<Box className={classes.main}>
|
|
|
|
|
<motion.div animate={{ opacity: hovering == service.name ? 1 : 0 }}>
|
|
|
|
|
<AppShelfMenu removeitem={removeService} name={service.name} />
|
2022-04-25 00:11:32 +02:00
|
|
|
</motion.div>
|
2022-05-02 15:09:39 +02:00
|
|
|
<Group direction="column" position="center">
|
|
|
|
|
<Anchor href={service.url} target="_blank">
|
|
|
|
|
<motion.div whileHover={{ scale: 1.2 }}>
|
|
|
|
|
<Image style={{ maxWidth: 60 }} src={service.icon} alt={service.name} />
|
|
|
|
|
</motion.div>
|
|
|
|
|
</Anchor>
|
|
|
|
|
<Text>{service.name}</Text>
|
|
|
|
|
</Group>
|
|
|
|
|
</Box>
|
|
|
|
|
</AspectRatio>
|
|
|
|
|
</motion.div>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
))
|
|
|
|
|
: null}
|
2022-04-27 03:11:35 +02:00
|
|
|
<AddItemShelfItem additem={addService} />
|
2022-04-25 00:11:32 +02:00
|
|
|
</Grid>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-27 03:11:35 +02:00
|
|
|
export default AppShelf;
|