Files
Homarr/src/components/Settings/Customization/Meta/BackgroundChanger.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-12-04 17:36:30 +01:00
import { TextInput } from '@mantine/core';
import { useTranslation } from 'next-i18next';
import { ChangeEventHandler, useState } from 'react';
2023-07-21 18:08:40 +09:00
2022-12-06 21:22:37 +01:00
import { useConfigContext } from '../../../../config/provider';
import { useConfigStore } from '../../../../config/store';
2022-12-04 17:36:30 +01:00
export const BackgroundChanger = () => {
2022-12-04 17:36:30 +01:00
const { t } = useTranslation('settings/customization/page-appearance');
const updateConfig = useConfigStore((x) => x.updateConfig);
const { config, name: configName } = useConfigContext();
const [backgroundImageUrl, setBackgroundImageUrl] = useState(
config?.settings.customization.backgroundImageUrl
);
2022-12-04 17:36:30 +01:00
if (!configName) return null;
const handleChange: ChangeEventHandler<HTMLInputElement> = (ev) => {
2022-12-06 21:22:37 +01:00
const { value } = ev.currentTarget;
2022-12-04 17:36:30 +01:00
const backgroundImageUrl = value.trim().length === 0 ? undefined : value;
setBackgroundImageUrl(backgroundImageUrl);
updateConfig(configName, (prev) => ({
...prev,
settings: {
...prev.settings,
customization: {
...prev.settings.customization,
backgroundImageUrl,
},
},
}));
};
return (
<TextInput
label={t('background.label')}
2023-04-11 18:59:56 +02:00
placeholder="/imgs/backgrounds/background.png"
2022-12-04 17:36:30 +01:00
value={backgroundImageUrl}
onChange={handleChange}
/>
);
};