feat: scroll to proxy item
This commit is contained in:
parent
ccb68bcda9
commit
4934a24293
@ -1,5 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Collapse,
|
Collapse,
|
||||||
@ -16,8 +16,8 @@ import {
|
|||||||
MyLocationRounded,
|
MyLocationRounded,
|
||||||
NetworkCheckRounded,
|
NetworkCheckRounded,
|
||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { updateProxy } from "../../services/api";
|
|
||||||
import { ApiType } from "../../services/types";
|
import { ApiType } from "../../services/types";
|
||||||
|
import { updateProxy } from "../../services/api";
|
||||||
import { getProfiles, patchProfile } from "../../services/cmds";
|
import { getProfiles, patchProfile } from "../../services/cmds";
|
||||||
import ProxyItem from "./proxy-item";
|
import ProxyItem from "./proxy-item";
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ProxyGroup = ({ group }: Props) => {
|
const ProxyGroup = ({ group }: Props) => {
|
||||||
|
const listRef = useRef<any>();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [now, setNow] = useState(group.now);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<ListItem button onClick={() => setOpen(!open)} dense>
|
<ListItem button onClick={() => setOpen(!open)} dense>
|
||||||
@ -88,7 +101,7 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
|
|
||||||
<Collapse in={open} timeout="auto" unmountOnExit>
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||||
<Box sx={{ pl: 4, pr: 3, my: 0.5 }}>
|
<Box sx={{ pl: 4, pr: 3, my: 0.5 }}>
|
||||||
<IconButton size="small" title="location">
|
<IconButton size="small" title="location" onClick={onLocation}>
|
||||||
<MyLocationRounded />
|
<MyLocationRounded />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton size="small" title="check">
|
<IconButton size="small" title="check">
|
||||||
@ -98,6 +111,7 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
|
|
||||||
{proxies.length >= 10 ? (
|
{proxies.length >= 10 ? (
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
|
ref={listRef}
|
||||||
style={{ height: "320px", marginBottom: "4px" }}
|
style={{ height: "320px", marginBottom: "4px" }}
|
||||||
totalCount={proxies.length}
|
totalCount={proxies.length}
|
||||||
itemContent={(index) => (
|
itemContent={(index) => (
|
||||||
|
Loading…
Reference in New Issue
Block a user