2022-12-11 00:17:34 +01:00
|
|
|
// disabled due to too many dynamic targets for next image cache
|
|
|
|
|
/* eslint-disable @next/next/no-img-element */
|
|
|
|
|
import Image from 'next/image';
|
|
|
|
|
import { createStyles, Loader } from '@mantine/core';
|
|
|
|
|
import { UseFormReturnType } from '@mantine/form';
|
|
|
|
|
import { useDebouncedValue } from '@mantine/hooks';
|
2022-12-18 22:27:01 +01:00
|
|
|
import { AppType } from '../../../../../../types/app';
|
2022-12-11 00:17:34 +01:00
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
interface DebouncedAppIconProps {
|
2022-12-11 00:17:34 +01:00
|
|
|
width: number;
|
|
|
|
|
height: number;
|
2022-12-18 22:27:01 +01:00
|
|
|
form: UseFormReturnType<AppType, (values: AppType) => AppType>;
|
2022-12-11 00:17:34 +01:00
|
|
|
debouncedWaitPeriod?: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
export const DebouncedAppIcon = ({
|
2022-12-11 00:17:34 +01:00
|
|
|
form,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
debouncedWaitPeriod = 1000,
|
2022-12-18 22:27:01 +01:00
|
|
|
}: DebouncedAppIconProps) => {
|
2022-12-11 00:17:34 +01:00
|
|
|
const { classes } = useStyles();
|
|
|
|
|
const [debouncedIconImageUrl] = useDebouncedValue(
|
|
|
|
|
form.values.appearance.iconUrl,
|
|
|
|
|
debouncedWaitPeriod
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (debouncedIconImageUrl !== form.values.appearance.iconUrl) {
|
|
|
|
|
return <Loader width={width} height={height} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debouncedIconImageUrl.length > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<img
|
|
|
|
|
className={classes.iconImage}
|
|
|
|
|
src={debouncedIconImageUrl}
|
|
|
|
|
width={width}
|
|
|
|
|
height={height}
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Image
|
|
|
|
|
className={classes.iconImage}
|
|
|
|
|
src="/imgs/logo/logo.png"
|
|
|
|
|
width={width}
|
|
|
|
|
height={height}
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const useStyles = createStyles(() => ({
|
|
|
|
|
iconImage: {
|
|
|
|
|
objectFit: 'contain',
|
|
|
|
|
},
|
|
|
|
|
}));
|