feat: full-screen loading page with fade-in on init complete
- AppProvider: add 'ready' flag set after init (auth restore + settings) - page.js: show LoadingScreen (spinner + forum name) until ready, then fade in main UI (.app-fade-in 0.4s) — no more unloaded UI flash
This commit is contained in:
1 parent
4d4c227f58
commit
ae8299820f
4 files changed
+80
-3
No files matched your search
@@ -1198,3 +1198,56 @@ svg {
|
||||
padding: 2px 6px !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 全屏加载页 ===== */
|
||||
.loading-screen {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 99999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg);
|
||||
transition: background var(--transition);
|
||||
}
|
||||
|
||||
.loading-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border: 4px solid var(--border);
|
||||
border-top-color: var(--primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
.loading-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.loading-sub {
|
||||
font-size: 13px;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* ===== 主界面淡入(初始化完成) ===== */
|
||||
.app-fade-in {
|
||||
animation: appFadeIn 0.4s ease-out;
|
||||
}
|
||||
|
||||
@keyframes appFadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
+9
-3
@@ -15,17 +15,23 @@ import CustomPage from '@/components/CustomPage';
|
||||
import MessagesPage from '@/components/MessagesPage';
|
||||
import ChatManager from '@/components/chat/ChatManager';
|
||||
import Modals from '@/components/Modals';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
|
||||
function HomeInner() {
|
||||
const { view, currentPostId, currentUsername, currentPageName } = useApp();
|
||||
const { view, currentPostId, currentUsername, currentPageName, ready, forumName } = useApp();
|
||||
const [modal, setModal] = useState(null); // null | login | register | report
|
||||
const [reportPostId, setReportPostId] = useState(null);
|
||||
|
||||
const openModal = (m) => setModal(m);
|
||||
const openReport = (postId) => { setReportPostId(postId); setModal('report'); };
|
||||
|
||||
// 初始化未完成:显示全屏加载页,避免未加载完的界面闪烁
|
||||
if (!ready) {
|
||||
return <LoadingScreen forumName={forumName} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="app-fade-in">
|
||||
<Navbar onOpenModal={openModal} />
|
||||
<ChatManager />
|
||||
|
||||
@@ -46,7 +52,7 @@ function HomeInner() {
|
||||
</div>
|
||||
|
||||
<Modals modal={modal} onClose={() => setModal(null)} reportPostId={reportPostId} />
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ export default function AppProvider({ children }) {
|
||||
const [currentPageName, setCurrentPageName] = useState(null);
|
||||
const [sort, setSort] = useState('latest');
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [ready, setReady] = useState(false); // 初始加载完成标记(控制加载页/淡入)
|
||||
const loadedRef = useRef(false);
|
||||
|
||||
const refresh = useCallback(() => setRefreshKey((k) => k + 1), []);
|
||||
@@ -69,6 +70,8 @@ export default function AppProvider({ children }) {
|
||||
localStorage.setItem('forumlify-forum-name', s.forum_name);
|
||||
}
|
||||
} catch { /* 用默认名 */ }
|
||||
// 无论成功失败,初始化完成即标记 ready(结束加载页,淡入页面)
|
||||
setReady(true);
|
||||
}
|
||||
init();
|
||||
}, []);
|
||||
@@ -208,6 +211,7 @@ export default function AppProvider({ children }) {
|
||||
currentPageName, openCustomPage,
|
||||
sort, setSort,
|
||||
refreshKey, refresh,
|
||||
ready,
|
||||
login, register, logout,
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
'use client';
|
||||
|
||||
// 全屏加载页:初始化未完成时显示转圈,加载完成后淡出
|
||||
export default function LoadingScreen({ forumName }) {
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<div className="loading-inner">
|
||||
<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