feat: toast notifications, canvas captcha, super admin, mobile fixes

- Toast system (ToastProvider + useToast): right-top colored toasts
  replace alert for publish success/error; CSS + layout mount
- Captcha as canvas image (noise + distortion) in NewPost/ReplyList/
  register modal — blocks bots, click to refresh
- Super admin: first registered user cannot be demoted (isFirstUser by
  created_at, DB-agnostic)
- Admins can delete others' posts/replies (UI buttons shown for admin)
- Mobile: post-actions wrap + compact, feed excerpt 2.5 lines
- Fix: missing sun icon in Icons (dark mode toggle showed nothing)
- Feed long posts: gradient fade mask instead of line-clamp
This commit is contained in:
lezi-fun committed 2026-08-10 21:54:28 +08:00
1 parent e860978aef
commit b2368f68df
12 files changed
+262 -31

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
'use client';
// Toast 通知系统:右上角弹出,自动消失(替代 alert)
// 用法:const { toast } = useToast(); toast('发布成功', 'success');
import { createContext, useContext, useState, useCallback, useRef } from 'react';
import { createPortal } from 'react-dom';
const ToastContext = createContext(null);
export function useToast() {
return useContext(ToastContext);
}
let idCounter = 0;
export function ToastProvider({ children }) {
const [toasts, setToasts] = useState([]);
const timersRef = useRef({});
const toast = useCallback((message, type = 'success', duration = 3000) => {
const id = ++idCounter;
setToasts((prev) => [...prev, { id, message, type }]);
if (timersRef.current[id]) clearTimeout(timersRef.current[id]);
timersRef.current[id] = setTimeout(() => {
setToasts((prev) => prev.filter((t) => t.id !== id));
delete timersRef.current[id];
}, duration);
}, []);
const dismiss = useCallback((id) => {
setToasts((prev) => prev.filter((t) => t.id !== id));
if (timersRef.current[id]) { clearTimeout(timersRef.current[id]); delete timersRef.current[id]; }
}, []);
return (
<ToastContext.Provider value={{ toast }}>
{children}
{typeof document !== 'undefined' && createPortal(
<div className="toast-container">
{toasts.map((t) => (
<div key={t.id} className={'toast toast-' + t.type} onClick={() => dismiss(t.id)}>
{t.message}
</div>
))}
</div>,
document.body
)}
</ToastContext.Provider>
);
}