add anc button to navbar

This commit is contained in:
2025-10-23 20:55:03 +08:00
parent abd4aaac7c
commit c40a899d15
2 changed files with 45 additions and 6 deletions

View File

@@ -14,7 +14,11 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks.ts";
import { getAnnouncement } from "../../redux/thunks/site.ts";
import SessionManager from "../../session";
const AnnouncementDialog = () => {
interface AnnouncementDialogProps {
forceOpen?: boolean;
}
const AnnouncementDialog = ({ forceOpen = false }: AnnouncementDialogProps) => {
const { t } = useTranslation("common");
const dispatch = useAppDispatch();
const announcement = useAppSelector((state) => state.siteConfig.basic.config.announcement || "");
@@ -55,11 +59,22 @@ const AnnouncementDialog = () => {
const timer = setTimeout(() => setOpen(true), 1000);
return () => clearTimeout(timer);
} else {
// 确保当不应该显示时关闭弹窗
setOpen(false);
// 确保当不应该显示且没有强制打开时关闭弹窗
if (!forceOpen) {
setOpen(false);
}
}
}, [announcement, announcementEnabled, lastAnnouncement]);
// 处理外部强制打开
useEffect(() => {
if (forceOpen && announcement && announcement.trim() !== "") {
setOpen(true);
// 重置不再显示选项
setDontShowAgain(false);
}
}, [announcement, announcementEnabled, lastAnnouncement, forceOpen]);
const handleClose = () => {
if (dontShowAgain) {
// 保存用户选择不再显示
@@ -90,4 +105,6 @@ const AnnouncementDialog = () => {
);
};
// 导出一个可以被外部组件控制的版本
export { AnnouncementDialog };
export default AnnouncementDialog;