So, sometimes coding is a little bit of hitting ones head against a wall. I want to see the vote count and the rewards update on the webpage. Notifications come in that a vote has come in for my recent post. I am viewing the post because I have recently posted it but my vote count reads zero. Why?
For example the following indicates there is a notification, for a post that I posted. It is a vote. But the number of votes shown for the page shows zero.
I want the reward amount and the vote count to update when a notification comes that indicates a vote for the post provided the user is viewing it.
The easiest way to do this is to force a refresh. I want to force a refresh when ever this happens, at least when we aren't disturbing the page. It shouldn't happen while users are writing a reply which may disturb a reply being composed.
The React-Redux-Typescript system used by the source code centralizes code to a single state. But the data is separated in such a way that where the notifications get uploaded it cannot view which permlink (URL) the user is viewing. On the other hand, where the permlink can be viewed the entry data (the post entry data) is already a constant and where the entry data is constant, we cannot view the notification data. And trying to force reloading of the entry data when the notifications indicate a vote not already included has eluded success.
It is not that I am unable to reload the post, it is that componentDidUpdate() in the control src/common/pages/entry.tsx is not getting called when the notifications number gets indicated next to the user. It is not until I go click on and look at the notification list that it actually updates. That's annoying.
This is the code added to componentDidUpdate(), does anyone see the problems here?
// Update the vote counts if there are vote notifications not among the active votes.
// This algorithm can only detect when a user votes on the current opened post for the first time and the current opened post
// must be authored by the ActiveUser account. Changed votes will not be detected.
if ((!this.state.edit) && (notifications.unread !== prevProps.notifications.unread)) {
const active_votes = entry?.active_votes;
const notifications_of_votes_to_this: ApiVoteNotification[] = notifications.list.filter(
(notification) =>
notification.type === "vote" &&
`@${notification.author}` === username &&
notification.permlink === permlink
) as ApiVoteNotification[];
if (active_votes)
for (const n of notifications_of_votes_to_this) {
const thisAv = active_votes.find((av) => av.voter === n.voter);
if (thisAv) continue;
console.log(
"Forcing update due to notifications indicating votes not in the saved entry vote list."
);
this.setState({ isMounted: false });
this.ensureEntry();
break;
}
else {
// entry is not filled out yet.
// This routine will be called again once the
// entry is ready.
} // if-for-else
} // if
So that is all for now. I will try to research why I am unable to get this to fire at the right time or why these conditions are not allowing the reload to work or why the reload is unable to occur somehow...
Posted with proof of brain.... Prove your brain now.🧠🧠🧠