Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Tips: Add interactivity #4155

Merged
merged 15 commits into from Jun 23, 2017
Merged

Tips: Add interactivity #4155

merged 15 commits into from Jun 23, 2017

Conversation

pjhampton
Copy link
Contributor

@pjhampton pjhampton commented May 3, 2017

Description of new Instant Answer, or changes

Adds interactivity to tips. Good for review 馃憤

screen shot 2017-05-03 at 10 03 24 pm

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

  • Title follows correct format (Specifies Instant Answer + Purpose)
  • Description contains a valid Instant Answer Page Link (e.g. https://duck.co/ia/view/my_ia)

Instant Answer Page (for new Instant Answers)

  • Instant Answer page is correctly filled out and contains:
    • The Title is appropriately named and formatted
    • The IA topics are present and appropriate
    • The Description is clear and coherent
    • Source Name exists if applicable
    • All Example Queries trigger on Beta

Code

  • Adheres to the DuckDuckGo Style Guide
  • Behaviour is appropriately tested. If improvement, tests are adequately extended.
  • There is no unnecessary files in place (such as editor config files)
  • There is no API keys / secrets present
  • Tests are passing (run $ duckpan test <goodie_id>)
    • Tester should report any failures

Ready to merge?

  • Has this IA been deployed to and tested on beta.duckduckgo.com?
  • For larger commits, has this been approved be more than one community member?
  • The number of reviews is appropriate for this type of PR
  • The commit message is clear, coherent and fitting

Pull Request Review Guidelines: https://docs.duckduckhack.com/programming-mission/pr-review.html


Instant Answer Page: https://duck.co/ia/view/tips

@daxtheduck
Copy link

daxtheduck commented May 3, 2017

Tips

Description: 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

@moollaza
Copy link
Member

moollaza commented May 5, 2017

Deploying to Beta 馃憤

@moollaza moollaza added the Design label May 5, 2017
@daxtheduck daxtheduck deployed to beta.duckduckgo.com May 5, 2017 21:58 Active
@pjhampton
Copy link
Contributor Author

@duckduckgo/duckduckhack-contributors Does anybody want to test drive this / code review? it would be greatly appreciated!

Copy link
Collaborator

@mattr555 mattr555 left a 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 馃憤 馃殌


.zci--tips span#tip_label,
.zci--tips span#total_label {
font-size: 1.5em
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we decrease the bottom-padding on the labels to 0 so it's more clear which number belongs to which label?
image

(You'll also have to change span to h4 in this rule.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see what you're saying. I believe @moollaza reached out to the internal design team to run their eyes over it. Once I have that feedback I will incorporate all your changes. Thanks for the feedback @mattr555. Super appreciated!

* the input buttons
*/
$bill_input.change(function(_e) {
calculateTip()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed when using the input buttons, it rounds off the value in the "Bill" field:
ddgtemp

This isn't super important, but it would be nice if it avoided this and rounded off when using these buttons.

Copy link
Contributor Author

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 馃憤


return {
onShow: function() {
DDG.require('math.js', function() {
Copy link
Collaborator

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?

Copy link
Contributor Author

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 馃憤

@pjhampton
Copy link
Contributor Author

I think this is good to be shipped. I have done some sec testing as well. All seems ok 馃憤

@pjhampton
Copy link
Contributor Author

screen shot 2017-05-16 at 12 02 51 pm
screen shot 2017-05-16 at 12 02 59 pm

* Event handlers to update the values when
* keys are pressed
*/
$bill_input.keyup(function(_e) {
Copy link
Member

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()
Copy link
Member

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

Copy link
Contributor Author

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.


var tip = bill_input * (bill_tip / 100);
var tip_pp = parseFloat(tip) / parseInt(bill_people);
var total = parseFloat(bill_input) + parseFloat(tip);
Copy link
Member

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)

Copy link
Contributor Author

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

font-size: 1.5em
}

.zci--tips div#tips_block_tip,
Copy link
Member

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, { ... }

Copy link
Contributor Author

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 馃憤

Copy link
Member

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

font-weight: bold;
text-align: center;
margin-bottom: 10px;
width: 90%;
Copy link
Member

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

Copy link
Contributor Author

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

@daxtheduck daxtheduck deployed to beta.duckduckgo.com May 25, 2017 16:00 Active
@daxtheduck daxtheduck deployed to beta.duckduckgo.com May 25, 2017 16:37 Active
@pjhampton
Copy link
Contributor Author

Does anybody have any last minute feedback? @duckduckgo/duckduckhack-contributors

@daxtheduck daxtheduck deployed to beta.duckduckgo.com May 26, 2017 16:54 Active
@pjhampton
Copy link
Contributor Author

@duckduckgo/community-leaders seems good to go 馃憤

@adityatandon007
Copy link
Contributor

adityatandon007 commented Jun 16, 2017

@pjhampton It doesn't look good to go as far as I am concerned.

tipcalculator

Solution: You deleted the click function in js so I think you need to add it to support the arrow buttons.

@pjhampton
Copy link
Contributor Author

pjhampton commented Jun 16, 2017

Seems like an edge case. What browser is this @adityatandon007? I can't replicate.

edit: Nvm. I see @adityatandn007

@pjhampton pjhampton force-pushed the pjhampton/tips-add_interactivity branch from 1708fc8 to 2eaf4b6 Compare June 16, 2017 09:50
@daxtheduck daxtheduck deployed to beta.duckduckgo.com June 23, 2017 20:43 Active
@moollaza
Copy link
Member

@pjhampton Thanks! This LGTM 馃憤

@moollaza moollaza merged commit ee9d459 into master Jun 23, 2017
@moollaza moollaza deleted the pjhampton/tips-add_interactivity branch June 23, 2017 21:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants