(null);
+ useEffect(() => {
+ const savedTag = sessionStorage.getItem("selectedTag");
+ if (savedTag && allTag.includes(savedTag)) {
+ onTagChange(savedTag);
+ }
+ }, [allTag]);
+
useEffect(() => {
const container = scrollRef.current;
if (!container) return;
const isOverflowing = container.scrollWidth > container.clientWidth;
-
- if (!isOverflowing) {
- return;
- }
+ if (!isOverflowing) return;
const onWheel = (e: WheelEvent) => {
e.preventDefault();
- e.stopPropagation();
container.scrollLeft += e.deltaY;
};
@@ -47,7 +50,7 @@ export default function Switch({
{allTag.map((tag) => (
setTag(tag)}
+ onClick={() => onTagChange(tag)}
className={cn(
"relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500",
nowTag === tag
diff --git a/package.json b/package.json
index 50dfe09..76c090f 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
- "dev": "next dev -p 3020 --turbo",
+ "dev": "next dev -p 3020",
"start": "node .next/standalone/server.js",
"lint": "next lint",
"build": "next build && cp -r .next/static .next/standalone/.next/ && cp -r public .next/standalone/",
From 11abe9255a287db615e333e256fcf29453485e9e Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Tue, 22 Oct 2024 20:51:07 +0800
Subject: [PATCH 25/44] fix: hasHistory
---
.../ClientComponents/ServerDetailClient.tsx | 5 ++---
.../ClientComponents/ServerListClient.tsx | 21 +++++++++++--------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/app/[locale]/(main)/ClientComponents/ServerDetailClient.tsx b/app/[locale]/(main)/ClientComponents/ServerDetailClient.tsx
index 74227c2..55a3e52 100644
--- a/app/[locale]/(main)/ClientComponents/ServerDetailClient.tsx
+++ b/app/[locale]/(main)/ClientComponents/ServerDetailClient.tsx
@@ -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);
}
}, []);
diff --git a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx
index 85425cc..707047f 100644
--- a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx
+++ b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx
@@ -12,11 +12,18 @@ import useSWR from "swr";
export default function ServerListClient() {
const t = useTranslations("ServerListClient");
const containerRef = useRef(null);
-
const defaultTag = t("defaultTag");
- const [tag, setTag] = useState(
- sessionStorage.getItem("selectedTag") || defaultTag,
- );
+
+ const [tag, setTag] = useState(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() {
);
- if (!data?.result) return null;
+ if (!data?.result || !isMounted) return null;
const { result } = data;
const sortedServers = result.sort((a, b) => {
From 6fbba1ec2d1e2dd88190b6e13d6d7b717dc409ac Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Tue, 22 Oct 2024 21:34:23 +0800
Subject: [PATCH 26/44] fix: detail page scroll
---
app/[locale]/(main)/[id]/page.tsx | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/app/[locale]/(main)/[id]/page.tsx b/app/[locale]/(main)/[id]/page.tsx
index 8695fb3..9309b7b 100644
--- a/app/[locale]/(main)/[id]/page.tsx
+++ b/app/[locale]/(main)/[id]/page.tsx
@@ -27,12 +27,18 @@ export default function Page({ params }: { params: { id: string } }) {