mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-06 18:06:36 +08:00
9a85363e44
* docs: add announcement popup design spec * docs: add announcement popup implementation plan * feat(api): include update_time in announcement response * feat(ui): add update_time to AnnouncementData interface * feat(ui): create AnnouncementModal component * feat(ui): manage announcement modal state in dashboard hook * feat(ui): add announcement modal to dashboard layout
2.6 KiB
2.6 KiB
Announcement Popup Notification Design
Overview
This feature implements a popup notification modal for important dashboard announcements to ensure users see them immediately, addressing GitHub Issue #169.
Requirements
- Automatic display of a popup modal when opening the dashboard page if a new/updated announcement exists.
- Includes a "Don't show again" option to remember the user's choice to dismiss it.
- Smart triggering: Only pops up for new or updated announcements.
- Support Markdown formatting for the announcement content.
- Retain the existing permanent top banner as a fallback.
Backend Changes (Go)
The /api/v1/announcement/get API currently only returns content and enabled. It must be updated to return the timestamp of the last update to enable the frontend to detect changes.
- Repository (
internal/store/repo/repository.go): EnsureGetAnnouncementretrievesUpdatedTime(or falls back toCreatedTime). - Handler (
internal/http/handler/handler.go): ModifygetAnnouncementto include anupdate_time(int64) field in its JSON response.
Frontend Changes (Vite/React/Tailwind)
- API Interface (
src/api/index.ts):- Update
AnnouncementDatato includeupdate_time: number.
- Update
- Storage Mechanism:
- Use browser
localStorageto persist the user's view state. Key:flvx_announcement_seen_time.
- Use browser
- UI Component (
AnnouncementModal):- Create a new modal component for the dashboard.
- The modal content will render the markdown of the announcement.
- It will feature two primary actions:
- "Close": Closes the modal temporarily for this session (does NOT update
localStorage). It will pop up again on the next page load. - "Don't show again": Closes the modal AND sets
localStorage.setItem('flvx_announcement_seen_time', announcement.update_time).
- "Close": Closes the modal temporarily for this session (does NOT update
- Integration (
src/pages/dashboard.tsx&use-dashboard-data.ts):- Add state to manage the modal visibility (e.g.,
isAnnouncementModalOpen). - On data load, compare the fetched
update_timewith the storedflvx_announcement_seen_time. If the fetched time is greater (or if no stored time exists), setisAnnouncementModalOpen(true).
- Add state to manage the modal visibility (e.g.,
Error Handling and Edge Cases
- If
localStorageis unavailable or throws an error (e.g., Private Browsing mode restrictions), the modal may show repeatedly. The code should safely catchlocalStorageaccess errors. - If
update_timeis missing from an old database record, the backend should gracefully fall back to the creation time or a safe default (like 0) to ensure the logic doesn't break.