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

Fix privacy opt-out button not clickable #3818

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yk-tuturu
Copy link
Contributor

Context

closes #3254

Implementation

following instructions detailed in issue #3254, implemented checks to see if matomo is initialized and disables the privacy toggle if blocked by an ad-blocker

Other Information

Copy link

vercel bot commented Sep 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nusmods-export ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 10:34am
nusmods-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 10:34am

Copy link

vercel bot commented Sep 4, 2024

@yk-tuturu is attempting to deploy a commit to the modsbot's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@ravern ravern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I am able to see your fix as intended — the toggle is set to "Opt-out" and disabled if matomo is not initialised.

While I think your solution fulfils the original comment made by an earlier maintainer, I think that adding a hook is unnecessary (and an incorrect usage of React hooks, see this comment).

I think the crux of this issue is if matomo is undefined, the opt-out toggle cannot be clicked, leading the user to believe that they cannot opt-out of the tracking, when in fact there is no tracking at all.

The current code that modifies the UI component actually already fixes this issue, and the addition of the hook is unnecessary. I think if we reverse the changes to the hook portion of this PR, it will LGTM.

Comment on lines -39 to +40
export function initializeMamoto() {
export function initializeMatomo() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 24 or 25 of this same file, there's the same mispelling of Matomo, can we fix that as well?

Comment on lines +82 to +90
export function useMatomo() {
// need to use useState here or the matomo returned will always be undefined
const [matomoCopy, setMatomoCopy] = useState<Tracker | undefined>(undefined);
useEffect(() => {
setMatomoCopy(matomo);
}, [matomo]);

return matomoCopy;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the following code:

useEffect(() => {
    setMatomoCopy(matomo);
  }, [matomo]);

This effect is only ever called once (on component mount) since the matomo variable exists outside of the React context. This is reflected by the linter as well:

React Hook useEffect has an unnecessary dependency: 'matomo'. Either exclude it or remove the
dependency array. Outer scope values like 'matomo' aren't valid dependencies because mutating
them doesn't re-render the component.

Copy link
Member

@ravern ravern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove hook

@ravern ravern changed the title fixed privacy opt-out button not clickable issue Fix privacy opt-out button not clickable Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Privacy Opt-Out not clickable
2 participants