Skip to content
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

User Labels - Voting a comment make the labels disappear #8

Closed
theCrius opened this issue Jun 8, 2018 · 6 comments
Closed

User Labels - Voting a comment make the labels disappear #8

theCrius opened this issue Jun 8, 2018 · 6 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@theCrius
Copy link
Owner

theCrius commented Jun 8, 2018

Report from the user apoctr:

I think I've found a bug - if you vote on the comment of someone you've labelled, their label disappears.

Apparently whenever a vote is casted, the whole comment is being sent back as response instead of just a json data that update the view.

image

I suppose I can try and intercept the click on the vote button and rebuild the label for that comment.

@theCrius theCrius added the bug Something isn't working label Jun 8, 2018
@theCrius theCrius self-assigned this Jun 8, 2018
@theCrius
Copy link
Owner Author

theCrius commented Jun 9, 2018

As a workaround I'm refreshing the labels after 500msec for now.
Not really a solution I'm proud of. What I would have done is to listen for XHR requests and detect a response received but apparently either it doesn't work with browser extension injected code or tildes.net use masked request.

It's a weird way, from tildes, to reload a whole object anyway when simply voting. I would have expected at most that the object received back was the 'vote button' or just the updated vote counts.

@theCrius theCrius closed this as completed Jun 9, 2018
@odensc
Copy link
Contributor

odensc commented Jun 9, 2018

@theCrius You can use MutationObserver to listen for updates to the DOM of the comment. I could submit a PR for this if you're not familiar with the API.

@theCrius
Copy link
Owner Author

theCrius commented Jun 9, 2018

I didn't think about the MutationObserver... that'll teach me to not code late at night :(

However I never used it but I created this project to try stuff I never used! I'll give it a look and update this issue in case I've issue, thanks!

@theCrius theCrius reopened this Jun 9, 2018
@theCrius
Copy link
Owner Author

theCrius commented Jun 9, 2018

Mhm, something's not right.

I've wrote a basic observer to detect changes:

const clog = console.log.bind(console);
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

const observer = new MutationObserver(mutations => {
  clog('something changed', mutations);
});

observer.observe(document.body, {
	attributes: true,
	childList: true,
	characterData: true
});

But while it detect changes on the page load, it doesn't detect changes when I click on a vote button.

If you feel like wasting some time on it, I'll appreciate a pull request (or if you can point out where I'm doing it wrong as well!)

I'm afraid it has something to do with intercooler.js on tildes.

@theCrius theCrius added the help wanted Extra attention is needed label Jun 9, 2018
@theCrius theCrius added this to High Priority in Tildes Extended Jun 9, 2018
@theCrius theCrius moved this from High Priority to In progress in Tildes Extended Jun 9, 2018
@odensc
Copy link
Contributor

odensc commented Jun 10, 2018

I'll take a look.

theCrius added a commit that referenced this issue Jun 11, 2018
Fix #8 using MutationObserver
@theCrius
Copy link
Owner Author

31bec8a

Clean up and deal with missing node to observe (for page with no comments)

@theCrius theCrius moved this from In progress to Done in Tildes Extended Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
Development

No branches or pull requests

2 participants