feat: proxy group auto scroll to current
This commit is contained in:
parent
b52a081e7b
commit
5280f1d745
@ -1,4 +1,4 @@
|
|||||||
import { useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useSWRConfig } from "swr";
|
import { useSWRConfig } from "swr";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso } from "react-virtuoso";
|
||||||
import {
|
import {
|
||||||
@ -75,14 +75,14 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onLocation = () => {
|
const onLocation = (smooth = true) => {
|
||||||
const index = proxies.findIndex((p) => p.name === now);
|
const index = proxies.findIndex((p) => p.name === now);
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
virtuosoRef.current?.scrollToIndex?.({
|
virtuosoRef.current?.scrollToIndex?.({
|
||||||
index,
|
index,
|
||||||
align: "center",
|
align: "center",
|
||||||
behavior: "smooth",
|
behavior: smooth ? "smooth" : "auto",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -110,6 +110,13 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
checkLockRef.current = false;
|
checkLockRef.current = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// auto scroll to current index
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setTimeout(() => onLocation(false), 5);
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ListItem button onClick={() => setOpen(!open)} dense>
|
<ListItem button onClick={() => setOpen(!open)} dense>
|
||||||
@ -131,7 +138,11 @@ 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" onClick={onLocation}>
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="location"
|
||||||
|
onClick={() => onLocation(true)}
|
||||||
|
>
|
||||||
<MyLocationRounded />
|
<MyLocationRounded />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton size="small" title="check" onClick={onCheckAll}>
|
<IconButton size="small" title="check" onClick={onCheckAll}>
|
||||||
|
Loading…
Reference in New Issue
Block a user