2022-12-20 11:45:33 +09:00
|
|
|
import { Center, Text, UnstyledButton } from '@mantine/core';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { NextLink } from '@mantine/next';
|
|
|
|
|
import { createStyles } from '@mantine/styles';
|
2023-01-02 02:52:12 +09:00
|
|
|
import { motion } from 'framer-motion';
|
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
|
|
|
|
|
|
|
|
const inner = (
|
|
|
|
|
<>
|
2022-12-18 22:27:01 +01:00
|
|
|
<Text align="center" weight={500} size="md" className={classes.appName}>
|
|
|
|
|
{app.name}
|
2022-12-04 17:36:30 +01:00
|
|
|
</Text>
|
|
|
|
|
<Center style={{ height: '75%', flex: 1 }}>
|
2022-12-11 00:00:11 +01:00
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
2023-01-02 02:52:12 +09:00
|
|
|
<motion.img
|
|
|
|
|
className={classes.image}
|
|
|
|
|
src={app.appearance.iconUrl}
|
|
|
|
|
alt=""
|
|
|
|
|
animate={{
|
|
|
|
|
scale: [0.8, 1.15, 1],
|
|
|
|
|
rotate: [0, 15, -15, 0],
|
|
|
|
|
}}
|
|
|
|
|
transition={{
|
|
|
|
|
duration: 0.5,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2022-12-04 17:36:30 +01:00
|
|
|
</Center>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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-11 00:00:11 +01:00
|
|
|
|
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' }}
|
|
|
|
|
>
|
|
|
|
|
{inner}
|
|
|
|
|
</UnstyledButton>
|
|
|
|
|
) : (
|
|
|
|
|
<UnstyledButton
|
|
|
|
|
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
|
|
|
|
|
component={NextLink}
|
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'}
|
2022-12-04 17:36:30 +01:00
|
|
|
className={cx(classes.button, classes.link)}
|
|
|
|
|
>
|
|
|
|
|
{inner}
|
|
|
|
|
</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: {
|
|
|
|
|
ref: getRef('image'),
|
|
|
|
|
maxHeight: '80%',
|
|
|
|
|
maxWidth: '80%',
|
|
|
|
|
transition: 'transform 100ms ease-in-out',
|
|
|
|
|
},
|
2022-12-18 22:27:01 +01:00
|
|
|
appName: {
|
|
|
|
|
ref: getRef('appName'),
|
2022-12-11 00:00:11 +01:00
|
|
|
},
|
|
|
|
|
button: {
|
|
|
|
|
height: '100%',
|
|
|
|
|
width: '100%',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: 4,
|
|
|
|
|
},
|
|
|
|
|
link: {
|
|
|
|
|
[`&:hover .${getRef('image')}`]: {
|
|
|
|
|
// TODO: add styles for image when hovering card
|
2022-12-04 17:36:30 +01:00
|
|
|
},
|
2022-12-18 22:27:01 +01:00
|
|
|
[`&:hover .${getRef('appName')}`]: {
|
|
|
|
|
// TODO: add styles for app name when hovering card
|
2022-12-04 17:36:30 +01:00
|
|
|
},
|
2022-12-11 00:00:11 +01:00
|
|
|
},
|
|
|
|
|
}));
|
2022-12-24 11:11:51 +01:00
|
|
|
|
|
|
|
|
export const appTileDefinition = {
|
|
|
|
|
component: AppTile,
|
|
|
|
|
minWidth: 2,
|
|
|
|
|
maxWidth: 12,
|
|
|
|
|
minHeight: 2,
|
|
|
|
|
maxHeight: 12,
|
|
|
|
|
};
|