Skip to content
Snippets Groups Projects
Unverified Commit 5280f1d7 authored by GyDi's avatar GyDi
Browse files

feat: proxy group auto scroll to current

parent b52a081e
No related branches found
No related tags found
No related merge requests found
import { useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { useSWRConfig } from "swr";
import { Virtuoso } from "react-virtuoso";
import {
......@@ -75,14 +75,14 @@ const ProxyGroup = ({ group }: Props) => {
}
};
const onLocation = () => {
const onLocation = (smooth = true) => {
const index = proxies.findIndex((p) => p.name === now);
if (index >= 0) {
virtuosoRef.current?.scrollToIndex?.({
index,
align: "center",
behavior: "smooth",
behavior: smooth ? "smooth" : "auto",
});
}
};
......@@ -110,6 +110,13 @@ const ProxyGroup = ({ group }: Props) => {
checkLockRef.current = false;
};
// auto scroll to current index
useEffect(() => {
if (open) {
setTimeout(() => onLocation(false), 5);
}
}, [open]);
return (
<>
<ListItem button onClick={() => setOpen(!open)} dense>
......@@ -131,7 +138,11 @@ const ProxyGroup = ({ group }: Props) => {
<Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ pl: 4, pr: 3, my: 0.5 }}>
<IconButton size="small" title="location" onClick={onLocation}>
<IconButton
size="small"
title="location"
onClick={() => onLocation(true)}
>
<MyLocationRounded />
</IconButton>
<IconButton size="small" title="check" onClick={onCheckAll}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment