2022-12-11 15:10:44 +01:00
|
|
|
import { Card, Center, Text, UnstyledButton } from '@mantine/core';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { NextLink } from '@mantine/next';
|
|
|
|
|
import { createStyles } from '@mantine/styles';
|
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 },
|
|
|
|
|
} = useCardStyles();
|
|
|
|
|
|
|
|
|
|
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 */}
|
2022-12-18 22:27:01 +01:00
|
|
|
<img className={classes.image} src={app.appearance.iconUrl} alt="" />
|
2022-12-04 17:36:30 +01:00
|
|
|
</Center>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2022-12-11 15:10:44 +01:00
|
|
|
<HomarrCardWrapper className={className}>
|
2022-12-18 22:27:01 +01:00
|
|
|
{/* TODO: add app menu */}
|
2022-12-11 00:00:11 +01:00
|
|
|
|
|
|
|
|
<div style={{ position: 'absolute', top: 10, right: 10 }}>
|
2022-12-18 22:27:01 +01:00
|
|
|
<AppMenu app={app} />
|
2022-12-11 00:00:11 +01:00
|
|
|
</div>
|
|
|
|
|
|
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-18 22:27:01 +01:00
|
|
|
href={app.url}
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
}));
|