+
{/* 独立页面 */}
- {view === 'post' && currentPostId &&
}
+ {view === 'post' && currentPostId &&
}
{view === 'user' && currentUsername &&
}
{view === 'custom' && currentPageName &&
}
{view === 'new' &&
}
diff --git a/app/api/auth/register/route.js b/app/api/auth/register/route.js
index 7de8957..fc59d24 100644
--- a/app/api/auth/register/route.js
+++ b/app/api/auth/register/route.js
@@ -27,7 +27,7 @@ export async function POST(req) {
return Response.json({
user: r.rows[0],
- message: isFirstUser ? '🎉 你是第一个用户,已自动设为管理员!' : '注册成功',
+ message: isFirstUser ? '你是第一个用户,已自动设为管理员!' : '注册成功',
});
} catch (err) {
if (err.code === '23505') {
diff --git a/app/globals.css b/app/globals.css
index f176eea..53cc34b 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -1,5 +1,5 @@
/* ============================================================
- 🧊 Forumlify —— 液态/磨砂玻璃风格(冰川蓝主题)
+ Forumlify —— 液态/磨砂玻璃风格(冰川蓝主题)
支持亮色/暗色模式 + 管理后台侧边栏 + 滑动Tab
============================================================ */
@@ -32,7 +32,7 @@
/* ===== 兼容旧变量(React 组件内联样式使用)===== */
--bg: #dfe6e9;
- --modal-bg: rgba(255, 255, 255, 0.85); /* 弹窗背景:半透明玻璃感但保证可读性 */
+ --modal-bg: rgba(255, 255, 255, 0.85);
--surface: rgba(255, 255, 255, 0.18);
--border: rgba(255, 255, 255, 0.30);
--border-light: rgba(255, 255, 255, 0.12);
@@ -73,7 +73,7 @@
/* ===== 兼容旧变量(React 组件内联样式使用)===== */
--bg: #0f0f1a;
- --modal-bg: rgba(24, 24, 38, 0.88); /* 弹窗背景:半透明玻璃感但保证可读性 */
+ --modal-bg: rgba(24, 24, 38, 0.88);
--surface: rgba(30, 30, 50, 0.35);
--border: rgba(255, 255, 255, 0.10);
--border-light: rgba(255, 255, 255, 0.06);
@@ -153,6 +153,16 @@ svg {
color: var(--glass-text);
}
+[data-theme="light"] #authButtons .btn-ghost {
+ background: rgba(74, 74, 106, 0.1);
+ border-color: transparent;
+ color: #30304a;
+}
+[data-theme="light"] #authButtons .btn-ghost:hover {
+ background: rgba(91, 155, 213, 0.2);
+ color: #202038;
+}
+
.btn-sm {
padding: 4px 12px;
border-radius: var(--radius-sm);
@@ -338,7 +348,7 @@ svg {
}
/* ===== 侧边栏 ===== */
-#sidebar {
+.sidebar {
width: 240px;
flex-shrink: 0;
}
@@ -433,6 +443,8 @@ svg {
border-radius: var(--radius-sm);
border: 1px solid var(--glass-border);
position: relative;
+ width: 280px;
+ max-width: 100%;
}
/* 滑块 */
@@ -470,8 +482,10 @@ svg {
cursor: pointer;
border-radius: calc(var(--radius-sm) - 2px);
transition: color 0.3s ease;
- flex: 1;
+ flex: 1 1 0;
+ min-width: 0;
text-align: center;
+ white-space: nowrap;
}
.tab:hover {
color: var(--glass-text);
@@ -491,6 +505,36 @@ svg {
margin-right: 6px;
}
+.feed-posts-drawer {
+ display: grid;
+ grid-template-rows: 1fr;
+ opacity: 1;
+ transform-origin: top;
+ transition:
+ grid-template-rows 0.34s cubic-bezier(0.22, 1, 0.36, 1),
+ opacity 0.2s ease,
+ transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
+}
+
+.feed-posts-drawer-inner {
+ min-height: 0;
+ overflow: hidden;
+}
+
+.feed-posts-drawer.closing,
+.feed-posts-drawer.closed {
+ grid-template-rows: 0fr;
+ opacity: 0;
+ transform: scaleY(0.985);
+}
+
+.feed-posts-drawer.opening,
+.feed-posts-drawer.idle {
+ grid-template-rows: 1fr;
+ opacity: 1;
+ transform: scaleY(1);
+}
+
/* ===== 帖子卡片 ===== */
.post-card {
background: var(--glass-bg);
@@ -611,17 +655,11 @@ svg {
}
.modal.active {
display: flex;
- animation: modalFade 0.2s ease-out;
+ animation: modalFade 0.28s ease-out;
}
@keyframes modalFade {
- from {
- opacity: 0;
- transform: scale(0.96);
- }
- to {
- opacity: 1;
- transform: scale(1);
- }
+ from { opacity: 0; }
+ to { opacity: 1; }
}
.modal-content {
background: var(--modal-bg, var(--glass-bg));
@@ -637,6 +675,13 @@ svg {
position: relative;
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
}
+.modal.active .modal-content {
+ animation: modalContentIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
+}
+@keyframes modalContentIn {
+ from { transform: translateY(12px) scale(0.9); opacity: 0; }
+ to { transform: translateY(0) scale(1); opacity: 1; }
+}
.modal-content .close {
position: absolute;
top: 14px;
@@ -843,6 +888,226 @@ svg {
display: block;
animation: slideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
+
+#pagePost.page-slide.active {
+ animation: none;
+}
+
+html.post-view-transition #pagePost .post-detail-card,
+html.home-view-transition.returning-home #pagePost .post-detail-card {
+ view-transition-name: post-expand;
+}
+
+html.post-view-transition #navbar,
+html.home-view-transition #navbar {
+ view-transition-name: persistent-navbar;
+}
+
+html.post-view-transition #sidebar,
+html.post-view-transition #postSidebar,
+html.home-view-transition.returning-home #sidebar,
+html.home-view-transition.returning-home #postSidebar {
+ view-transition-name: post-sidebar;
+}
+
+html.post-view-transition #pagePost .post-detail-card .post-time,
+html.home-view-transition.returning-home #pagePost .post-detail-card .post-time {
+ view-transition-name: post-time;
+}
+
+html.post-view-transition #pagePost .post-page-header h2,
+html.home-view-transition.returning-home #pagePost .post-page-header h2 {
+ view-transition-name: post-heading;
+}
+
+html.post-view-transition::view-transition,
+html.home-view-transition::view-transition {
+ background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-end) 100%);
+}
+
+html.post-view-transition::view-transition-group(post-expand) {
+ animation-duration: 0.96s;
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+html.post-view-transition::view-transition-group(post-sidebar),
+html.post-view-transition::view-transition-group(post-heading) {
+ animation-duration: 0.72s;
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+html.post-view-transition::view-transition-group(post-time) {
+ animation-duration: 1.05s;
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+html.post-view-transition::view-transition-group(persistent-navbar),
+html.home-view-transition::view-transition-group(persistent-navbar),
+html.post-view-transition::view-transition-old(persistent-navbar),
+html.post-view-transition::view-transition-new(persistent-navbar),
+html.home-view-transition::view-transition-old(persistent-navbar),
+html.home-view-transition::view-transition-new(persistent-navbar) {
+ animation: none;
+ mix-blend-mode: normal;
+}
+
+html.post-view-transition::view-transition-old(root) {
+ animation: feedViewFadeOut 0.28s 0.34s ease-out both;
+}
+
+html.post-view-transition::view-transition-new(root) {
+ animation: postSurroundingsReveal 0.24s 0.56s ease-out both;
+}
+
+html.post-view-transition::view-transition-old(post-expand) {
+ animation: postCardFadeOut 0.2s 0.5s ease-out both;
+}
+
+html.post-view-transition::view-transition-new(post-expand) {
+ animation: postCardReveal 0.22s 0.56s ease-out both;
+}
+
+html.post-view-transition::view-transition-old(post-heading) {
+ animation: sharedTitleOut 0.14s 0.48s ease-out both;
+}
+
+html.post-view-transition::view-transition-new(post-heading) {
+ animation: sharedTitleIn 0.14s 0.82s ease-out both;
+}
+
+html.post-view-transition::view-transition-old(post-time) {
+ animation: sharedTimeOut 0.2s 0.32s ease-out both;
+}
+
+html.post-view-transition::view-transition-new(post-time) {
+ animation: sharedTimeIn 0.2s 0.38s ease-out both;
+}
+
+html.post-view-transition::view-transition-old(post-sidebar) {
+ animation: sharedSidebarOut 0.2s 0.42s ease-out both;
+}
+
+html.post-view-transition::view-transition-new(post-sidebar) {
+ animation: sharedSidebarIn 0.2s 0.42s ease-out both;
+}
+
+html.home-view-transition::view-transition-old(root) {
+ animation: homeSourceFadeOut 0.4s ease-in both;
+}
+
+html.home-view-transition::view-transition-new(root) {
+ animation: homeFeedFadeIn 0.5s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-old(root) {
+ animation: homeSourceFadeOut 0.24s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-new(root) {
+ animation: homeFeedFadeIn 0.32s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-group(post-expand) {
+ animation-duration: 0.48s;
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+html.home-view-transition.returning-home::view-transition-group(post-sidebar),
+html.home-view-transition.returning-home::view-transition-group(post-heading),
+html.home-view-transition.returning-home::view-transition-group(post-time) {
+ animation-duration: 0.48s;
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+html.home-view-transition.returning-home::view-transition-old(post-expand) {
+ animation: postDetailCollapse 0.24s 0.12s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-new(post-expand) {
+ animation: postCardFadeIn 0.24s 0.18s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-old(post-heading) {
+ animation: sharedTitleOut 0.12s 0.22s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-new(post-heading) {
+ animation: sharedTitleIn 0.12s 0.36s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-old(post-time),
+html.home-view-transition.returning-home::view-transition-old(post-sidebar) {
+ animation: sharedTimeOut 0.14s 0.24s ease-out both;
+}
+
+html.home-view-transition.returning-home::view-transition-new(post-time),
+html.home-view-transition.returning-home::view-transition-new(post-sidebar) {
+ animation: sharedTimeIn 0.14s 0.26s ease-out both;
+}
+
+@keyframes feedViewFadeOut {
+ to { opacity: 0; }
+}
+
+@keyframes postSurroundingsReveal {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes postCardFadeOut {
+ 0%, 72% { opacity: 1; }
+ 100% { opacity: 0; }
+}
+
+@keyframes postCardReveal {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes homeSourceFadeOut {
+ to { opacity: 0; }
+}
+
+@keyframes homeFeedFadeIn {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes postDetailCollapse {
+ to { opacity: 0; }
+}
+
+@keyframes postCardFadeIn {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes sharedTitleOut {
+ to { opacity: 0; }
+}
+
+@keyframes sharedTitleIn {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes sharedTimeOut {
+ to { opacity: 0.2; }
+}
+
+@keyframes sharedTimeIn {
+ from { opacity: 0.2; }
+ to { opacity: 1; }
+}
+
+@keyframes sharedSidebarOut {
+ to { opacity: 0.72; }
+}
+
+@keyframes sharedSidebarIn {
+ from { opacity: 0.72; }
+ to { opacity: 1; }
+}
@keyframes slideIn {
from {
transform: translateX(40px);
@@ -906,6 +1171,34 @@ svg {
}
/* ===== 帖子详情页 ===== */
+.post-page-layout {
+ display: flex;
+ gap: 28px;
+ max-width: 1200px;
+ margin: 0 auto;
+ width: 100%;
+ align-items: flex-start;
+}
+
+.post-page-main {
+ flex: 1;
+ min-width: 0;
+ padding-top: 0;
+}
+
+#postSidebar {
+ width: 240px;
+ flex-shrink: 0;
+ align-self: start;
+}
+
+.post-page-header {
+ max-width: 1200px;
+ margin-left: auto;
+ margin-right: auto;
+ width: 100%;
+}
+
#pagePost .post-detail-card {
background: var(--glass-bg);
backdrop-filter: blur(16px);
@@ -923,6 +1216,10 @@ svg {
font-size: 22px;
}
+#pagePost .post-detail-actions {
+ margin-top: 8px;
+}
+
#repliesList {
margin-top: 4px;
}
@@ -1292,7 +1589,7 @@ svg {
/* ===== 响应式(保持原有) ===== */
@media (max-width: 768px) {
- #sidebar {
+ .sidebar {
display: none;
}
#app {
@@ -1311,6 +1608,7 @@ svg {
.feed-header-left {
display: flex;
gap: 4px;
+ width: 100%;
}
.tab {
flex: 1;
@@ -1325,6 +1623,12 @@ svg {
.post-card {
padding: 14px 16px;
}
+ .post-page-layout {
+ display: block;
+ }
+ .post-page-main {
+ padding-top: 0;
+ }
.post-image {
max-width: 120px;
max-height: 100px;
@@ -1488,7 +1792,7 @@ svg {
}
[data-theme="dark"] .admin-sidebar {
- background: var(--glass-bg);
+ background: #181826;
border-color: var(--glass-border);
}
[data-theme="dark"] .admin-nav-item:hover {
@@ -1505,7 +1809,7 @@ svg {
stroke: var(--primary);
}
[data-theme="dark"] .admin-content {
- background: var(--glass-bg);
+ background: #181826;
border-color: var(--glass-border);
}
[data-theme="dark"] .admin-sidebar {
@@ -1541,7 +1845,7 @@ svg {
}
/* ============================================================
- 💬 私信模态框 —— 亮色模式修复
+ 私信模态框 —— 亮色模式修复
============================================================ */
/* 亮色模式下私信列表模态框 + 聊天模态框 */
@@ -1602,7 +1906,7 @@ svg {
/* 暗色模式保持原样(不覆盖) */
/* ============================================================
- ⚠️ 自定义 CSS 警告模态框 —— 亮色模式文字修复
+ 自定义 CSS 警告模态框 —— 亮色模式文字修复
============================================================ */
/* 亮色模式下警告模态框文字变深 */
@@ -1617,7 +1921,7 @@ svg {
}
/* ============================================================
- 🎨 自定义 CSS 按钮 —— 亮色模式修复
+ 自定义 CSS 按钮 —— 亮色模式修复
============================================================ */
/* 亮色模式:删除自定义 CSS 按钮 */
@@ -1717,7 +2021,7 @@ svg {
color: #fff !important;
}
/* ============================================================
- 👤 用户个人主页 —— 卡片样式覆盖
+ 用户个人主页 —— 卡片样式覆盖
============================================================ */
/* 用户主页的主卡片 */
@@ -2101,24 +2405,51 @@ a.btn-secondary {
border-radius: 10px;
font-size: 14px;
font-weight: 500;
- color: #fff;
+ color: var(--glass-text);
+ border: 1px solid var(--glass-border);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
cursor: pointer;
animation: toastIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
+ display: flex;
+ align-items: center;
+ gap: 8px;
}
.toast-success {
- background: rgba(34, 197, 94, 0.92);
+ background: rgba(255, 255, 255, 0.85);
+ border-color: #22c55e;
}
.toast-error {
- background: rgba(239, 68, 68, 0.92);
+ background: rgba(255, 255, 255, 0.85);
+ border-color: #ef4444;
}
-.toast-info {
- background: rgba(91, 155, 213, 0.92);
+.toast-warning {
+ background: rgba(255, 255, 255, 0.85);
+ border-color: #f59e0b;
+}
+
+.toast-success svg {
+ color: #22c55e;
+}
+
+.toast-error svg {
+ color: #ef4444;
+}
+
+.toast-warning svg {
+ color: #f59e0b;
+}
+
+[data-theme="dark"] .toast {
+ background: rgba(30, 30, 50, 0.85);
+}
+
+.toast.closing {
+ animation: toastOut 0.22s ease-in forwards;
}
@keyframes toastIn {
@@ -2126,6 +2457,65 @@ a.btn-secondary {
to { opacity: 1; transform: translateX(0); }
}
+@keyframes toastOut {
+ from { opacity: 1; transform: translateX(0); }
+ to { opacity: 0; transform: translateX(24px); }
+}
+
+.modal.closing {
+ display: flex;
+ animation: modalFadeOut 0.32s ease-in forwards;
+ pointer-events: none;
+}
+
+@keyframes modalFadeOut {
+ from { opacity: 1; }
+ to { opacity: 0; }
+}
+
+.modal.closing .modal-content {
+ animation: modalContentOut 0.32s cubic-bezier(0.4, 0, 1, 1) forwards;
+}
+
+@keyframes modalContentOut {
+ from { transform: translateY(0) scale(1); opacity: 1; }
+ to { transform: translateY(12px) scale(0.9); opacity: 0; }
+}
+
+.feedback-confirm {
+ z-index: 100001;
+}
+
+.feedback-confirm .modal-content {
+ max-width: 440px;
+ background: var(--modal-bg);
+}
+
+.feedback-confirm .modal-content p {
+ color: var(--glass-text-secondary);
+ line-height: 1.6;
+ overflow-wrap: anywhere;
+}
+
+.feedback-confirm-actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: 10px;
+ margin-top: 24px;
+}
+
+.feedback-confirm-actions button {
+ border-radius: var(--radius-sm);
+ padding: 9px 18px;
+ cursor: pointer;
+}
+
+.feedback-confirm-actions .btn-danger {
+ border: 1px solid rgba(239, 68, 68, 0.5);
+ background: #dc2626;
+ color: #fff;
+}
+
/* 设置页面侧边栏导航项 */
.settings-nav-item {
display: flex;
@@ -2163,6 +2553,12 @@ a.btn-secondary {
}
/* 设置页面侧边栏容器 */
+.settings-layout {
+ max-width: none !important;
+ margin-left: 0 !important;
+ margin-right: 0 !important;
+}
+
.settings-sidebar {
background: var(--glass-bg) !important;
backdrop-filter: blur(16px) !important;
@@ -2177,6 +2573,11 @@ a.btn-secondary {
/* 设置页面内容区 */
.settings-content {
+ flex: 1 1 0;
+ width: calc(100% - 228px) !important;
+ max-width: none !important;
+ min-width: 0;
+ overflow-wrap: anywhere;
background: var(--glass-bg) !important;
backdrop-filter: blur(16px) !important;
-webkit-backdrop-filter: blur(16px) !important;
@@ -2186,6 +2587,59 @@ a.btn-secondary {
box-shadow: var(--glass-shadow) !important;
}
+.settings-content > *,
+.settings-content [data-panel] {
+ max-width: 100%;
+ min-width: 0;
+}
+
+.language-toggle {
+ width: 220px;
+ max-width: 100%;
+}
+
+.language-toggle .tab {
+ min-width: 0;
+ white-space: nowrap;
+}
+
+@media (max-width: 768px) {
+ .settings-layout {
+ flex-direction: column;
+ gap: 12px !important;
+ }
+
+ .settings-sidebar {
+ position: static;
+ width: 100% !important;
+ }
+
+ .settings-nav {
+ display: flex;
+ width: 100%;
+ }
+
+ .settings-nav-item {
+ flex: 1 1 0;
+ min-width: 0;
+ justify-content: center;
+ padding: 8px 6px;
+ border-left: 0;
+ border-bottom: 3px solid transparent;
+ text-align: center;
+ white-space: normal;
+ }
+
+ .settings-nav-item.active {
+ border-left-color: transparent;
+ border-bottom-color: var(--primary);
+ }
+
+ .settings-content {
+ width: 100% !important;
+ }
+}
+
/* 设置页面内部卡片 */
.settings-content [style*="background:var(--surface)"] {
background: rgba(255, 255, 255, 0.08) !important;
@@ -2255,7 +2709,7 @@ a.btn-secondary {
/* 暗色模式适配 */
[data-theme="dark"] .settings-sidebar {
- background: var(--glass-bg) !important;
+ background: #181826 !important;
border-color: var(--glass-border) !important;
}
[data-theme="dark"] .settings-nav-item:hover {
@@ -2272,7 +2726,7 @@ a.btn-secondary {
stroke: var(--primary);
}
[data-theme="dark"] .settings-content {
- background: var(--glass-bg) !important;
+ background: #181826 !important;
border-color: var(--glass-border) !important;
}
[data-theme="dark"] .settings-content input,
@@ -2283,6 +2737,46 @@ a.btn-secondary {
border-color: var(--glass-border) !important;
}
+/* 详情页两列布局需要压过页面尾部的通用卡片与响应式覆盖。 */
+#pagePost .post-page-layout {
+ display: flex !important;
+ gap: 28px !important;
+ width: 100% !important;
+ max-width: 1200px !important;
+ margin: 0 auto !important;
+ align-items: start !important;
+}
+
+#pagePost #postSidebar {
+ display: block !important;
+ width: 240px !important;
+ min-width: 240px !important;
+ flex: 0 0 240px !important;
+ align-self: start !important;
+}
+
+#pagePost .post-page-main {
+ display: block !important;
+ flex: 1 1 0 !important;
+ width: 100% !important;
+ min-width: 0 !important;
+}
+
+@media (max-width: 768px) {
+ #pagePost .post-page-layout {
+ display: block !important;
+ max-width: none !important;
+ }
+
+ #pagePost #postSidebar {
+ display: none !important;
+ }
+
+ #pagePost .post-page-main {
+ width: 100% !important;
+ }
+}
+
/* ===== 小转圈(列表/局部加载) ===== */
.spinner-sm {
display: inline-block;
diff --git a/components/AccountSecurity.js b/components/AccountSecurity.js
index c24bdcd..fd83314 100644
--- a/components/AccountSecurity.js
+++ b/components/AccountSecurity.js
@@ -5,10 +5,13 @@ import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { API } from '@/lib/api';
import { useApp } from './AppProvider';
+import { Icon } from './Icons';
+import { useToast } from './Toast';
export default function AccountSecurity() {
const { currentUser } = useApp();
const { t } = useTranslation();
+ const { toast } = useToast();
const [oldPassword, setOldPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [pwStatus, setPwStatus] = useState(null);
@@ -17,33 +20,33 @@ export default function AccountSecurity() {
const [emailStatus, setEmailStatus] = useState(null);
const changePassword = async () => {
- if (!oldPassword || !newPassword) { alert(t('security.fillAll')); return; }
- if (newPassword.length < 6) { alert(t('security.pwMin')); return; }
+ if (!oldPassword || !newPassword) { toast(t('security.fillAll'), 'warning'); return; }
+ if (newPassword.length < 6) { toast(t('security.pwMin'), 'warning'); return; }
try {
await API.updatePassword(currentUser.id, oldPassword, newPassword);
setPwStatus({ ok: true, msg: t('security.pwChanged') });
setOldPassword('');
setNewPassword('');
} catch (err) {
- setPwStatus({ ok: false, msg: '❌ ' + err.message });
+ setPwStatus({ ok: false, msg: err.message });
}
};
const changeEmail = async () => {
- if (!emailPassword || !newEmail) { alert(t('security.fillAll')); return; }
+ if (!emailPassword || !newEmail) { toast(t('security.fillAll'), 'warning'); return; }
try {
await API.updateEmail(currentUser.id, emailPassword, newEmail);
setEmailStatus({ ok: true, msg: t('security.emailChanged') });
setEmailPassword('');
setNewEmail('');
} catch (err) {
- setEmailStatus({ ok: false, msg: '❌ ' + err.message });
+ setEmailStatus({ ok: false, msg: err.message });
}
};
return (
-
🔒 {t('security.title')}
+
{t('security.title')}
@@ -54,7 +57,7 @@ export default function AccountSecurity() {
setNewPassword(e.target.value)} />
- {pwStatus &&
{pwStatus.msg}
}
+ {pwStatus &&
{pwStatus.msg}
}
@@ -67,7 +70,7 @@ export default function AccountSecurity() {
setNewEmail(e.target.value)} />
- {emailStatus &&
{emailStatus.msg}
}
+ {emailStatus &&
{emailStatus.msg}
}
);
}
diff --git a/components/AppProvider.js b/components/AppProvider.js
index d158eea..ec6d373 100644
--- a/components/AppProvider.js
+++ b/components/AppProvider.js
@@ -2,10 +2,47 @@
// 全局状态 Provider:用户、主题、论坛名、当前视图(feed/post/new/admin/...)
import { createContext, useContext, useState, useEffect, useCallback, useRef } from 'react';
+import { flushSync } from 'react-dom';
import { API, getTheme, setToken, getToken } from '@/lib/api';
const AppContext = createContext(null);
+function stageSharedGeometry(transition, { name, duration, moveOffset, preserveSizeUntilMove = false }) {
+ transition.ready.then(() => {
+ const groupAnimation = document.getAnimations().find(
+ (animation) => animation.effect?.pseudoElement === `::view-transition-group(${name})`
+ );
+ const frames = groupAnimation?.effect?.getKeyframes();
+ if (!groupAnimation || !frames || frames.length < 2) return;
+
+ const start = frames[0];
+ const end = frames[frames.length - 1];
+ groupAnimation.effect.setKeyframes([
+ {
+ offset: 0,
+ width: start.width,
+ height: start.height,
+ transform: start.transform,
+ easing: 'cubic-bezier(0.16, 1, 0.3, 1)',
+ },
+ {
+ offset: moveOffset,
+ width: preserveSizeUntilMove ? start.width : end.width,
+ height: start.height,
+ transform: end.transform,
+ easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
+ },
+ {
+ offset: 1,
+ width: end.width,
+ height: end.height,
+ transform: end.transform,
+ },
+ ]);
+ groupAnimation.effect.updateTiming({ duration, easing: 'linear', fill: 'both' });
+ }).catch(() => {});
+}
+
export function useApp() {
return useContext(AppContext);
}
@@ -17,6 +54,7 @@ export default function AppProvider({ children, cachedName = '' }) {
const [theme, setThemeState] = useState('light');
const [view, setView] = useState('feed'); // feed | post | new | admin | settings | messages | user | custom
const [currentPostId, setCurrentPostId] = useState(null);
+ const [currentPostPreview, setCurrentPostPreview] = useState(null);
const [currentUsername, setCurrentUsername] = useState(null);
const [currentPageName, setCurrentPageName] = useState(null);
const [sort, setSort] = useState('latest');
@@ -166,20 +204,101 @@ export default function AppProvider({ children, cachedName = '' }) {
url.searchParams.set('page', page);
url.searchParams.delete('post');
}
- window.history.pushState({ page }, '', url);
- setView(page);
- setCurrentPostId(null);
- refresh();
- }, [refresh]);
+ const commitNavigation = (refreshFeed = true) => {
+ window.history.pushState({ page }, '', url);
+ setView(page);
+ setCurrentPostId(null);
+ setCurrentPostPreview(null);
+ if (refreshFeed) refresh();
+ };
- const openPost = useCallback((postId) => {
+ const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
+ if (page !== 'feed' || view === 'feed' || !document.startViewTransition || reduceMotion) {
+ commitNavigation();
+ return;
+ }
+
+ let targetCard = currentPostId
+ ? Array.from(document.querySelectorAll('[data-post-id]')).find((element) => element.dataset.postId === String(currentPostId))
+ : null;
+ let targetTitle = null;
+ let targetTime = null;
+ document.documentElement.classList.add('home-view-transition');
+ if (targetCard) document.documentElement.classList.add('returning-home');
+
+ const transition = document.startViewTransition(() => {
+ flushSync(() => commitNavigation(false));
+ targetCard = currentPostId
+ ? Array.from(document.querySelectorAll('[data-post-id]')).find((element) => element.dataset.postId === String(currentPostId))
+ : null;
+ targetTitle = targetCard?.querySelector('.post-title');
+ targetTime = targetCard?.querySelector('.post-time');
+ if (targetCard) targetCard.style.viewTransitionName = 'post-expand';
+ if (targetTitle) targetTitle.style.viewTransitionName = 'post-heading';
+ if (targetTime) targetTime.style.viewTransitionName = 'post-time';
+ });
+ stageSharedGeometry(transition, { name: 'post-expand', duration: 480, moveOffset: 0.72 });
+ stageSharedGeometry(transition, {
+ name: 'post-heading',
+ duration: 480,
+ moveOffset: 0.72,
+ preserveSizeUntilMove: true,
+ });
+ const clearTargetNames = () => {
+ if (targetCard) targetCard.style.viewTransitionName = '';
+ if (targetTitle) targetTitle.style.viewTransitionName = '';
+ if (targetTime) targetTime.style.viewTransitionName = '';
+ };
+ transition.ready.then(clearTargetNames, clearTargetNames);
+ transition.finished.finally(() => {
+ document.documentElement.classList.remove('home-view-transition', 'returning-home');
+ refresh();
+ });
+ }, [currentPostId, refresh, view]);
+
+ const openPost = useCallback((postId, sourceElement = null, preview = null) => {
const url = new URL(window.location);
url.searchParams.set('post', postId);
url.searchParams.delete('page');
url.searchParams.delete('user');
- window.history.pushState({ page: 'post', postId }, '', url);
- setView('post');
- setCurrentPostId(postId);
+ const commitNavigation = () => {
+ window.history.pushState({ page: 'post', postId }, '', url);
+ setView('post');
+ setCurrentPostId(postId);
+ setCurrentPostPreview(preview);
+ };
+
+ const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
+ if (!sourceElement || !document.startViewTransition || reduceMotion) {
+ commitNavigation();
+ return;
+ }
+
+ const sourceTitle = sourceElement.querySelector('.post-title');
+ const sourceTime = sourceElement.querySelector('.post-time');
+ sourceElement.style.viewTransitionName = 'post-expand';
+ if (sourceTitle) sourceTitle.style.viewTransitionName = 'post-heading';
+ if (sourceTime) sourceTime.style.viewTransitionName = 'post-time';
+ document.documentElement.classList.add('post-view-transition');
+ const transition = document.startViewTransition(() => {
+ flushSync(commitNavigation);
+ });
+ stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 });
+ stageSharedGeometry(transition, {
+ name: 'post-heading',
+ duration: 960,
+ moveOffset: 0.62,
+ preserveSizeUntilMove: true,
+ });
+ const clearSourceNames = () => {
+ sourceElement.style.viewTransitionName = '';
+ if (sourceTitle) sourceTitle.style.viewTransitionName = '';
+ if (sourceTime) sourceTime.style.viewTransitionName = '';
+ };
+ transition.ready.then(clearSourceNames, clearSourceNames);
+ transition.finished.finally(() => {
+ document.documentElement.classList.remove('post-view-transition');
+ });
}, []);
const openUser = useCallback((username) => {
@@ -209,6 +328,7 @@ export default function AppProvider({ children, cachedName = '' }) {
if (state.postId) {
setView('post');
setCurrentPostId(state.postId);
+ setCurrentPostPreview(null);
} else if (state.username) {
setView('user');
setCurrentUsername(state.username);
@@ -218,6 +338,7 @@ export default function AppProvider({ children, cachedName = '' }) {
} else {
setView(state.page || 'feed');
setCurrentPostId(null);
+ setCurrentPostPreview(null);
setCurrentUsername(null);
setCurrentPageName(null);
}
@@ -262,7 +383,7 @@ export default function AppProvider({ children, cachedName = '' }) {
forumName, forumNameLoaded, updateForumName,
theme, toggleTheme,
view, navigate,
- currentPostId, openPost,
+ currentPostId, currentPostPreview, openPost,
currentUsername, openUser,
currentPageName, openCustomPage,
sort, setSort,
diff --git a/components/Feed.js b/components/Feed.js
index a57452a..a3d43cc 100644
--- a/components/Feed.js
+++ b/components/Feed.js
@@ -8,6 +8,7 @@ import { useApp } from './AppProvider';
import { Icon } from './Icons';
import ImageViewer from './ImageViewer';
import { renderMarkdown } from '@/lib/markdown';
+import { useToast } from './Toast';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -17,17 +18,21 @@ function avatar(username) {
export default function Feed({ onOpenModal, onReport }) {
const { currentUser, sort, setSort, openPost, openUser, navigate, refreshKey } = useApp();
const { t } = useTranslation();
+ const { toast, confirmAction } = useToast();
const [posts, setPosts] = useState(null);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const [viewerSrc, setViewerSrc] = useState(null);
+ const [selectedSort, setSelectedSort] = useState(sort);
+ const [drawerPhase, setDrawerPhase] = useState('idle');
const postListRef = useRef(null);
+ const sortTimerRef = useRef(null);
+ const pendingSortRef = useRef(null);
const PAGE_SIZE = 20;
const load = useCallback(async (targetPage) => {
- setPosts(null);
setError(null);
try {
const result = await API.getPosts(sort, null, targetPage, PAGE_SIZE);
@@ -37,6 +42,16 @@ export default function Feed({ onOpenModal, onReport }) {
} catch (err) {
setError(err.message);
setPosts([]);
+ } finally {
+ if (pendingSortRef.current === sort) {
+ requestAnimationFrame(() => {
+ setDrawerPhase('opening');
+ sortTimerRef.current = setTimeout(() => {
+ pendingSortRef.current = null;
+ setDrawerPhase('idle');
+ }, 360);
+ });
+ }
}
}, [sort, refreshKey]);
@@ -58,13 +73,37 @@ export default function Feed({ onOpenModal, onReport }) {
// 排序切换时回第一页
useEffect(() => { setPage(1); }, [sort]);
+ useEffect(() => () => clearTimeout(sortTimerRef.current), []);
+
+ const handleSortChange = (nextSort) => {
+ if (nextSort === selectedSort) return;
+
+ setSelectedSort(nextSort);
+ clearTimeout(sortTimerRef.current);
+
+ // 快速切回当前排序时,直接重新展开尚未替换的列表。
+ if (nextSort === sort) {
+ pendingSortRef.current = null;
+ setDrawerPhase('opening');
+ sortTimerRef.current = setTimeout(() => setDrawerPhase('idle'), 360);
+ return;
+ }
+
+ setDrawerPhase('closing');
+ sortTimerRef.current = setTimeout(() => {
+ pendingSortRef.current = nextSort;
+ setDrawerPhase('closed');
+ setSort(nextSort);
+ }, 220);
+ };
+
const handleDelete = async (postId) => {
- if (!confirm(t('feed.confirmDelete'))) return;
+ if (!await confirmAction(t('feed.confirmDelete'))) return;
try {
await API.deletePost(postId);
load(page);
} catch (err) {
- alert(t('feed.deleteFailed', { msg: err.message }));
+ toast(t('feed.deleteFailed', { msg: err.message }), 'error');
}
};
@@ -72,34 +111,36 @@ export default function Feed({ onOpenModal, onReport }) {
-
-
+
+
-
- {posts === null ? (
-
{t('feed.loading')}
- ) : error ? (
-
{t('feed.loadFailed', { msg: error })}
- ) : posts.length === 0 ? (
-
{t('feed.empty')}
- ) : (
- posts.map((p) => {
- const time = p.created_at ? new Date(p.created_at).toLocaleString('zh-CN') : '';
- return (
-
openPost(p.id)}>
+
+
+
+ {posts === null ? (
+
{t('feed.loading')}
+ ) : error ? (
+
{t('feed.loadFailed', { msg: error })}
+ ) : posts.length === 0 ? (
+
{t('feed.empty')}
+ ) : (
+ posts.map((p) => {
+ const time = p.created_at ? new Date(p.created_at).toLocaleString('zh-CN') : '';
+ return (
+
openPost(p.id, e.currentTarget, p)}>
{p.is_pinned && (
-
{t('feed.pinned')}
+
{t('feed.pinned')}
)}

@@ -130,7 +171,7 @@ export default function Feed({ onOpenModal, onReport }) {
)}
-
- );
- })
- )}
+
+ );
+ })
+ )}
+
+
{totalPages > 1 && posts && posts.length > 0 && (
diff --git a/components/Icons.js b/components/Icons.js
index b8487d8..6fdaf47 100644
--- a/components/Icons.js
+++ b/components/Icons.js
@@ -87,6 +87,11 @@ const PATHS = {
>
),
+ back: (
+ <>
+
+ >
+ ),
close: (
<>
@@ -97,4 +102,89 @@ const PATHS = {
>
),
+ success: (
+ <>
+
+ >
+ ),
+ error: (
+ <>
+
+ >
+ ),
+ warning: (
+ <>
+
+ >
+ ),
+ pending: (
+ <>
+
+ >
+ ),
+ edit: (
+ <>
+
+ >
+ ),
+ pin: (
+ <>
+
+ >
+ ),
+ camera: (
+ <>
+
+ >
+ ),
+ image: (
+ <>
+
+ >
+ ),
+ key: (
+ <>
+
+ >
+ ),
+ calendar: (
+ <>
+
+ >
+ ),
+ refresh: (
+ <>
+
+ >
+ ),
+ list: (
+ <>
+
+ >
+ ),
+ megaphone: (
+ <>
+
+ >
+ ),
+ code: (
+ <>
+
+ >
+ ),
+ upload: (
+ <>
+
+ >
+ ),
+ save: (
+ <>
+
+ >
+ ),
+ flag: (
+ <>
+
+ >
+ ),
};
diff --git a/components/MessagesPage.js b/components/MessagesPage.js
index 23ae2a8..c2228fe 100644
--- a/components/MessagesPage.js
+++ b/components/MessagesPage.js
@@ -6,7 +6,7 @@ import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
-const TYPE_MAP = { reply: '💬', post_deleted: '🗑️', report_handled: '🛡️', system: '📢' };
+const TYPE_MAP = { reply: 'message', post_deleted: 'trash', report_handled: 'shield', system: 'megaphone' };
export default function MessagesPage() {
const { currentUser } = useApp();
@@ -46,11 +46,11 @@ export default function MessagesPage() {
) : (
notifications.map((n) => {
- const icon = TYPE_MAP[n.type] || '📌';
+ const icon = TYPE_MAP[n.type] || 'pin';
const time = n.created_at ? new Date(n.created_at).toLocaleString('zh-CN') : '';
return (
-
{icon}
+
{n.title}
{n.content}
diff --git a/components/Modals.js b/components/Modals.js
index a70dbf9..3b0c16b 100644
--- a/components/Modals.js
+++ b/components/Modals.js
@@ -7,10 +7,12 @@ import { API, generateCaptcha } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
import CaptchaImage from './CaptchaImage';
+import { useToast } from './Toast';
export default function Modals({ modal, onClose, reportPostId }) {
const { login, register, currentUser, refresh } = useApp();
const { t } = useTranslation();
+ const { toast } = useToast();
// 登录表单
const [loginEmail, setLoginEmail] = useState('');
@@ -38,7 +40,7 @@ export default function Modals({ modal, onClose, reportPostId }) {
};
const handleLogin = async () => {
- if (!loginEmail.trim() || !loginPassword) { alert('请填写完整信息'); return; }
+ if (!loginEmail.trim() || !loginPassword) { toast('请填写完整信息', 'warning'); return; }
try {
const result = await login(loginEmail.trim(), loginPassword);
if (result.user) {
@@ -48,15 +50,15 @@ export default function Modals({ modal, onClose, reportPostId }) {
refresh();
}
} catch (err) {
- alert('登录失败:' + err.message);
+ toast('登录失败:' + err.message, 'error');
}
};
const handleRegister = async () => {
- if (!regUsername.trim() || !regEmail.trim() || !regPassword) { alert('请填写完整信息'); return; }
- if (regPassword.length < 6) { alert('密码至少6位'); return; }
+ if (!regUsername.trim() || !regEmail.trim() || !regPassword) { toast('请填写完整信息', 'warning'); return; }
+ if (regPassword.length < 6) { toast('密码至少6位', 'warning'); return; }
if (!regCaptcha || parseInt(regCaptchaInput) !== regCaptcha.answer) {
- alert('验证码错误,请重新计算');
+ toast('验证码错误,请重新计算', 'warning');
setRegCaptcha(generateCaptcha());
setRegCaptchaInput('');
return;
@@ -68,10 +70,10 @@ export default function Modals({ modal, onClose, reportPostId }) {
setRegEmail('');
setRegPassword('');
setRegCaptchaInput('');
- alert('注册成功!');
+ toast('注册成功!', 'success');
refresh();
} catch (err) {
- alert('注册失败:' + err.message);
+ toast('注册失败:' + err.message, 'error');
}
};
@@ -80,9 +82,9 @@ export default function Modals({ modal, onClose, reportPostId }) {
try {
await API.createReport(reportPostId, reportReason);
onClose();
- alert('举报已提交,管理员将尽快处理');
+ toast('举报已提交,管理员将尽快处理', 'success');
} catch (err) {
- alert('举报失败:' + err.message);
+ toast('举报失败:' + err.message, 'error');
}
};
diff --git a/components/Navbar.js b/components/Navbar.js
index 6934c5d..806d7a1 100644
--- a/components/Navbar.js
+++ b/components/Navbar.js
@@ -7,10 +7,12 @@ import { useApp } from './AppProvider';
import { Icon } from './Icons';
import { API } from '@/lib/api';
import { DMButton } from './chat/ChatManager';
+import { useToast } from './Toast';
export default function Navbar({ onOpenModal }) {
const { currentUser, forumName, theme, toggleTheme, navigate, openCustomPage, logout } = useApp();
const { t } = useTranslation();
+ const { toast, confirmAction } = useToast();
const [menuOpen, setMenuOpen] = useState(false);
const [customPages, setCustomPages] = useState([]);
@@ -37,7 +39,7 @@ export default function Navbar({ onOpenModal }) {
const goPage = (page) => {
if (page === 'admin' && currentUser?.role !== 'admin') {
- alert('无权限访问');
+ toast('无权限访问', 'warning');
return;
}
setMenuOpen(false);
@@ -47,7 +49,7 @@ export default function Navbar({ onOpenModal }) {
const openMessages = (e) => {
e.preventDefault();
setMenuOpen(false);
- // 消息页 = 通知列表(与原版一致),私信走导航栏 ✉️ 按钮
+ // 消息页展示通知列表,私信使用导航栏按钮。
navigate('messages');
};
@@ -117,9 +119,9 @@ export default function Navbar({ onOpenModal }) {
{
+ onClick={async (e) => {
e.preventDefault();
- if (confirm(t('nav.logoutConfirm'))) {
+ if (await confirmAction(t('nav.logoutConfirm'))) {
setMenuOpen(false);
logout();
}
diff --git a/components/NewPost.js b/components/NewPost.js
index d9c35ed..649c300 100644
--- a/components/NewPost.js
+++ b/components/NewPost.js
@@ -30,7 +30,7 @@ export default function NewPost() {
for (const file of files) {
if (!file.type.startsWith('image/')) continue;
if (file.size > 5 * 1024 * 1024) {
- alert('图片 ' + file.name + ' 超过 5MB,请压缩后上传');
+ toast('图片 ' + file.name + ' 超过 5MB,请压缩后上传', 'warning');
continue;
}
const dataUrl = await new Promise((resolve) => {
@@ -44,7 +44,7 @@ export default function NewPost() {
}
setPreviews((prev) => [...prev, ...newPreviews]);
} catch (err) {
- alert('上传失败:' + err.message);
+ toast('上传失败:' + err.message, 'error');
} finally {
setUploading(false);
}
@@ -117,8 +117,9 @@ export default function NewPost() {
onDragLeave={(e) => { e.preventDefault(); setDragOver(false); }}
onDrop={(e) => { e.preventDefault(); setDragOver(false); if (e.dataTransfer.files) handleFiles(Array.from(e.dataTransfer.files)); }}
>
+ {!uploading && !dragOver && }
- {uploading ? t('newPost.uploading') : (dragOver ? t('newPost.drop') : '📷 ' + t('newPost.dropHint'))}
+ {uploading ? t('newPost.uploading') : (dragOver ? t('newPost.drop') : t('newPost.dropHint'))}
加载中...
;
+ return
加载中...
;
}
const time = post.created_at ? new Date(post.created_at).toLocaleString('zh-CN') : '';
@@ -55,23 +58,23 @@ export default function PostDetail({ postId }) {
const canEdit = currentUser && currentUser.id === post.user_id;
const handleDelete = async () => {
- if (!confirm('确定要删除这条帖子吗?')) return;
+ if (!await confirmAction('确定要删除这条帖子吗?')) return;
try {
await API.deletePost(postId);
- alert('删除成功');
+ toast('删除成功', 'success');
navigate('feed');
} catch (err) {
- alert('删除失败:' + err.message);
+ toast('删除失败:' + err.message, 'error');
}
};
const handleTogglePin = async () => {
- if (!confirm('确定要' + (post.is_pinned ? '取消' : '') + '置顶吗?')) return;
+ if (!await confirmAction('确定要' + (post.is_pinned ? '取消' : '') + '置顶吗?', { danger: false })) return;
try {
await API.togglePinPost(postId);
load();
} catch (err) {
- alert('操作失败:' + err.message);
+ toast('操作失败:' + err.message, 'error');
}
};
@@ -83,27 +86,27 @@ export default function PostDetail({ postId }) {
};
const handleSaveEdit = async () => {
- if (!editContent.trim()) { alert('请填写内容'); return; }
+ if (!editContent.trim()) { toast('请填写内容', 'warning'); return; }
try {
await API.updatePost(postId, editTitle.trim() || '无标题', editContent.trim(), editImages);
setEditing(false);
load();
} catch (err) {
- alert('编辑失败:' + err.message);
+ toast('编辑失败:' + err.message, 'error');
}
};
// 编辑时上传新图片
const handleEditUpload = async (file) => {
if (!file) return;
- if (!file.type.startsWith('image/')) { alert('请选择图片文件'); return; }
- if (file.size > 5 * 1024 * 1024) { alert('图片不能超过 5MB'); return; }
+ if (!file.type.startsWith('image/')) { toast('请选择图片文件', 'warning'); return; }
+ if (file.size > 5 * 1024 * 1024) { toast('图片不能超过 5MB', 'warning'); return; }
setEditUploading(true);
try {
const url = await uploadImage(file);
setEditImages((prev) => [...prev, url]);
} catch (err) {
- alert('上传失败:' + err.message);
+ toast('上传失败:' + err.message, 'error');
} finally {
setEditUploading(false);
}
@@ -116,68 +119,74 @@ export default function PostDetail({ postId }) {
return (
-
+
+
{post.title || '帖子详情'}
-
-
-
-

-
openUser(post.username)}
- >
- {post.username || '匿名用户'}
-
-
{time}
- {post.edited_at && (
-
- (已编辑 {new Date(post.edited_at).toLocaleString('zh-CN')})
+
+
+
+
+
+

+
openUser(post.username)}
+ >
+ {post.username || '匿名用户'}
- )}
- {post.is_pinned && (
-
📌 置顶
- )}
-
- {currentUser && currentUser.role === 'admin' && (
-
+
{time}
+ {post.edited_at && (
+
+ (已编辑 {new Date(post.edited_at).toLocaleString('zh-CN')})
+
)}
- {canDelete && (
-
- )}
- {canDelete && (
-
+ {post.is_pinned && (
+
置顶
)}
+
+ {currentUser && currentUser.role === 'admin' && (
+
+ )}
+ {canEdit && (
+
+ )}
+ {canDelete && (
+
+ )}
+
+
+ {post.images && post.images.length > 0 && (
+
+ {post.images.map((img, i) => (
+

setViewerSrc(img)} />
+ ))}
+
+ )}
+ {post.signature && (
+
+ )}
-
- {post.images && post.images.length > 0 && (
-
- {post.images.map((img, i) => (
-

setViewerSrc(img)} />
- ))}
-
- )}
- {post.signature && (
-
- )}
+
-
{/* 编辑帖子 modal */}
{editing && (
{ if (e.target === e.currentTarget) setEditing(false); }}>
- setEditing(false)}>×
-
✏️ 编辑帖子
+ setEditing(false)}>
+ 编辑帖子
handleEditRemoveImage(img)}
- style={{ position: 'absolute', top: -6, right: -6, width: 20, height: 20, borderRadius: '50%', background: '#ef4444', color: '#fff', border: 'none', cursor: 'pointer', fontSize: 12, lineHeight: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
- >×
+ style={{ position: 'absolute', top: -6, right: -6, width: 20, height: 20, borderRadius: '50%', background: '#ef4444', color: '#fff', border: 'none', cursor: 'pointer', lineHeight: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
+ >
))}
)}
{ const files = e.target.files; if (files && files.length > 0) { [...files].forEach((f) => handleEditUpload(f)); e.target.value = ''; } }} />
diff --git a/components/RecoveryCodes.js b/components/RecoveryCodes.js
index 8bf440c..6bd81e9 100644
--- a/components/RecoveryCodes.js
+++ b/components/RecoveryCodes.js
@@ -4,11 +4,23 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { API } from '@/lib/api';
+import { Icon } from './Icons';
+import { useToast } from './Toast';
export default function RecoveryCodes() {
const { t } = useTranslation();
+ const { toast, confirmAction } = useToast();
const [count, setCount] = useState(0);
const [modal, setModal] = useState(null); // null | {codes, isNew}
+ const [modalClosing, setModalClosing] = useState(false);
+
+ const closeModal = () => {
+ setModalClosing(true);
+ setTimeout(() => {
+ setModal(null);
+ setModalClosing(false);
+ }, 340);
+ };
const loadCount = () => {
API.getRecoveryCodeCount().then((d) => setCount(d.count || 0)).catch(() => {});
@@ -16,13 +28,13 @@ export default function RecoveryCodes() {
useEffect(loadCount, []);
const regenerate = async () => {
- if (!confirm(t('recovery.confirmRegenerate'))) return;
+ if (!await confirmAction(t('recovery.confirmRegenerate'))) return;
try {
const d = await API.generateRecoveryCodes();
setModal({ codes: d.codes || [], isNew: true });
loadCount();
} catch (err) {
- alert(t('recovery.genFailed', { msg: err.message }));
+ toast(t('recovery.genFailed', { msg: err.message }), 'error');
}
};
@@ -33,32 +45,32 @@ export default function RecoveryCodes() {
setModal({ codes: d.codes || [], isNew: false });
loadCount();
} catch (err) {
- alert(t('recovery.fetchFailed', { msg: err.message }));
+ toast(t('recovery.fetchFailed', { msg: err.message }), 'error');
}
};
return (
-
🔑 {t('recovery.title')}
+
{t('recovery.title')}
{t('recovery.desc')}
-
-
+
+
{t('recovery.remaining', { count })}
{modal && (
-
{ if (e.target === e.currentTarget) setModal(null); }}>
+
{ if (e.target === e.currentTarget) closeModal(); }}>
-
setModal(null)}>×
+
{modal.isNew ? t('recovery.newCodes') : t('recovery.title')}
-
{t('recovery.saveWarning')}
+
{t('recovery.saveWarning')}
{modal.codes.map((c, i) => (
{c}
))}
-
+
)}
diff --git a/components/ReplyList.js b/components/ReplyList.js
index b31b7cd..220523a 100644
--- a/components/ReplyList.js
+++ b/components/ReplyList.js
@@ -7,6 +7,7 @@ import { useApp } from './AppProvider';
import { Icon } from './Icons';
import { renderMarkdown } from '@/lib/markdown';
import CaptchaImage from './CaptchaImage';
+import { useToast } from './Toast';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -15,6 +16,7 @@ function avatar(username) {
export default function ReplyList({ postId, onRefresh }) {
const { currentUser, openUser } = useApp();
+ const { toast, confirmAction } = useToast();
const [replies, setReplies] = useState([]);
const [content, setContent] = useState('');
const [captcha, setCaptcha] = useState(null);
@@ -31,10 +33,10 @@ export default function ReplyList({ postId, onRefresh }) {
useEffect(() => { setCaptcha(generateCaptcha()); }, [postId]);
const handleSubmit = async () => {
- if (!currentUser) { alert('请先登录'); return; }
- if (!content.trim()) { alert('请填写回复内容'); return; }
+ if (!currentUser) { toast('请先登录', 'warning'); return; }
+ if (!content.trim()) { toast('请填写回复内容', 'warning'); return; }
if (!captcha || parseInt(captchaInput) !== captcha.answer) {
- alert('验证码错误,请重新计算');
+ toast('验证码错误,请重新计算', 'warning');
setCaptcha(generateCaptcha());
setCaptchaInput('');
return;
@@ -48,17 +50,17 @@ export default function ReplyList({ postId, onRefresh }) {
load();
onRefresh();
} catch (err) {
- alert('回复失败:' + err.message);
+ toast('回复失败:' + err.message, 'error');
}
};
const handleDelete = async (replyId) => {
- if (!confirm('确定要删除这条回复吗?')) return;
+ if (!await confirmAction('确定要删除这条回复吗?')) return;
try {
await API.deleteReply(replyId);
load();
} catch (err) {
- alert('删除失败:' + err.message);
+ toast('删除失败:' + err.message, 'error');
}
};
@@ -69,7 +71,7 @@ export default function ReplyList({ postId, onRefresh }) {
{replies.length === 0 ? (
-
还没有回复,快来抢沙发吧 🛋️
+
还没有回复,快来发表第一条回复吧
) : (
replies.map((r) => {
const rTime = r.created_at ? new Date(r.created_at).toLocaleString('zh-CN') : '';
diff --git a/components/SettingsPage.js b/components/SettingsPage.js
index 0ca3f23..833b400 100644
--- a/components/SettingsPage.js
+++ b/components/SettingsPage.js
@@ -47,10 +47,10 @@ export default function SettingsPage() {
return (
-
+
{t('settings.title')}
-
+
{ if (e.target.files?.[0]) handleAvatar(e.target.files[0]); }} />
{currentUser?.username}
-
{bio || '这个人很懒,什么都没写'}
+
{bio || t('user.bioEmpty')}
{avatarStatus && (
-
{avatarStatus.msg}
+
{avatarStatus.msg}
)}
{/* 基本资料 */}
-
+
setUsername(e.target.value)} />
-
+
-
-
-
+
{/* 语言设置 */}
-
+