From b3c1c565794f5eedcf1a0f84eca5bc6d0f8899d4 Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Mon, 21 Nov 2022 22:10:24 +0800
Subject: [PATCH] fix: group proxies render list is null

---
 src/components/proxy/proxy-groups.tsx   |  2 +-
 src/components/proxy/proxy-head.tsx     |  4 ++--
 src/components/proxy/use-render-list.ts | 12 +++++++++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx
index 94b8992..47dbf7d 100644
--- a/src/components/proxy/proxy-groups.tsx
+++ b/src/components/proxy/proxy-groups.tsx
@@ -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)}
diff --git a/src/components/proxy/proxy-head.tsx b/src/components/proxy/proxy-head.tsx
index 0515f99..fe29cb8 100644
--- a/src/components/proxy/proxy-head.tsx
+++ b/src/components/proxy/proxy-head.tsx
@@ -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>
diff --git a/src/components/proxy/use-render-list.ts b/src/components/proxy/use-render-list.ts
index 5fdf52e..8518a7a 100644
--- a/src/components/proxy/use-render-list.ts
+++ b/src/components/proxy/use-render-list.ts
@@ -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,
-- 
GitLab