2023-08-06 19:36:36 +02:00
|
|
|
import { Box, Flex, Text, Tooltip, UnstyledButton } from '@mantine/core';
|
|
|
|
|
import { createStyles, useMantineTheme } from '@mantine/styles';
|
2023-01-02 02:52:12 +09:00
|
|
|
import { motion } from 'framer-motion';
|
2023-01-23 01:34:36 +09:00
|
|
|
import Link from 'next/link';
|
2023-07-21 18:08:40 +09:00
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
import { AppType } from '../../../../types/app';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { useCardStyles } from '../../../layout/useCardStyles';
|
2022-12-04 19:10:07 +01:00
|
|
|
import { useEditModeStore } from '../../Views/useEditModeStore';
|
2022-12-11 15:04:05 +01:00
|
|
|
import { HomarrCardWrapper } from '../HomarrCardWrapper';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { BaseTileProps } from '../type';
|
2022-12-18 22:27:01 +01:00
|
|
|
import { AppMenu } from './AppMenu';
|
|
|
|
|
import { AppPing } from './AppPing';
|
2022-12-04 17:36:30 +01:00
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
interface AppTileProps extends BaseTileProps {
|
|
|
|
|
app: AppType;
|
2022-12-04 17:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
export const AppTile = ({ className, app }: AppTileProps) => {
|
2022-12-04 17:36:30 +01:00
|
|
|
const isEditMode = useEditModeStore((x) => x.enabled);
|
|
|
|
|
|
|
|
|
|
const { cx, classes } = useStyles();
|
|
|
|
|
|
2023-08-06 19:36:36 +02:00
|
|
|
const { colorScheme } = useMantineTheme();
|
|
|
|
|
|
|
|
|
|
const tooltipContent = [
|
|
|
|
|
app.appearance.appNameStatus === "hover" ? app.name : undefined,
|
|
|
|
|
app.behaviour.tooltipDescription
|
|
|
|
|
].filter( e => e ).join( ': ' );
|
|
|
|
|
|
2022-12-04 17:36:30 +01:00
|
|
|
const {
|
|
|
|
|
classes: { card: cardClass },
|
2022-12-30 17:58:12 +01:00
|
|
|
} = useCardStyles(false);
|
2022-12-04 17:36:30 +01:00
|
|
|
|
2023-01-03 22:32:00 +09:00
|
|
|
function Inner() {
|
|
|
|
|
return (
|
2023-08-06 19:36:36 +02:00
|
|
|
<Tooltip.Floating
|
|
|
|
|
label={tooltipContent}
|
|
|
|
|
position="right-start"
|
|
|
|
|
c={ colorScheme === 'light' ? "black" : "dark.0" }
|
|
|
|
|
color={ colorScheme === 'light' ? "gray.2" : "dark.4" }
|
|
|
|
|
multiline
|
|
|
|
|
disabled={tooltipContent === ''}
|
|
|
|
|
styles={{ tooltip: { '&': { maxWidth: 300, }, }, }}
|
|
|
|
|
>
|
|
|
|
|
<Flex
|
2023-01-19 10:05:48 +09:00
|
|
|
m={0}
|
|
|
|
|
p={0}
|
|
|
|
|
justify="space-around"
|
|
|
|
|
align="center"
|
2023-08-06 19:36:36 +02:00
|
|
|
h="100%"
|
|
|
|
|
w="100%"
|
2023-02-10 23:37:08 +01:00
|
|
|
className="dashboard-tile-app"
|
2023-08-06 19:36:36 +02:00
|
|
|
direction={app.appearance.positionAppName ?? 'column'}
|
2023-01-19 10:05:48 +09:00
|
|
|
>
|
2023-08-06 19:36:36 +02:00
|
|
|
<Box px={10} hidden={["hover", "hidden"].includes(app.appearance.appNameStatus)}>
|
|
|
|
|
<Text
|
|
|
|
|
w="max-content"
|
2023-03-03 00:37:22 +09:00
|
|
|
size="md"
|
|
|
|
|
ta="center"
|
2023-08-06 19:36:36 +02:00
|
|
|
weight={700}
|
2023-03-03 00:37:22 +09:00
|
|
|
className={cx(classes.appName, 'dashboard-tile-app-title')}
|
|
|
|
|
>
|
2023-01-19 10:05:48 +09:00
|
|
|
{app.name}
|
2023-08-06 19:36:36 +02:00
|
|
|
</Text>
|
2023-01-19 10:05:48 +09:00
|
|
|
</Box>
|
2023-08-06 19:36:36 +02:00
|
|
|
<Box
|
|
|
|
|
w="100%"
|
|
|
|
|
h="100%"
|
|
|
|
|
display="flex"
|
|
|
|
|
sx={{
|
|
|
|
|
alignContent: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
flex: '1 1 auto',
|
|
|
|
|
flexWrap: 'wrap',
|
2023-01-19 10:05:48 +09:00
|
|
|
}}
|
2023-08-06 19:36:36 +02:00
|
|
|
>
|
|
|
|
|
<motion.img
|
|
|
|
|
className={classes.image}
|
|
|
|
|
height="85%"
|
|
|
|
|
style={{
|
|
|
|
|
objectFit: 'contain',
|
|
|
|
|
}}
|
|
|
|
|
src={app.appearance.iconUrl}
|
|
|
|
|
alt={app.name}
|
|
|
|
|
whileHover={{
|
|
|
|
|
scale: 1.2,
|
|
|
|
|
transition: { duration: 0.2 },
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Tooltip.Floating>
|
2023-01-03 22:32:00 +09:00
|
|
|
);
|
|
|
|
|
}
|
2022-12-04 17:36:30 +01:00
|
|
|
|
|
|
|
|
return (
|
2022-12-11 15:10:44 +01:00
|
|
|
<HomarrCardWrapper className={className}>
|
2022-12-19 18:26:04 +01:00
|
|
|
<AppMenu app={app} />
|
2022-12-18 22:27:01 +01:00
|
|
|
{!app.url || isEditMode ? (
|
2022-12-04 17:36:30 +01:00
|
|
|
<UnstyledButton
|
|
|
|
|
className={classes.button}
|
|
|
|
|
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
|
|
|
|
|
>
|
2023-01-03 22:32:00 +09:00
|
|
|
<Inner />
|
2022-12-04 17:36:30 +01:00
|
|
|
</UnstyledButton>
|
|
|
|
|
) : (
|
|
|
|
|
<UnstyledButton
|
|
|
|
|
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
|
2023-01-23 01:34:36 +09:00
|
|
|
component={Link}
|
2022-12-30 16:58:05 +01:00
|
|
|
href={app.behaviour.externalUrl.length > 0 ? app.behaviour.externalUrl : app.url}
|
2022-12-18 22:27:01 +01:00
|
|
|
target={app.behaviour.isOpeningNewTab ? '_blank' : '_self'}
|
2023-01-03 22:32:00 +09:00
|
|
|
className={cx(classes.button)}
|
2022-12-04 17:36:30 +01:00
|
|
|
>
|
2023-01-03 22:32:00 +09:00
|
|
|
<Inner />
|
2022-12-04 17:36:30 +01:00
|
|
|
</UnstyledButton>
|
|
|
|
|
)}
|
2022-12-18 22:27:01 +01:00
|
|
|
<AppPing app={app} />
|
2022-12-11 15:04:05 +01:00
|
|
|
</HomarrCardWrapper>
|
2022-12-04 17:36:30 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-11 00:00:11 +01:00
|
|
|
const useStyles = createStyles((theme, _params, getRef) => ({
|
|
|
|
|
image: {
|
2023-01-03 22:32:00 +09:00
|
|
|
maxHeight: '90%',
|
|
|
|
|
maxWidth: '90%',
|
2022-12-11 00:00:11 +01:00
|
|
|
},
|
2022-12-18 22:27:01 +01:00
|
|
|
appName: {
|
2023-01-20 12:57:45 +09:00
|
|
|
wordBreak: 'break-word',
|
2022-12-11 00:00:11 +01:00
|
|
|
},
|
|
|
|
|
button: {
|
|
|
|
|
height: '100%',
|
|
|
|
|
width: '100%',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: 4,
|
|
|
|
|
},
|
|
|
|
|
}));
|
2022-12-24 11:11:51 +01:00
|
|
|
|
|
|
|
|
export const appTileDefinition = {
|
|
|
|
|
component: AppTile,
|
2023-01-03 22:32:00 +09:00
|
|
|
minWidth: 1,
|
|
|
|
|
minHeight: 1,
|
2022-12-24 11:11:51 +01:00
|
|
|
maxWidth: 12,
|
|
|
|
|
maxHeight: 12,
|
|
|
|
|
};
|