-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine Modal Display Logic to Only Show on First Visit (SnapshotNotifyModal) #1644
base: staging
Are you sure you want to change the base?
Conversation
WalkthroughThe recent update introduces a new modal component, Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (2)
- src/components/_modals/SnapshotNotifyModal..tsx (1 hunks)
- src/pages/index.tsx (1 hunks)
Additional comments not posted (2)
src/components/_modals/SnapshotNotifyModal..tsx (2)
8-10
: Consider removing theuseEffect
hook if it's not being utilized for any specific logic, such as analytics or side effects based on theisOpen
state.
18-26
: Ensure the link colorwhite.500
is accessible and provides sufficient contrast against the modal's background for all users.
useEffect(() => { | ||
const modalShown = localStorage.getItem("modalShown") | ||
if (!modalShown) { | ||
setIsModalOpen(true) | ||
localStorage.setItem("modalShown", "true") | ||
} | ||
}, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that accessing localStorage
directly in the useEffect
hook does not cause any issues during server-side rendering (SSR) in Next.js applications. Consider checking if the window object is defined before accessing localStorage
.
useEffect(() => {
+ if (typeof window !== "undefined") {
const modalShown = localStorage.getItem("modalShown")
if (!modalShown) {
setIsModalOpen(true)
localStorage.setItem("modalShown", "true")
}
+ }
}, [])
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
useEffect(() => { | |
const modalShown = localStorage.getItem("modalShown") | |
if (!modalShown) { | |
setIsModalOpen(true) | |
localStorage.setItem("modalShown", "true") | |
} | |
}, []) | |
useEffect(() => { | |
if (typeof window !== "undefined") { | |
const modalShown = localStorage.getItem("modalShown") | |
if (!modalShown) { | |
setIsModalOpen(true) | |
localStorage.setItem("modalShown", "true") | |
} | |
} | |
}, []) |
|
||
const Home: NextPage = () => { | ||
return <PageHome /> | ||
const [isModalOpen, setIsModalOpen] = useState(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider initializing isModalOpen
state based on the localStorage
value to avoid unnecessary re-renders.
- const [isModalOpen, setIsModalOpen] = useState(false)
+ const [isModalOpen, setIsModalOpen] = useState(() => typeof window !== "undefined" && !localStorage.getItem("modalShown"))
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const [isModalOpen, setIsModalOpen] = useState(false) | |
const [isModalOpen, setIsModalOpen] = useState(() => typeof window !== "undefined" && !localStorage.getItem("modalShown")) |
This ticket addresses the repetitive display of the SnapshotNotifyModal on every home page visit. The fix involves modifying the modal's visibility logic to only appear on the user's first visit, using localStorage to track this state. The expected outcome is to enhance user experience by reducing redundancy and ensuring the modal is only shown once. Implementation includes updating the React state logic in the Home component and ensuring proper prop handling for isOpen and onClose. Testing will verify the modal's one-time appearance per browser session and its absence on subsequent visits.
Summary by CodeRabbit