Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

#6 created a Client-side functionality for the Helpful and Not Helpfu… #15

Merged
merged 17 commits into from
Oct 15, 2017

Conversation

Yjohn
Copy link
Collaborator

@Yjohn Yjohn commented Sep 9, 2017

#6 it needs more work to make the buttons functional

Copy link
Owner

@NateWr NateWr left a comment

Choose a reason for hiding this comment

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

Good start! Just a few things to touch up and then start working on the problem of how you'll get each question's button to work separately.

views/index.hbs Outdated
<div class="entry__help">
<span id="displayCount">{{this.helpful}}</span>/<span id="totalNumber"></span> people found this helpful. Was this entry helpful?
<button id="Button1" class="button button--small">Yes</button>
<button id="Button2" class="button button--small">No</button>
Copy link
Owner

Choose a reason for hiding this comment

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

Button1 and Button2 are bad names for the buttons. Consider using a more descriptive name like button-helpful and button-not-helpful.

public/main.js Outdated
unhelpful++;
total++;
totalNumber.innerHTML = total;
});
Copy link
Owner

Choose a reason for hiding this comment

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

You're going to run into problems using getElementById, because every id on an HTML page must be completely unique. You can't have two elements with the same id.

Learn about querySelectorAll which allows you to select by class name and other attributes.

You'll face the same problem with your global helpful and total vars. If each question has it's own values, you'll need a way to store those values separately.

views/layout.hbs Outdated
@@ -14,5 +14,6 @@
</header>
{{{body}}}
</div>
<script src="/main.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

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

The indentation doesn't look right here. Try formatting the document.

@Yjohn
Copy link
Collaborator Author

Yjohn commented Sep 14, 2017

I saw the review and changed a lot of staff

Copy link
Owner

@NateWr NateWr left a comment

Choose a reason for hiding this comment

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

Great work @Yjohn and @khaledkzy! Code looks really clean. Just a few comments throughout. I haven't tested this myself but let me know when you address the comments and I'll give it a go.

helpful: helpful
})
};
fetch("/rating", options)
Copy link
Owner

Choose a reason for hiding this comment

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

Where does the fetch function come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fetch is built-in in modern browsers (i can use fetch without using Jquery or any other library)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Cool! I didn't even know about that!

})
};
fetch("/rating", options)
.then(response => response.json())
Copy link
Owner

Choose a reason for hiding this comment

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

What's this line doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the route "/rating" is the Url that I and Khalid communicate with the server
it's the same like url: "/api/helpful", it's our argument

Copy link
Owner

Choose a reason for hiding this comment

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

I mean specifically the line .then(response => response.json()) but I think I understand now. That's converting the response string into an object, yeah?

routes/index.js Outdated
const renderEntries = function(error, entry) {
if (error) {
console.log(error);
res.sendStatus(400)
Copy link
Owner

Choose a reason for hiding this comment

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

A 400 status usually indicates an authentication error (ie - "You are not allowed to do this."). In your case, I think you want to render a 500 status (ie - "The server ran into an error.").

routes/index.js Outdated
{$inc: { [helpful ? 'helpful' : 'unhelpful' ]: 1}},
{new: true}
, renderEntries);
});
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like you might have some indentation issues here. Try formatting the document.

views/index.hbs Outdated
{{{this.answer}}}
</div>
<div class="entry__help">
<span class="value-helpful" data-question-id={{this._id}}>{{this.helpful}} people found this helpful. Was this entry helpful?</span>
Copy link
Owner

Choose a reason for hiding this comment

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

Missing quotes " around {{this._id}}.

Also, you're missing the total count: 11/25 people found this helpful. You may need @khaledkzy to modify the data delivered to the template for you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Khalid accept only the ID and the boolean of the Helpful buttons, and he changed depends on what he gets from me
if it's false he add the total number and if it's true he adds 1 to the helpful

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, but in this initial template, the string displays without a total count. You only say "11 people found this helpful" but you need to display "11/25 people found this helpful". Yeah?

@@ -0,0 +1,32 @@
const clickEvent = function (event) {
const id = event.target.getAttribute('data-question-id');
const helpful = JSON.parse(event.target.getAttribute('data-helpful'));
Copy link
Owner

Choose a reason for hiding this comment

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

Do you need the JSON.parse() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, I need JSON.parse() to change the string to boolean

Copy link
Owner

Choose a reason for hiding this comment

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

👍

@Yjohn
Copy link
Collaborator Author

Yjohn commented Sep 15, 2017

@NateWr I commented all the feedback, let me know ... :)

@NateWr
Copy link
Owner

NateWr commented Sep 15, 2017

@Yjohn Great! You can push new commits to this branch with changes for any outstanding issues (like this one).

Copy link
Owner

@NateWr NateWr left a comment

Choose a reason for hiding this comment

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

Nice work! The code looks really good. I haven't tested it yet but let me know when you make the last few changes requested and I'll take it for a spin.

views/index.hbs Outdated
<span class="value-helpful" data-question-id={{this._id}}>{{this.helpful}}/{{this.total}} people found this helpful. Was this entry helpful?</span>
<button class="button button--small button-feedback" data-helpful="true" data-question-id="{{this._id}}">Yes</button>
<button class="button button--small button-feedback" data-helpful="false" data-question-id="{{this._id}}">No</button>
<div id="loading" class="hidden"></div>
Copy link
Owner

Choose a reason for hiding this comment

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

The id attribute needs to be unique across the entire page. So if you have lots of elements with id="loading", it can cause problems if someone tries to use document.getElementById('loading').

It works in your case because you're limiting the selection document.querySelector('.class-<id> #loading'). But it should generally be avoided. You can either:

  1. Add a unique value to each id: id="loading-{this._id}".

  2. Turn the selector into a class: `class="hidden loading".

It's up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created an id only to apply the animation and style. If someone tries to use document.getElementById('loading'), only select empty <div> with animations.
I tried to make it class="hidden loading" but isn't working

Copy link
Owner

Choose a reason for hiding this comment

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

Show me the code that you've tried to get it working with a class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

public/main.js Outdated
let valueElId = valueEl.getAttribute('data-question-id')
if (res._id === valueElId) {
let totalNumber = res.helpful + res.unhelpful;
valueEl.innerHTML = res.helpful + '/' + totalNumber + ' people found this helpful. was this entry helpful';
Copy link
Owner

Choose a reason for hiding this comment

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

Was this entry helpful?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is how I received changes from the database and server, then display the number of people who select the button of helpful and the total number of people whose give their votes.
which part makes you confused?

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I should have explained. I meant to change the words at the end of the line from was this entry helpful to Was this entry helpful?

@NateWr NateWr merged commit 6dd75bf into NateWr:master Oct 15, 2017
@NateWr
Copy link
Owner

NateWr commented Oct 15, 2017

This is amazing @Yjohn! I love the loading animation too. I've merged it now. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants