2023-02-10 11:53:26 -08:00
|
|
|
import { ChangeEvent } from 'react';
|
|
|
|
|
import { Divider, Group, Stack } from '@mantine/core';
|
|
|
|
|
import { Accordion, Button, ContextModalVars, Switch } from '/@/renderer/components';
|
|
|
|
|
import { useLocalStorage } from '@mantine/hooks';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { openContextModal } from '@mantine/modals';
|
2023-02-10 11:53:26 -08:00
|
|
|
import isElectron from 'is-electron';
|
2023-10-30 19:22:45 -07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { RiAddFill, RiServerFill } from 'react-icons/ri';
|
|
|
|
|
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
|
|
|
|
|
import { ServerListItem } from '/@/renderer/features/servers/components/server-list-item';
|
|
|
|
|
import { useServerList } from '/@/renderer/store';
|
|
|
|
|
import { titleCase } from '/@/renderer/utils';
|
|
|
|
|
|
2023-02-10 11:53:26 -08:00
|
|
|
const localSettings = isElectron() ? window.electron.localSettings : null;
|
|
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
export const ServerList = () => {
|
2023-10-30 19:22:45 -07:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const serverListQuery = useServerList();
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleAddServerModal = () => {
|
|
|
|
|
openContextModal({
|
|
|
|
|
innerProps: {
|
2023-09-15 20:42:38 -07:00
|
|
|
// eslint-disable-next-line react/no-unstable-nested-components
|
2023-07-01 19:10:05 -07:00
|
|
|
modalBody: (vars: ContextModalVars) => (
|
|
|
|
|
<AddServerForm onCancel={() => vars.context.closeModal(vars.id)} />
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
modal: 'base',
|
2023-10-30 19:22:45 -07:00
|
|
|
title: t('form.addServer.title', { postProcess: 'titleCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
});
|
|
|
|
|
};
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const [ignoreCORS, setIgnoreCORS] = useLocalStorage({
|
|
|
|
|
defaultValue: 'false',
|
|
|
|
|
key: 'ignore_cors',
|
|
|
|
|
});
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const [ignoreSSL, setIgnoreSSL] = useLocalStorage({
|
|
|
|
|
defaultValue: 'false',
|
|
|
|
|
key: 'ignore_ssl',
|
|
|
|
|
});
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleUpdateIgnoreCORS = (e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setIgnoreCORS(String(e.currentTarget.checked));
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
if (isElectron()) {
|
|
|
|
|
localSettings?.set('ignore_cors', e.currentTarget.checked);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleUpdateIgnoreSSL = (e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setIgnoreSSL(String(e.currentTarget.checked));
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
if (isElectron()) {
|
|
|
|
|
localSettings?.set('ignore_ssl', e.currentTarget.checked);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-02-10 11:53:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Group
|
|
|
|
|
mb={10}
|
|
|
|
|
position="right"
|
|
|
|
|
sx={{
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: 55,
|
|
|
|
|
transform: 'translateY(-3.5rem)',
|
|
|
|
|
zIndex: 2000,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
autoFocus
|
|
|
|
|
compact
|
|
|
|
|
leftIcon={<RiAddFill size={15} />}
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="filled"
|
|
|
|
|
onClick={handleAddServerModal}
|
|
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('form.addServer.title', { postProcess: 'titleCase' })}
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Accordion variant="separated">
|
|
|
|
|
{Object.keys(serverListQuery)?.map((serverId) => {
|
|
|
|
|
const server = serverListQuery[serverId];
|
|
|
|
|
return (
|
|
|
|
|
<Accordion.Item
|
|
|
|
|
key={server.id}
|
|
|
|
|
value={server.name}
|
|
|
|
|
>
|
|
|
|
|
<Accordion.Control icon={<RiServerFill size={15} />}>
|
|
|
|
|
<Group position="apart">
|
|
|
|
|
{titleCase(server?.type)} - {server?.name}
|
|
|
|
|
</Group>
|
|
|
|
|
</Accordion.Control>
|
|
|
|
|
<Accordion.Panel>
|
|
|
|
|
<ServerListItem server={server} />
|
|
|
|
|
</Accordion.Panel>
|
|
|
|
|
</Accordion.Item>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Accordion>
|
2023-10-17 13:21:36 +00:00
|
|
|
{isElectron() && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<Group>
|
|
|
|
|
<Switch
|
|
|
|
|
checked={ignoreCORS === 'true'}
|
2023-10-30 19:22:45 -07:00
|
|
|
label={t('form.addServer.ignoreCors', {
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
})}
|
2023-10-17 13:21:36 +00:00
|
|
|
onChange={handleUpdateIgnoreCORS}
|
|
|
|
|
/>
|
|
|
|
|
</Group>
|
|
|
|
|
<Group>
|
|
|
|
|
<Switch
|
|
|
|
|
checked={ignoreSSL === 'true'}
|
2023-10-30 19:22:45 -07:00
|
|
|
label={t('form.addServer.ignoreSsl', {
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
})}
|
2023-10-17 13:21:36 +00:00
|
|
|
onChange={handleUpdateIgnoreSSL}
|
|
|
|
|
/>
|
|
|
|
|
</Group>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2023-07-01 19:10:05 -07:00
|
|
|
</Stack>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|