diff options
| author | Haishan <[email protected]> | 2020-03-20 22:19:56 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-03-21 13:33:43 +0800 |
| commit | 8e48c01e7aada6978e92a6da1d040f3ef0d37945 (patch) | |
| tree | 63cdf772b88d2cff340449ba98225bdbad526a19 /src/components/ProxyGroup.js | |
| parent | c5d70b5236be5ce0fb067bab3c8eeb6e946a73dd (diff) | |
feat: remembers group collapse state
for https://github.com/haishanh/yacd/issues/480
Diffstat (limited to 'src/components/ProxyGroup.js')
| -rw-r--r-- | src/components/ProxyGroup.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/components/ProxyGroup.js b/src/components/ProxyGroup.js index fffb020..d7cf203 100644 --- a/src/components/ProxyGroup.js +++ b/src/components/ProxyGroup.js @@ -2,11 +2,11 @@ import React from 'react'; import cx from 'classnames'; import memoizeOne from 'memoize-one'; -import { connect } from './StateProvider'; +import { connect, useStoreActions } from './StateProvider'; import { getProxies, getRtFilterSwitch } from '../store/proxies'; +import { getCollapsibleIsOpen } from '../store/app'; import CollapsibleSectionHeader from './CollapsibleSectionHeader'; import Proxy, { ProxySmall } from './Proxy'; -import { useToggle } from '../hooks/basic'; import s0 from './ProxyGroup.module.css'; @@ -14,9 +14,17 @@ import { switchProxy } from '../store/proxies'; const { useCallback, useMemo } = React; -function ProxyGroup({ name, all, type, now, apiConfig, dispatch }) { +function ProxyGroup({ name, all, type, now, isOpen, apiConfig, dispatch }) { const isSelectable = useMemo(() => type === 'Selector', [type]); - const [isOpen, toggle] = useToggle(true); + + const { + app: { updateCollapsibleIsOpen } + } = useStoreActions(); + + const toggle = useCallback(() => { + updateCollapsibleIsOpen('proxyGroup', name, !isOpen); + }, [isOpen, updateCollapsibleIsOpen, name]); + const itemOnTapCallback = useCallback( proxyName => { if (!isSelectable) return; @@ -161,11 +169,13 @@ export function ProxyListSummaryView({ export default connect((s, { name, delay }) => { const proxies = getProxies(s); const filterByRt = getRtFilterSwitch(s); + const collapsibleIsOpen = getCollapsibleIsOpen(s); const group = proxies[name]; const { all, type, now } = group; return { all: filterAvailableProxiesAndSort(all, delay, filterByRt), type, - now + now, + isOpen: collapsibleIsOpen[`proxyGroup:${name}`] }; })(ProxyGroup); |
