🐛 fix(home): prevent empty notice modal from auto-showing
Previously, the notice modal would automatically show every day even when the notice content was empty, causing unnecessary user interruption. This commit modifies the logic to: - Check notice content before showing the modal - Only display the modal when notice content exists and is not empty - Add proper error handling to prevent modal showing on API failures - Improve user experience by avoiding empty notice interruptions Changes: - Modified useEffect in Home component to fetch notice content first - Added API call to /api/notice before setting noticeVisible state - Added try-catch block for graceful error handling - Only show modal when notice data is truthy and non-empty after trimming
This commit is contained in:
@@ -22,11 +22,23 @@ const Home = () => {
|
||||
const isDemoSiteMode = statusState?.status?.demo_site_enabled || false;
|
||||
|
||||
useEffect(() => {
|
||||
const lastCloseDate = localStorage.getItem('notice_close_date');
|
||||
const today = new Date().toDateString();
|
||||
if (lastCloseDate !== today) {
|
||||
setNoticeVisible(true);
|
||||
}
|
||||
const checkNoticeAndShow = async () => {
|
||||
const lastCloseDate = localStorage.getItem('notice_close_date');
|
||||
const today = new Date().toDateString();
|
||||
if (lastCloseDate !== today) {
|
||||
try {
|
||||
const res = await API.get('/api/notice');
|
||||
const { success, data } = res.data;
|
||||
if (success && data && data.trim() !== '') {
|
||||
setNoticeVisible(true);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取公告失败:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
checkNoticeAndShow();
|
||||
}, []);
|
||||
|
||||
const displayHomePageContent = async () => {
|
||||
|
||||
Reference in New Issue
Block a user