From 4934a2429363c856b42da9eac2c3d8471af3967d Mon Sep 17 00:00:00 2001 From: GyDi Date: Tue, 15 Feb 2022 01:34:10 +0800 Subject: [PATCH] feat: scroll to proxy item --- src/components/proxy/proxy-group.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/proxy/proxy-group.tsx b/src/components/proxy/proxy-group.tsx index 6962189..2638660 100644 --- a/src/components/proxy/proxy-group.tsx +++ b/src/components/proxy/proxy-group.tsx @@ -1,5 +1,5 @@ -import { useState } from "react"; -import { Virtuoso } from "react-virtuoso"; +import { useRef, useState } from "react"; +import { Virtuoso, VirtuosoHandle } from "react-virtuoso"; import { Box, Collapse, @@ -16,8 +16,8 @@ import { MyLocationRounded, NetworkCheckRounded, } from "@mui/icons-material"; -import { updateProxy } from "../../services/api"; import { ApiType } from "../../services/types"; +import { updateProxy } from "../../services/api"; import { getProfiles, patchProfile } from "../../services/cmds"; import ProxyItem from "./proxy-item"; @@ -26,6 +26,7 @@ interface Props { } const ProxyGroup = ({ group }: Props) => { + const listRef = useRef(); const [open, setOpen] = useState(false); const [now, setNow] = useState(group.now); @@ -67,6 +68,18 @@ const ProxyGroup = ({ group }: Props) => { } }; + const onLocation = () => { + const index = proxies.findIndex((p) => p.name === now); + + if (index >= 0) { + listRef.current?.scrollToIndex?.({ + index, + align: "center", + behavior: "smooth", + }); + } + }; + return ( <> setOpen(!open)} dense> @@ -88,7 +101,7 @@ const ProxyGroup = ({ group }: Props) => { - + @@ -98,6 +111,7 @@ const ProxyGroup = ({ group }: Props) => { {proxies.length >= 10 ? ( (