Skip to content

Conversation

@NataliaButenko
Copy link
Collaborator

No description provided.


render() {

document.body.innerHTML += this.createHeader();
Copy link
Member

Choose a reason for hiding this comment

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

oyy!
as I see you updating innerHTML several times, it's better to update it only once

<footer class="footer">
<div class="container bottom-radius">
<nav class="main-nav">
<a href="index.html" class="tab active">
Copy link
Member

Choose a reason for hiding this comment

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

I believe you could make links more reusable.

What if one day you have to set class but the click ? or something more expensive.

I guess it could look that way

<nav class="main-nav">
 this.renderLink({ content:'Contacts', className:'active', icon:'search'});
 this.renderLink({ content:'Keypad', icon:'th'});
 this.renderLink({ content:'Edit contact' });
 ...
</nav>

We could reuse some HTML parts and create a smaller reusable blocks

document.body.innerHTML += this.createHeader();
document.body.innerHTML += this.createMain();
let insert = document.querySelector('main > div');
insert.appendChild(this.createTable());
Copy link
Member

Choose a reason for hiding this comment

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

pretty sure you have to create table with inner HTML also


render() {

document.body.innerHTML += this.createHeader();
Copy link
Member

Choose a reason for hiding this comment

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

document.body.innerHTML not sure I like to use document.body.

You have to create an additional tag at index.html and call it, for example,

<div id="mountNode"></div>

And update content only inside such node. updating the whole document.body is too risky

@NataliaButenko NataliaButenko force-pushed the phoneApp branch 3 times, most recently from 026cde8 to 59872b9 Compare August 13, 2018 20:18
Copy link
Member

@OlegLustenko OlegLustenko left a comment

Choose a reason for hiding this comment

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

I see a lot of job already done, but it requires updates in architecture.

And I don't see your main class called `App' who initializing all pages and store all App specific state.

For the first experience with HTML and not first with JavaScript :), it's a pretty good result. Let's improve it together!

if(e.target.tagName === 'BUTTON') {
let input = document.querySelector('input.numbers');
if(input.value.length === 0) {
input.value += `(${e.target.textContent}`;
Copy link
Member

Choose a reason for hiding this comment

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

it's better to use regexp here.
Such logic with length is pretty hard to read and extend

input.onkeypress = function(event) {
if((event.charCode >= 48 && event.charCode <=57) || event.charCode == 42 || event.charCode == 35) {
if(input.value.length === 0) {
input.value += `(${event.target.textContent}`;
Copy link
Member

Choose a reason for hiding this comment

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

well, it looks like a duplication of the code from line 43.

You should create reusable function to generate such numbers (and use regexp)

input.value = input.value.slice(0, -1);
});
let input = document.querySelector('input.numbers');
input.onkeypress = function(event) {
Copy link
Member

Choose a reason for hiding this comment

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

you have to use addEventListener for keypress intead of onkeypress event binding


addEvents() {
let keypadHolder = document.querySelector('div.keypad-holder');
keypadHolder.addEventListener('click', 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.

in most scenarios of adding callback function to event you have to create additional method and than bind it, the same as we done it in classroom on MVC lesson

@@ -0,0 +1,91 @@
class Keypad {
constructor() {
this.buttonsContent = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'];
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 create numbers as static content, no need to store them in any structures.

How to understand what we should store in a variable and what is just static?

If such data sent from the server you have to store it scenarios (around 95% of all scenarios) it's just a static data.

Furthermore, there will never exist numbers like "11" on keypad at phone :)

// email: '[email protected]'
// }
//];
this.columnHeadings = ['Name', 'Last name', 'Email'];
Copy link
Member

Choose a reason for hiding this comment

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

please move such columns to static innerHTML

start += `<th>${elem}</th>\n`
return start;
}, '');
let resultThead = openThead + `${createThead}</tr></thead>`;
Copy link
Member

Choose a reason for hiding this comment

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

puppies dies in the loop :(

I mean please make 1 ES6 string as with example I mentioned above and make it single line

`;
let createTbody = dataUsers.reduce((start, elem) => {
start += `
<tr data-uid="${elem.id}">
Copy link
Member

Choose a reason for hiding this comment

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

the same about string concatenation


table.addEventListener('click', function(e) {
if(e.target.tagName === 'TH') {
sortTable(e.target.cellIndex, e.target.textContent);
Copy link
Member

Choose a reason for hiding this comment

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

please fix formatting

let newUsers = userJson.map((elem) => {
return {
email: elem.email,
name: elem.fullName.split(' ')[0],
Copy link
Member

Choose a reason for hiding this comment

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

please optimize such call elem.fullName.split(' ')

I have provided an a example several days ago in skype.
Feel free to send message me with any questions

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.

3 participants