2023-03-31 05:56:32 -07:00
|
|
|
import { Flex, Group } from '@mantine/core';
|
|
|
|
|
import { closeAllModals, openModal } from '@mantine/modals';
|
2023-10-30 19:22:45 -07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-03-30 03:01:31 -07:00
|
|
|
import { RiSettings2Fill } from 'react-icons/ri';
|
2024-05-05 13:25:05 -07:00
|
|
|
import { Button, ConfirmModal, PageHeader, SearchInput } from '/@/renderer/components';
|
2023-03-30 03:01:31 -07:00
|
|
|
import { LibraryHeaderBar } from '/@/renderer/features/shared';
|
2023-03-31 05:56:32 -07:00
|
|
|
import { useSettingsStoreActions } from '../../../store/settings.store';
|
2024-05-05 13:25:05 -07:00
|
|
|
import { useSettingSearchContext } from '/@/renderer/features/settings/context/search-context';
|
|
|
|
|
import { useContainerQuery } from '/@/renderer/hooks';
|
2023-03-30 03:01:31 -07:00
|
|
|
|
2024-05-05 13:25:05 -07:00
|
|
|
export type SettingsHeaderProps = {
|
|
|
|
|
setSearch: (search: string) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const SettingsHeader = ({ setSearch }: SettingsHeaderProps) => {
|
2023-10-30 19:22:45 -07:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const { reset } = useSettingsStoreActions();
|
2024-05-05 13:25:05 -07:00
|
|
|
const search = useSettingSearchContext();
|
|
|
|
|
const cq = useContainerQuery();
|
|
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleResetToDefault = () => {
|
|
|
|
|
reset();
|
|
|
|
|
closeAllModals();
|
|
|
|
|
};
|
2023-03-31 05:56:32 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const openResetConfirmModal = () => {
|
|
|
|
|
openModal({
|
2023-10-30 19:22:45 -07:00
|
|
|
children: (
|
|
|
|
|
<ConfirmModal onConfirm={handleResetToDefault}>
|
|
|
|
|
{t('common.areYouSure', { postProcess: 'sentenceCase' })}
|
|
|
|
|
</ConfirmModal>
|
|
|
|
|
),
|
|
|
|
|
title: t('common.resetToDefault', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
});
|
|
|
|
|
};
|
2023-03-31 05:56:32 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2024-05-05 13:25:05 -07:00
|
|
|
<Flex ref={cq.ref}>
|
2023-07-01 19:10:05 -07:00
|
|
|
<PageHeader>
|
|
|
|
|
<LibraryHeaderBar>
|
|
|
|
|
<Flex
|
|
|
|
|
align="center"
|
|
|
|
|
justify="space-between"
|
|
|
|
|
w="100%"
|
|
|
|
|
>
|
|
|
|
|
<Group noWrap>
|
|
|
|
|
<RiSettings2Fill size="2rem" />
|
2023-10-30 19:22:45 -07:00
|
|
|
<LibraryHeaderBar.Title>
|
|
|
|
|
{t('common.setting', { count: 2, postProcess: 'titleCase' })}
|
|
|
|
|
</LibraryHeaderBar.Title>
|
2023-07-01 19:10:05 -07:00
|
|
|
</Group>
|
2024-05-05 13:25:05 -07:00
|
|
|
<Group>
|
|
|
|
|
<SearchInput
|
|
|
|
|
defaultValue={search}
|
|
|
|
|
openedWidth={cq.isMd ? 250 : cq.isSm ? 200 : 150}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
setSearch(event.target.value.toLocaleLowerCase())
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
variant="default"
|
|
|
|
|
onClick={openResetConfirmModal}
|
|
|
|
|
>
|
|
|
|
|
{t('common.resetToDefault', { postProcess: 'sentenceCase' })}
|
|
|
|
|
</Button>
|
|
|
|
|
</Group>
|
2023-07-01 19:10:05 -07:00
|
|
|
</Flex>
|
|
|
|
|
</LibraryHeaderBar>
|
|
|
|
|
</PageHeader>
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
2023-03-30 03:01:31 -07:00
|
|
|
};
|