mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
fix: hasHistory
This commit is contained in:
parent
1b868a90b5
commit
11abe9255a
@ -30,11 +30,10 @@ export default function ServerDetailClient({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const previousPath = sessionStorage.getItem("lastPath");
|
const previousPath = sessionStorage.getItem("lastPath");
|
||||||
const currentPath = window.location.pathname;
|
if (previousPath) {
|
||||||
|
|
||||||
if (previousPath && previousPath !== currentPath) {
|
|
||||||
setHasHistory(true);
|
setHasHistory(true);
|
||||||
} else {
|
} else {
|
||||||
|
const currentPath = window.location.pathname;
|
||||||
sessionStorage.setItem("lastPath", currentPath);
|
sessionStorage.setItem("lastPath", currentPath);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -12,11 +12,18 @@ import useSWR from "swr";
|
|||||||
export default function ServerListClient() {
|
export default function ServerListClient() {
|
||||||
const t = useTranslations("ServerListClient");
|
const t = useTranslations("ServerListClient");
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const defaultTag = t("defaultTag");
|
const defaultTag = t("defaultTag");
|
||||||
const [tag, setTag] = useState<string>(
|
|
||||||
sessionStorage.getItem("selectedTag") || defaultTag,
|
const [tag, setTag] = useState<string>(defaultTag);
|
||||||
);
|
|
||||||
|
const [isMounted, setIsMounted] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
const savedTag = sessionStorage.getItem("selectedTag") || defaultTag;
|
||||||
|
setTag(savedTag);
|
||||||
|
|
||||||
|
restoreScrollPosition();
|
||||||
|
setIsMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleTagChange = (newTag: string) => {
|
const handleTagChange = (newTag: string) => {
|
||||||
setTag(newTag);
|
setTag(newTag);
|
||||||
@ -34,10 +41,6 @@ export default function ServerListClient() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
restoreScrollPosition();
|
|
||||||
}, [tag]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleRouteChange = () => {
|
const handleRouteChange = () => {
|
||||||
restoreScrollPosition();
|
restoreScrollPosition();
|
||||||
@ -61,7 +64,7 @@ export default function ServerListClient() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!data?.result) return null;
|
if (!data?.result || !isMounted) return null;
|
||||||
|
|
||||||
const { result } = data;
|
const { result } = data;
|
||||||
const sortedServers = result.sort((a, b) => {
|
const sortedServers = result.sort((a, b) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user