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

Events #4

Merged
merged 3 commits into from Mar 17, 2022
Merged

Events #4

merged 3 commits into from Mar 17, 2022

Conversation

Kakalanp
Copy link
Owner

@Kakalanp Kakalanp commented Mar 16, 2022

  • Adding big.js.
  • Adding functions provided by Microverse for the calculator to work.
  • Adding event handlers to the calculator buttons.
  • Adding a pair of comments for better readability.
  • Adding a sorting algorithm that creates buttons from an array and adds class names accordingly.

Copy link

@Gambit142 Gambit142 left a comment

Choose a reason for hiding this comment

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

Hi @Kakalanp 👋,

Good job so far!

Highlights

  • Linters checks passed ✔️
  • Correct use of logic files ✔️

However, there are some issues that you still need to work on to go to the next project but you are almost there!

Required Changes ♻️

KIndly check the comments under the review.

Optional suggestions

Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.

You can also consider the optional change I suggested.

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

Comment on lines 5 to 16
export default function Calculator() {
const [total, setTotal] = useState(0);
const [next, setNext] = useState(null);
const [operation, setOperation] = useState(null);

function clickHandler(e) {
const result = calculate({ total, next, operation }, e.target.textContent);
setTotal(result.total);
setNext(result.next);
setOperation(result.operation);
}

Copy link

@Gambit142 Gambit142 Mar 16, 2022

Choose a reason for hiding this comment

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

  • Nice work done on this project. Your Calculator component should be a class-based component for now. There is nothing wrong with how you have it now, but the project requirements state that you should use React Lifecycle methods. The only way you can use a lifecycle method is by turning your component into a class-based component. You can read this article to have an idea of how to use lifecycle methods. 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

I completely missed that requirement, I just did the refactoring, thanks! 😁

Comment on lines 28 to 83
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>AC</p>
</div>
<div className={styles.calculator__button__grey}>
<p>+/-</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>+/-</p>
</div>
<div className={styles.calculator__button__grey}>
<p>%</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>%</p>
</div>
<div className={styles.calculator__button__orange}>
<p>÷</p>
<div className={styles.calculator__button__orange} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>÷</p>
</div>
<div className={styles.calculator__button__grey}>
<p>7</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>7</p>
</div>
<div className={styles.calculator__button__grey}>
<p>8</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>8</p>
</div>
<div className={styles.calculator__button__grey}>
<p>9</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>9</p>
</div>
<div className={styles.calculator__button__orange}>
<p>x</p>
<div className={styles.calculator__button__orange} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>x</p>
</div>
<div className={styles.calculator__button__grey}>
<p>4</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>4</p>
</div>
<div className={styles.calculator__button__grey}>
<p>5</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>5</p>
</div>
<div className={styles.calculator__button__grey}>
<p>6</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>6</p>
</div>
<div className={styles.calculator__button__orange}>
<p>-</p>
<div className={styles.calculator__button__orange} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>-</p>
</div>
<div className={styles.calculator__button__grey}>
<p>1</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>1</p>
</div>
<div className={styles.calculator__button__grey}>
<p>2</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>2</p>
</div>
<div className={styles.calculator__button__grey}>
<p>3</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>3</p>
</div>
<div className={styles.calculator__button__orange}>
<p>+</p>
<div className={styles.calculator__button__orange} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>+</p>
</div>
<div className={`${styles.calculator__button__grey} ${styles.calculator__button__zero}`}>
<p>0</p>
<div className={`${styles.calculator__button__grey} ${styles.calculator__button__zero}`} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>0</p>
</div>
<div className={styles.calculator__button__grey}>
<p>.</p>
<div className={styles.calculator__button__grey} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>.</p>
</div>
<div className={styles.calculator__button__orange}>
<p>=</p>
<div className={styles.calculator__button__orange} onClick={clickHandler} onKeyPress={(e) => { if (e.key === 'Enter') clickHandler(); }} role="button" tabIndex={0}>
<p style={{ userSelect: 'none' }}>=</p>
Copy link

@Gambit142 Gambit142 Mar 16, 2022

Choose a reason for hiding this comment

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

  • (Optional) You can put all the symbols and numbers in an array as strings, then map through the array and display every symbol/number dynamically. This way, your code will be dry and there won't be repetition. You can read this article as a guide. 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I did an algorithm like that and added the required conditionals for class-naming. 🎉

- Adding an array of symbols to loop from, that way the code is DRY!
Copy link

@bimbolabuari bimbolabuari left a comment

Choose a reason for hiding this comment

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

Hi @Kakalanp,

Your project is complete! There is nothing else to say other than... it's time to merge it :shipit:
Congratulations! 🎉

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

@Kakalanp Kakalanp merged commit 9859885 into dev Mar 17, 2022
@Kakalanp Kakalanp deleted the events branch March 17, 2022 18:09
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.

None yet

3 participants