fix: hasHistory

This commit is contained in:
hamster1963 2024-10-22 20:51:07 +08:00
parent 1b868a90b5
commit 11abe9255a
2 changed files with 14 additions and 12 deletions

View File

@ -30,11 +30,10 @@ export default function ServerDetailClient({
useEffect(() => {
const previousPath = sessionStorage.getItem("lastPath");
const currentPath = window.location.pathname;
if (previousPath && previousPath !== currentPath) {
if (previousPath) {
setHasHistory(true);
} else {
const currentPath = window.location.pathname;
sessionStorage.setItem("lastPath", currentPath);
}
}, []);

View File

@ -12,11 +12,18 @@ import useSWR from "swr";
export default function ServerListClient() {
const t = useTranslations("ServerListClient");
const containerRef = useRef<HTMLDivElement>(null);
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) => {
setTag(newTag);
@ -34,10 +41,6 @@ export default function ServerListClient() {
}
};
useEffect(() => {
restoreScrollPosition();
}, [tag]);
useEffect(() => {
const handleRouteChange = () => {
restoreScrollPosition();
@ -61,7 +64,7 @@ export default function ServerListClient() {
</div>
);
if (!data?.result) return null;
if (!data?.result || !isMounted) return null;
const { result } = data;
const sortedServers = result.sort((a, b) => {