Conversation
TipsDescription: calculate a total including a percentage tip Example Query: 20% tip on $21.63, 20 percent tip for a $20 bill Tab Name: Answer Source: These are the important fields from the IA page. Please check these for errors or missing information and update the IA page This is an automated message which will be updated as changes are made to the IA page |
Deploying to Beta 馃憤 |
@duckduckgo/duckduckhack-contributors Does anybody want to test drive this / code review? it would be greatly appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nitpicks 馃憤 馃殌
share/goodie/tips/tips.css
Outdated
|
||
.zci--tips span#tip_label, | ||
.zci--tips span#total_label { | ||
font-size: 1.5em |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
share/goodie/tips/tips.js
Outdated
* the input buttons | ||
*/ | ||
$bill_input.change(function(_e) { | ||
calculateTip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that is annoying. Well spotted. Will fix 馃憤
share/goodie/tips/tips.js
Outdated
|
||
return { | ||
onShow: function() { | ||
DDG.require('math.js', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this dependency is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! I was planning to use it but just used plain js in the end. Will fix 馃憤
I think this is good to be shipped. I have done some sec testing as well. All seems ok 馃憤 |
share/goodie/tips/tips.js
Outdated
* Event handlers to update the values when | ||
* keys are pressed | ||
*/ | ||
$bill_input.keyup(function(_e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should grab all the inputs
with a jQuery selector and apply a single keyUp event handler
$inputs = $dom.find('input');
// use change to handle both keyup and click
$inputs.change(function(){
normalizeText();
calculateTip()
});
setUpSelectors(); | ||
$bill_input.val(init_bill); | ||
$bill_tip.val(init_percentage); | ||
calculateTip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to start doing this pre-render in interactive IAs to prevent lag. It's noticeable on slower computers and slower internet connections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. Maybe a unified approach to this might be a good starting point.
share/goodie/tips/tips.js
Outdated
|
||
var tip = bill_input * (bill_tip / 100); | ||
var tip_pp = parseFloat(tip) / parseInt(bill_people); | ||
var total = parseFloat(bill_input) + parseFloat(tip); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the parseFloat
and parseInt
here. Javascript will figure it out :)
You could also do things like (intA + floatB).toFixed(2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that although inputs are type='number'
they jquery still fetches them as string objects that need to be parsed as floats/ints
share/goodie/tips/tips.css
Outdated
font-size: 1.5em | ||
} | ||
|
||
.zci--tips div#tips_block_tip, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use ID's here -- this is a perfect use case for selectors or classes:
/* with a class on parent div */
.zci--tips frm--right div { ... }
/* OR */
/* with a class on the divs we're targetting */
.zci--tips tips_block { ... }
/* OR */
/* approach without IDs */
.zci--tips tips_block--tip,
.zci--tips tips_block--total, { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use these ids for the responsive layout now 馃憤
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still use the IDs on the elements, but I would add a class to both to simplify the CSS.
internally we use a js-foo
class to specify things we'll target with JS. We typically avoid using ids:
<div class="tips_block tips_block--tip js-tips_block-tips">
The first class can be used for CSS rules like the one above, the 2nd for element-specific CSS, the third for a JS handler
share/goodie/tips/tips.css
Outdated
font-weight: bold; | ||
text-align: center; | ||
margin-bottom: 10px; | ||
width: 90%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use class="ninety"
on the element this will force 100% width on mobile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed to cause a lot of problems believe it with the mobile and desktop design
Does anybody have any last minute feedback? @duckduckgo/duckduckhack-contributors |
@duckduckgo/community-leaders seems good to go 馃憤 |
@pjhampton It doesn't look good to go as far as I am concerned. Solution: You deleted the |
edit: Nvm. I see @adityatandn007 |
1708fc8
to
2eaf4b6
Compare
@pjhampton Thanks! This LGTM 馃憤 |
Description of new Instant Answer, or changes
Adds interactivity to tips. Good for review 馃憤
Related Issues and Discussions
People to notify
@moollaza
Testing & Review
To be completed by Community Leader (or DDG Staff) when reviewing Pull Request
Pull Request
Instant Answer Page (for new Instant Answers)
Code
$ duckpan test <goodie_id>
)Ready to merge?
Pull Request Review Guidelines: https://docs.duckduckhack.com/programming-mission/pr-review.html
Instant Answer Page: https://duck.co/ia/view/tips