2023-01-31 22:10:27 +01:00
|
|
|
import { Box, Stack, Title, UnstyledButton } from '@mantine/core';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { createStyles } 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';
|
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();
|
|
|
|
|
|
|
|
|
|
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-01-19 10:05:48 +09:00
|
|
|
<Stack
|
|
|
|
|
m={0}
|
|
|
|
|
p={0}
|
|
|
|
|
spacing="xs"
|
|
|
|
|
justify="space-around"
|
|
|
|
|
align="center"
|
|
|
|
|
style={{ height: '100%', width: '100%' }}
|
2023-02-10 23:37:08 +01:00
|
|
|
className="dashboard-tile-app"
|
2023-01-19 10:05:48 +09:00
|
|
|
>
|
|
|
|
|
<Box hidden={false}>
|
2023-03-03 00:37:22 +09:00
|
|
|
<Title
|
|
|
|
|
order={5}
|
|
|
|
|
size="md"
|
|
|
|
|
ta="center"
|
|
|
|
|
lineClamp={1}
|
|
|
|
|
className={cx(classes.appName, 'dashboard-tile-app-title')}
|
|
|
|
|
>
|
2023-01-19 10:05:48 +09:00
|
|
|
{app.name}
|
|
|
|
|
</Title>
|
|
|
|
|
</Box>
|
2023-01-03 22:32:00 +09:00
|
|
|
<motion.img
|
|
|
|
|
className={classes.image}
|
2023-01-19 10:05:48 +09:00
|
|
|
height="85%"
|
|
|
|
|
width="85%"
|
|
|
|
|
style={{
|
|
|
|
|
objectFit: 'contain',
|
|
|
|
|
}}
|
2023-01-03 22:32:00 +09:00
|
|
|
src={app.appearance.iconUrl}
|
|
|
|
|
alt={app.name}
|
|
|
|
|
whileHover={{
|
|
|
|
|
scale: 1.2,
|
|
|
|
|
transition: { duration: 0.2 },
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2023-01-19 10:05:48 +09:00
|
|
|
</Stack>
|
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: {
|
2023-01-03 22:32:00 +09:00
|
|
|
paddingBottom: 10,
|
2022-12-11 00:00:11 +01:00
|
|
|
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,
|
|
|
|
|
};
|