-
Notifications
You must be signed in to change notification settings - Fork 196
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
New updates toast message only when button is displayed #5306
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5306 +/- ##
=======================================
Coverage 99.17% 99.17%
=======================================
Files 235 236 +1
Lines 9345 9354 +9
Branches 2241 2241
=======================================
+ Hits 9268 9277 +9
Misses 77 77
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
bafdba2
to
cce0dd7
Compare
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.
Getting real close here, I think!
I had a couple of suggestions...
useEffect(() => { | ||
if (hasPendingUpdates) { | ||
toastMessenger.success( | ||
`There are ${pendingUpdateCount} new annotations.`, |
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.
Because we will only announce once and not again until any additional annotations are loaded in, I think we might consider not announcing the specific count, as it may not be accurate by the time the user loads in the annotations.
`There are ${pendingUpdateCount} new annotations.`, | |
`New annotations are available`, |
This will read better when it can be followed with "Press (whatever) to load these annotations". And even better down the line when we can confirm with "X new annotations loaded".
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.
BTW, I see now why you were a little ambivalent about adding a hasPendingUpdates
selector, since this component also needs pendingUpdateCount
. But I still think it's fine...
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.
BTW, I see now why you were a little ambivalent about adding a hasPendingUpdates selector, since this component also needs pendingUpdateCount. But I still think it's fine...
Yes. I mean, we could have a locally memoized flag which depends on the amount. Something in these lines:
const hasPendingUpdates = useMemo(() => pendingUpdateCount > 0, [pendingUpdateCount]);
But if we are going to do that we may as well have the selector, which is easier to reason about and can be used somewhere else if needed.
src/sidebar/components/TopBar.tsx
Outdated
}`} | ||
/> | ||
)} | ||
<PendingUpdatesButton onClick={applyPendingUpdates} /> |
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.
Given that PendingUpdatesButton
is already pretty self sufficient and makes use of the toastMessengerService
, I wonder if you might go ahead and inject the streamer
service into it, and free TopBar
from having to know about streamer
. Thoughts?
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.
Good point!
// We only want this effect to trigger when changing from no-updates to at | ||
// least one update, not every time the amount changes | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
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.
I think this may be out of date. Can you check the dependencies here?
Thanks @lyzadanger! All suggestions pushed. |
@acelaya In the hopes that this will make your testing strategy easier: you don't have to use different devices to test this feature. All you need is a separate session (browser profile, different browser, e.g.). For example, here is a screen shot of me using:
I hope this makes your life a little easier? (Safari here is on top of the Chrome session) Edited: Oh wait, I think I get it. It's not possible to retain focus on the iframe that would announce the pending update in this setup. Disregard! |
Exactly 😅. I used this approach at first, but I had to end up adding a small timeout to dispatching the reduce action so that I had time to go back to the main window before it got actually dispatched, otherwise the screen reader would not announce anything. At some point it became cumbersome to have to remember which file needed to be excluded from commits, plus I realized I was not testing the real behavior and thought I might miss something. That's when I moved to use two devices. |
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.
SO so so so so so close! Looking good! There is one thing I'd like to address: ToastMessageItem
will prefix success
or error
toast messages with the word Success:
or Error:
respectively. If you set the message as a notice
type, it shouldn't do that prefixing (right now, the word Success:
is announced as part of the message: let's get rid of that). I think these are "notice" type messages, anyway.
Everything else is working great...let's get this done!
toastMessenger: ToastMessengerService; | ||
streamer: StreamerService; |
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.
World's teensiest nit: I tend to alphabetize injected service props.
@@ -217,6 +217,17 @@ function hasPendingDeletion(state, id) { | |||
return hasOwn(state.pendingDeletions, id); | |||
} | |||
|
|||
/** | |||
* Return true if an annotation has been created on the server, but it has not | |||
* yet been applied. |
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.
The wording "applied" is somewhat vague. I imagine you derived this comment from elsewhere: don't worry about it for now, and I can see why applied could make sense (I mean, the annotations are loaded already in a sense...). This makes me realize that I should familiarize myself with the flow of "pending" annotations a little better: then I might be able to provide a suggestion...
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.
Yes, I kept "applied" for consistency with other comments, but it was not super obvious to me neither, to be honest. I wouldn't mind finding a better wording.
c74451f
to
ac096f8
Compare
@lyzadanger changed to use |
ac096f8
to
61b34e7
Compare
61b34e7
to
5e64dc2
Compare
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.
All righty, let's get this landed!
This PR changes the logic introduced in #5305 to make sure the message is toasted only when pending updates goes from 0 to a value greater than zero, which effectively means it is toasted when the button to refresh notifications is displayed.
If for any reason the pending notifications are increased before the notifications are refreshed, this prevents the message to be toasted again, which might be overwhelming on documents with a lot of activity.
Testing steps:
localhost:3000
.