Skip to content

fix(client): get sound value from redux to play sound - #48107

Closed
nayabatir1 wants to merge 2 commits into
freeCodeCamp:mainfrom
nayabatir1:atir-issue-46372
Closed

nayabatir1 wants to merge 2 commits into
freeCodeCamp:mainfrom
nayabatir1:atir-issue-46372

Conversation

@nayabatir1

@nayabatir1 nayabatir1 commented Oct 17, 2022 •

Copy link
Copy Markdown
Contributor

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Closes #46372
Closes #48106

This 2nd method of solving issue.
Here I've removed localstorage dependency from playTone. Sound value is grabbed directly from redux and audio is played accordingly.

@nayabatir1
nayabatir1 requested review from a team, naomi-lgbt and ojeytonwilliams October 17, 2022 20:50
@gitpod-io

gitpod-io Bot commented Oct 17, 2022

Copy link
Copy Markdown

@github-actions github-actions Bot added the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Oct 17, 2022
@ghost

ghost commented Oct 17, 2022 •

Copy link
Copy Markdown

👀 Review this PR in a CodeSee Review Map

View the CodeSee Map of this change

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@nayabatir1 nayabatir1 changed the title fix(bug): campfire audio issue fix fix(bug): campfire audio play on multiple browser Oct 17, 2022
@majestic-owl448

Copy link
Copy Markdown
Contributor

@raisedadead raisedadead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are you re-arranging the unrelated imports?

Other than that, I like the idea of not needing to use the localStorage, but others are better qualified to confirm.

Comment thread client/src/utils/tone/index.ts Outdated
@@ -1,4 +1,5 @@
import store from 'store';
import * as Tone from 'tone';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
import * as Tone from 'tone';

What's the rationale for this change? We deliberately do not statically import tone because it's a large library that not all users need to view the site.

@nayabatir1 nayabatir1 Oct 18, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used this way of import b'cuz it is mentioned in npm. I've also checked bundle size
image

I did some research and found a better way to import is import { loaded, Player } from 'tone';.
Taking advantage of tree shaking.
If it seem fit I can change it or revert back to previous way importing.

@nayabatir1 nayabatir1 changed the title fix(bug): campfire audio play on multiple browser fix(bug): get sound value from redux to play sound Oct 18, 2022
@nayabatir1

Copy link
Copy Markdown
Contributor Author

Please take a moment to give a name to the PR that follows the guidelines: https://contribute.freecodecamp.org/#/how-to-open-a-pull-request?id=prepare-a-good-pr-title

I've updated pr title

@nayabatir1

nayabatir1 commented Oct 18, 2022 •

Copy link
Copy Markdown
Contributor Author

I did some research and found that audio can be played without any dependency. I think we should definitely use this method

const audio = new Audio(toneUrls[state]);

const storedVolume = (store.get('soundVolume') as number) ?? 50;
const calculateDecibel = storedVolume / 100;

audio.volume = calculateDecibel;

await audio.play();

@nayabatir1 nayabatir1 closed this Oct 18, 2022
@nayabatir1 nayabatir1 reopened this Oct 18, 2022
@majestic-owl448 majestic-owl448 changed the title fix(bug): get sound value from redux to play sound fix(client): get sound value from redux to play sound Oct 18, 2022
@raisedadead

raisedadead commented Oct 18, 2022 •

Copy link
Copy Markdown
Member

You do not need to work on the other PR (the other solution). Just wait on some conclusive comments from others.

This is likely the version we want. You are welcome to hang on to the other if you prefer - but if there is anything the maintainers like, that is less noise.

@nayabatir1

Copy link
Copy Markdown
Contributor Author

You do not need to work on the other PR (the other solution). Just wait on some conclusive comments from others.

This is likely the version we want. You are welcome to hang on to the other if you prefer - but if there is anything the maintainers like, that is less noise.

Sorry if it bothers you.
I found a better solution so I thought why not implement it.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

#48106 (review) applies here, too. I hadn't realised there were two PRs solving the same issue.

I found a better solution so I thought why not implement it.

The reason is that small, focused PRs are easier to understand. This makes it easier for reviewers to see if there are any issues that need to be addressed before merging. Also, if we later find that there are problems, it's easier to debug them.

@raisedadead

raisedadead commented Oct 18, 2022 •

Copy link
Copy Markdown
Member

Sorry if it bothers you.

That's not the problem.

The issue is you have two PRs, making it hard for multiple people to review your work. You may be working on a couple of issues; the maintainers deal with a dozen PRs. It is easy for us to lose context.

We get that you have two different approaches, and the simplest thing to do in such cases would be to keep the discussion on the most favored approach (this PR) and not work on the other one until you are asked to.

It would have been even better to get a confirmation on the main issue before you started – but we are past that.

Let's focus on working on the review of this PR.

@naomi-lgbt

Copy link
Copy Markdown
Member

I did some research and found that audio can be played without any dependency. I think we should definitely use this method

The purpose of using Tone specifically was the ability to easily generate dynamic audio in the editor - while it would be possible to do so with the raw Audio context, IMHO it's not worth the overhead.

@nayabatir1

Copy link
Copy Markdown
Contributor Author

@ojeytonwilliams can I create checkout of this branch for removing tone package. Checkout of main branch will result in merge conflict as both branch modify same function playTone

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Sorry, @nayabatir1, I hadn't realised why we were using Tone specifically. @naomi-lgbt understands this issue better than I do, so I will defer to her.

For this PR, please could you keep the changes to those needed to fix the original issue, #46372? There's no need to re-arrange the imports or change to statically importing to address that.

@nayabatir1
nayabatir1 requested review from ojeytonwilliams and removed request for naomi-lgbt October 18, 2022 22:01
@raisedadead raisedadead added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 26, 2022

@naomi-lgbt naomi-lgbt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because the logic to check store has been removed from playTone, there are a few different areas where we'll need to check the user's settings:

  • client/src/components/Donation/donation-modal.tsx
  • client/src/components/Flash/redux/index.ts
  • client/src/components/settings/sound.tsx
  • client/src/templates/Challenges/redux/execute-challenge-saga.js

@naomi-lgbt naomi-lgbt added status: waiting update Is awaiting update, after feedback or request for changes and removed status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. labels Oct 28, 2022
@nayabatir1

Copy link
Copy Markdown
Contributor Author

@naomi-lgbt I looked into all the mentioned files.
All functions must be converted to React components in order to access redux store values.
For simplicity, I think we should consider this pr

@naomi-lgbt

Copy link
Copy Markdown
Member

We can certainly consider that approach, though we'd need to not remove Tone in the process.

@nayabatir1

Copy link
Copy Markdown
Contributor Author

We can certainly consider that approach, though we'd need to not remove Tone in the process.

@naomi-lgbt I've updated pr.

@raisedadead raisedadead closed this Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. status: waiting update Is awaiting update, after feedback or request for changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Campfire Mode doesn't trigger on multiple browsers unless you turn it on and off

5 participants