-
Notifications
You must be signed in to change notification settings - Fork 200
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
How to make a notification appear only once #118
Comments
Add a cookie on each path that your user have visited, so if they returns back again to the page that includes the cookie you can prevent notyf from appear |
@nd3w you can utilize globalThis.localStorage API to track notifications you've already pushed As well as Read the stored log from import { crc32_str as crc32 } from 'https://cdn.sheetjs.com/crc-32-latest/package/crc32.mjs'
/* ... Some subroutines ... */
/* The id of log record in localStorage */
const logId = 'notyfLog'
/* Message to be pushed */
const message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
/* Digest of the above message to be utilized as key below */
const digest = crc32(message)
const type = 'success'
const logRecord = { /* Track data on message to be pushed */
type,
message,
postedAt : null
} /* And any other info you'd like to log, unlimited */
/* ... Another subroutines ... */
/* Time to push message. Retrieving full log from localStorage */
const log = JSON.decode(localStorage.getItem(logId) ?? '{}')
/**
* . Let log object be like
*
* {
*. cbb14041 : {
* type : 'error',
* message : 'Phasellus eu vulputate justo, et placerat erat. Proin odio ex, ornare in ante ac',
* postedAt : 1669643082
* },
* a657f58c : {
* type : 'warning',
* message : 'Vestibulum pellentesque sed mi ut bibendum. Morbi odio quam, posuere',
* postedAt : 1606571082
* }
* }
*
*/
/* Pushing message only if it has not been already pushed */
if (!Object.keys(log).includes(digest)) {
/* Pushing message */
notyf.open({ type, message })
/* Timestamp when message has been pushed */
logRecord.postedAt = Date.now()
/* Storing record of pushed message to log */
log[digest] = logRecord
/* Putting the whole updated log back to localStorage */
localStorage.setItem(logId, JSON.stringify(log))
}
/* ... More subroutines ... */ You can find a nice clean guide for Bugs free coding! |
How do I make a notif appear only once? When I went back from another page, the notif was appearing again.
The text was updated successfully, but these errors were encountered: