-
Notifications
You must be signed in to change notification settings - Fork 975
Fixes publisher toggle (heart), button enables after time requirements satisfied. #13900
Conversation
WIP has been removed, I may have a way to eliminate the use of setTimeout |
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 this error:
"Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the PublisherToggle component.", source: http://localhost:8080/gen/app.entry.js (5816)
// page visit has started recording. It is important that a | ||
// page data update is not triggered before this has happened. | ||
const topSitesWait = ledgerUtil.milliseconds.second * 6 | ||
const updateWait = ledgerUtil.milliseconds.second * 3 |
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.
could we instead of triggering this every 3s, trigger this only after MIN_VISIT_TIME
?
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.
also we have min count, so that means if you set this for 10, you need to visit this site 10 times. Maybe we should only add this timer if this visit would hit this minimum. This means that we would not add timer until you have 9 visits already logged and this is your 10 visit. Only in this case we would add timer, which would be min visit time
@ryanml wdyt?
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 approach would be a lot more efficient yes, especially for minimums with multiple visits. It only would not work for one scenario:
Suppose your minimums are 1 visit for 1 minute, and you've made one visit but only for 41 seconds. Visiting the site again with this approach you'd have to wait 60 seconds for the full MIN_VISIT_TIME to pass.
To get around that, maybe we could calculate the time remaining, (In the above scenario, calculate 60000 - 41000 = 19000 and set the timeout to 19000). Does that sound agreeable?
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 let's do that
@@ -32,6 +32,7 @@ const fundUnverifiedPublisherImage = require('../../../extensions/brave/img/urlb | |||
class PublisherToggle extends React.Component { | |||
constructor (props) { | |||
super(props) | |||
this.mounted = 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.
Thanks for fixing 👍
// page visit has started recording. It is important that a | ||
// page data update is not triggered before this has happened. | ||
const topSitesWait = ledgerUtil.milliseconds.second * 6 | ||
const updateWait = ledgerUtil.milliseconds.second * 3 |
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 approach would be a lot more efficient yes, especially for minimums with multiple visits. It only would not work for one scenario:
Suppose your minimums are 1 visit for 1 minute, and you've made one visit but only for 41 seconds. Visiting the site again with this approach you'd have to wait 60 seconds for the full MIN_VISIT_TIME to pass.
To get around that, maybe we could calculate the time remaining, (In the above scenario, calculate 60000 - 41000 = 19000 and set the timeout to 19000). Does that sound agreeable?
99ce0c3
to
5b1043a
Compare
@NejcZdovc changes pushed, ready to review. The correct calculations should now be in place so an update is only triggered when it needs to. |
3e19cb6
to
ec69a3c
Compare
app/common/lib/ledgerUtil.js
Outdated
@@ -591,6 +592,45 @@ const getMediaProvider = (url, firstPartyUrl, referrer) => { | |||
return provider | |||
} | |||
|
|||
const shouldSetTimeout = (publisherKey) => { |
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.
Please rename this to something more verbose like hasRequiredVisits
app/common/lib/ledgerUtil.js
Outdated
return (visitDifference === 1) | ||
} | ||
|
||
const getTimeoutWait = (publisherKey) => { |
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.
Please rename this to something more verbose like getRemainingRequiredTime
app/common/lib/ledgerUtil.js
Outdated
const publisher = ledgerState.getPublisher(appStore.state, publisherKey) | ||
const publisherVisits = publisher.get('visits') | ||
|
||
if (publisherVisits === undefined) { |
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.
Can we just check here if publisherVisits
is number?
app/common/lib/ledgerUtil.js
Outdated
const publisherDuration = publisher.get('duration') | ||
|
||
if ( | ||
publisherDuration === undefined || |
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.
Can we just check here if publisherDuration
is number?
@ryanml please add tests |
Codecov Report
@@ Coverage Diff @@
## master #13900 +/- ##
==========================================
+ Coverage 56.45% 56.49% +0.03%
==========================================
Files 284 284
Lines 29220 29302 +82
Branches 4851 4864 +13
==========================================
+ Hits 16495 16553 +58
- Misses 12725 12749 +24
|
9965ee5
to
387517a
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.
works great, after tests are added we can merge it
387517a
to
3415463
Compare
9c8759e
to
a78d744
Compare
@NejcZdovc tests added |
a78d744
to
486c0d5
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.
++ works great
Fixes publisher toggle (heart), button enables after time requirements satisfied.
Fixes publisher toggle (heart), button enables after time requirements satisfied.
Fixes #12675
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
Tests
Given that there didn't seem to be an appropriate appConstant (or a relatively efficient/telling new one that could be made), it seems to make sense for the Publisher Toggle component to have an attribute of its internal state that can check its ledger status at an interval.
Currently, the interval avoids starting until after APP_TOP_SITE_DATA_AVAILABLE has dispatched. Doing this call to pageDataChanged before that action can break ledger activity recorder.
The interval will clear once the publisher toggle has reached an enabled state (there's no way for a site to become disabled merely by browsing, so this interval does not concern that path), any time the publisherToggle component dismounts, and reset if the tab loads to a new potential publisher.