fix: group proxies render list is null

This commit is contained in:
GyDi 2022-11-21 22:10:24 +08:00
parent bd0e932910
commit b3c1c56579
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
3 changed files with 12 additions and 6 deletions

View File

@ -174,7 +174,7 @@ function ProxyRenderItem(props: RenderProps) {
if (type === 1) {
return (
<ProxyHead
sx={{ pl: indent ? 4.5 : 2.5, pr: 3, my: 1, button: { mr: 0.5 } }}
sx={{ pl: indent ? 4.5 : 2.5, pr: 3, mt: indent ? 1 : 0.5, mb: 1 }}
groupName={group.name}
headState={headState!}
onLocation={() => onLocation(group)}

View File

@ -49,7 +49,7 @@ export const ProxyHead = (props: Props) => {
}, [groupName, testUrl, verge?.default_latency_test]);
return (
<Box sx={{ display: "flex", alignItems: "center", ...sx }}>
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5, ...sx }}>
<IconButton
size="small"
color="inherit"
@ -86,7 +86,7 @@ export const ProxyHead = (props: Props) => {
onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType })
}
>
{sortType === 0 && <SortRounded />}
{sortType !== 1 && sortType !== 2 && <SortRounded />}
{sortType === 1 && <AccessTimeRounded />}
{sortType === 2 && <SortByAlphaRounded />}
</IconButton>

View File

@ -2,7 +2,11 @@ import useSWR from "swr";
import { getProxies } from "@/services/api";
import { useEffect, useMemo } from "react";
import { filterSort } from "./use-filter-sort";
import { useHeadStateNew, type HeadState } from "./use-head-state";
import {
useHeadStateNew,
DEFAULT_STATE,
type HeadState,
} from "./use-head-state";
export interface IRenderItem {
type: 0 | 1 | 2 | 3; // 组 head item empty
@ -36,17 +40,19 @@ export const useRenderList = (mode: string) => {
const renderList: IRenderItem[] = useMemo(() => {
if (!proxiesData) return [];
// global 和 direct 使用展开的样式
const useRule = mode === "rule" || mode === "script";
const renderGroups =
(useRule ? proxiesData?.groups : [proxiesData?.global!]) || [];
const retList = renderGroups.flatMap((group) => {
const headState = headStates[group.name];
const headState = headStates[group.name] || DEFAULT_STATE;
const ret: IRenderItem[] = [
{ type: 0, key: group.name, group, headState },
];
if (headState?.open) {
if (headState?.open || !useRule) {
const proxies = filterSort(
group.all,
group.name,