2023-06-09 23:45:41 +00:00
|
|
|
|
import {
|
2023-06-10 12:10:21 +00:00
|
|
|
|
Box,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
Button,
|
2023-06-10 12:10:21 +00:00
|
|
|
|
Center,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
Flex,
|
2023-06-10 12:10:21 +00:00
|
|
|
|
HStack,
|
2023-06-15 19:52:41 +00:00
|
|
|
|
Icon,
|
|
|
|
|
IconButton,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
Menu,
|
|
|
|
|
MenuButton,
|
|
|
|
|
MenuItem,
|
|
|
|
|
MenuList,
|
|
|
|
|
Portal,
|
2023-06-10 12:10:21 +00:00
|
|
|
|
Spacer,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
Tab,
|
|
|
|
|
TabList,
|
|
|
|
|
TabPanel,
|
|
|
|
|
TabPanels,
|
|
|
|
|
Tabs,
|
|
|
|
|
Text,
|
2023-06-10 12:10:21 +00:00
|
|
|
|
VStack,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
useBreakpointValue,
|
|
|
|
|
} from '@chakra-ui/react';
|
|
|
|
|
import { PanelQMCv2Key } from './panels/PanelQMCv2Key';
|
|
|
|
|
import { useState } from 'react';
|
2023-06-15 19:52:41 +00:00
|
|
|
|
import { MdExpandMore, MdMenu, MdOutlineSettingsBackupRestore } from 'react-icons/md';
|
2023-06-10 12:10:21 +00:00
|
|
|
|
import { useAppDispatch } from '~/hooks';
|
|
|
|
|
import { commitStagingChange, discardStagingChanges } from './settingsSlice';
|
2023-06-17 01:45:31 +00:00
|
|
|
|
import { PanelKWMv2Key } from './panels/PanelKWMv2Key';
|
2023-06-09 23:45:41 +00:00
|
|
|
|
|
|
|
|
|
const TABS: { name: string; Tab: () => JSX.Element }[] = [
|
|
|
|
|
{ name: 'QMCv2 密钥', Tab: PanelQMCv2Key },
|
2023-06-17 01:45:31 +00:00
|
|
|
|
{ name: 'KWMv2 密钥', Tab: PanelKWMv2Key },
|
2023-06-09 23:45:41 +00:00
|
|
|
|
{
|
|
|
|
|
name: '其它/待定',
|
2023-06-10 12:10:21 +00:00
|
|
|
|
Tab: () => <Text>这里空空如也~</Text>,
|
2023-06-09 23:45:41 +00:00
|
|
|
|
},
|
|
|
|
|
];
|
2023-06-09 22:11:30 +00:00
|
|
|
|
|
|
|
|
|
export function Settings() {
|
2023-06-10 12:10:21 +00:00
|
|
|
|
const dispatch = useAppDispatch();
|
2023-06-09 23:45:41 +00:00
|
|
|
|
const isLargeWidthDevice =
|
|
|
|
|
useBreakpointValue({
|
|
|
|
|
base: false,
|
|
|
|
|
lg: true,
|
|
|
|
|
}) ?? false;
|
|
|
|
|
|
|
|
|
|
const [tabIndex, setTabIndex] = useState(0);
|
|
|
|
|
const handleTabChange = (idx: number) => {
|
|
|
|
|
setTabIndex(idx);
|
|
|
|
|
};
|
2023-06-10 12:10:21 +00:00
|
|
|
|
const handleResetSettings = () => dispatch(discardStagingChanges());
|
|
|
|
|
const handleApplySettings = () => dispatch(commitStagingChange());
|
2023-06-09 23:45:41 +00:00
|
|
|
|
|
2023-06-09 22:11:30 +00:00
|
|
|
|
return (
|
2023-06-09 23:45:41 +00:00
|
|
|
|
<Flex flexDir="column" flex={1}>
|
|
|
|
|
<Menu>
|
|
|
|
|
<MenuButton
|
|
|
|
|
as={Button}
|
|
|
|
|
leftIcon={<MdMenu />}
|
|
|
|
|
rightIcon={<MdExpandMore />}
|
|
|
|
|
colorScheme="gray"
|
|
|
|
|
variant="outline"
|
|
|
|
|
w="full"
|
|
|
|
|
flexShrink={0}
|
|
|
|
|
hidden={isLargeWidthDevice}
|
|
|
|
|
mb="4"
|
|
|
|
|
>
|
|
|
|
|
{TABS[tabIndex].name}
|
|
|
|
|
</MenuButton>
|
|
|
|
|
<Portal>
|
|
|
|
|
<MenuList w="100px">
|
|
|
|
|
{TABS.map(({ name }, i) => (
|
|
|
|
|
<MenuItem key={name} onClick={() => setTabIndex(i)}>
|
|
|
|
|
{name}
|
|
|
|
|
</MenuItem>
|
|
|
|
|
))}
|
|
|
|
|
</MenuList>
|
|
|
|
|
</Portal>
|
|
|
|
|
</Menu>
|
|
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
|
orientation={isLargeWidthDevice ? 'vertical' : 'horizontal'}
|
|
|
|
|
align="start"
|
|
|
|
|
variant="line-i"
|
|
|
|
|
display="flex"
|
|
|
|
|
flex={1}
|
|
|
|
|
index={tabIndex}
|
|
|
|
|
onChange={handleTabChange}
|
|
|
|
|
>
|
|
|
|
|
<TabList hidden={!isLargeWidthDevice} minW="8em" width="8em" textAlign="right" justifyContent="center">
|
|
|
|
|
{TABS.map(({ name }) => (
|
|
|
|
|
<Tab key={name}>{name}</Tab>
|
|
|
|
|
))}
|
|
|
|
|
</TabList>
|
2023-06-09 22:11:30 +00:00
|
|
|
|
|
2023-06-09 23:45:41 +00:00
|
|
|
|
<TabPanels>
|
|
|
|
|
{TABS.map(({ name, Tab }) => (
|
2023-06-10 12:10:21 +00:00
|
|
|
|
<Flex as={TabPanel} flex={1} flexDir="column" h="100%" key={name}>
|
|
|
|
|
<Flex h="100%" flex={1} minH={0}>
|
|
|
|
|
<Tab />
|
|
|
|
|
</Flex>
|
|
|
|
|
|
|
|
|
|
<VStack mt="4" alignItems="flex-start" w="full">
|
|
|
|
|
<Flex flexDir="row" gap="2" w="full">
|
|
|
|
|
<Center>
|
|
|
|
|
<Box color="gray">设置会在保存后生效。</Box>
|
|
|
|
|
</Center>
|
|
|
|
|
<Spacer />
|
|
|
|
|
<HStack gap="2" justifyContent="flex-end">
|
2023-06-15 19:52:41 +00:00
|
|
|
|
<IconButton
|
|
|
|
|
icon={<Icon as={MdOutlineSettingsBackupRestore} />}
|
|
|
|
|
onClick={handleResetSettings}
|
|
|
|
|
colorScheme="red"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
title="放弃未储存的更改,将设定还原为储存前的状态。"
|
|
|
|
|
aria-label="放弃未储存的更改"
|
|
|
|
|
/>
|
2023-06-10 15:16:41 +00:00
|
|
|
|
<Button onClick={handleApplySettings}>保存</Button>
|
2023-06-10 12:10:21 +00:00
|
|
|
|
</HStack>
|
|
|
|
|
</Flex>
|
|
|
|
|
</VStack>
|
|
|
|
|
</Flex>
|
2023-06-09 23:45:41 +00:00
|
|
|
|
))}
|
|
|
|
|
</TabPanels>
|
|
|
|
|
</Tabs>
|
|
|
|
|
</Flex>
|
2023-06-09 22:11:30 +00:00
|
|
|
|
);
|
|
|
|
|
}
|