fix: loading screen shows Forumlify on first visit + rotating tab title
- LoadingScreen: drop forumName title (default name flashed on first
visit before settings loaded); show 🌊 logo + spinner instead
- AppProvider: during init rotate document.title Loading. → Loading..
→ Loading... every second; after ready show actual forum name
- layout: initial metadata title is 'Loading...' (client takes over)
This commit is contained in:
1 parent
ae8299820f
commit
ba65f446ec
5 files changed
+39
-5
No files matched your search
@@ -1218,6 +1218,17 @@ svg {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.loading-logo {
|
||||
font-size: 44px;
|
||||
line-height: 1;
|
||||
animation: float 2.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translateY(0); }
|
||||
50% { transform: translateY(-6px); }
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
|
||||
+2
-1
@@ -3,7 +3,8 @@ import './globals.css';
|
||||
import CustomCssLoader from '@/components/CustomCssLoader';
|
||||
|
||||
export const metadata = {
|
||||
title: 'Forumlify',
|
||||
// 初始标题由客户端 AppProvider 接管(加载时轮换 Loading.,完成后显示论坛名)
|
||||
title: 'Loading...',
|
||||
description: 'Forumlify - 简洁优雅的现代社区系统',
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import Modals from '@/components/Modals';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
|
||||
function HomeInner() {
|
||||
const { view, currentPostId, currentUsername, currentPageName, ready, forumName } = useApp();
|
||||
const { view, currentPostId, currentUsername, currentPageName, ready } = useApp();
|
||||
const [modal, setModal] = useState(null); // null | login | register | report
|
||||
const [reportPostId, setReportPostId] = useState(null);
|
||||
|
||||
@@ -27,7 +27,7 @@ function HomeInner() {
|
||||
|
||||
// 初始化未完成:显示全屏加载页,避免未加载完的界面闪烁
|
||||
if (!ready) {
|
||||
return <LoadingScreen forumName={forumName} />;
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -76,6 +76,26 @@ export default function AppProvider({ children }) {
|
||||
init();
|
||||
}, []);
|
||||
|
||||
// 页面标题:初始化中轮换 Loading. → Loading.. → Loading...,完成后显示论坛名
|
||||
useEffect(() => {
|
||||
if (!ready) {
|
||||
const seq = ['Loading.', 'Loading..', 'Loading...'];
|
||||
let i = 0;
|
||||
document.title = seq[0];
|
||||
const t = setInterval(() => {
|
||||
i = (i + 1) % seq.length;
|
||||
document.title = seq[i];
|
||||
}, 1000);
|
||||
return () => {
|
||||
clearInterval(t);
|
||||
};
|
||||
}
|
||||
// 初始化完成:标题恢复为论坛名
|
||||
document.title = forumName;
|
||||
const titleEl = document.querySelector('title');
|
||||
if (titleEl) titleEl.textContent = forumName;
|
||||
}, [ready, forumName]);
|
||||
|
||||
// 按 URL 参数初始化视图
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
'use client';
|
||||
|
||||
// 全屏加载页:初始化未完成时显示转圈,加载完成后淡出
|
||||
export default function LoadingScreen({ forumName }) {
|
||||
// 注意:不显示论坛名——初始化时论坛名可能尚未从服务器加载,
|
||||
// 显示默认名会造成"Forumlify 一闪而过"的体验问题。
|
||||
export default function LoadingScreen() {
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<div className="loading-inner">
|
||||
<div className="loading-logo" aria-hidden="true">🌊</div>
|
||||
<div className="loading-spinner" />
|
||||
<div className="loading-title">{forumName || 'Forumlify'}</div>
|
||||
<div className="loading-sub">加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user