Conversation
phoneApp/index.js
Outdated
|
|
||
| render() { | ||
|
|
||
| document.body.innerHTML += this.createHeader(); |
There was a problem hiding this comment.
oyy!
as I see you updating innerHTML several times, it's better to update it only once
phoneApp/index.js
Outdated
| <footer class="footer"> | ||
| <div class="container bottom-radius"> | ||
| <nav class="main-nav"> | ||
| <a href="index.html" class="tab active"> |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
pretty sure you have to create table with inner HTML also
phoneApp/index.js
Outdated
|
|
||
| render() { | ||
|
|
||
| document.body.innerHTML += this.createHeader(); |
There was a problem hiding this comment.
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
026cde8 to
59872b9
Compare
OlegLustenko
left a comment
There was a problem hiding this comment.
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!
phoneApp/keypad.js
Outdated
| if(e.target.tagName === 'BUTTON') { | ||
| let input = document.querySelector('input.numbers'); | ||
| if(input.value.length === 0) { | ||
| input.value += `(${e.target.textContent}`; |
There was a problem hiding this comment.
it's better to use regexp here.
Such logic with length is pretty hard to read and extend
phoneApp/keypad.js
Outdated
| 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}`; |
There was a problem hiding this comment.
well, it looks like a duplication of the code from line 43.
You should create reusable function to generate such numbers (and use regexp)
phoneApp/keypad.js
Outdated
| input.value = input.value.slice(0, -1); | ||
| }); | ||
| let input = document.querySelector('input.numbers'); | ||
| input.onkeypress = function(event) { |
There was a problem hiding this comment.
you have to use addEventListener for keypress intead of onkeypress event binding
phoneApp/keypad.js
Outdated
|
|
||
| addEvents() { | ||
| let keypadHolder = document.querySelector('div.keypad-holder'); | ||
| keypadHolder.addEventListener('click', function(e) { |
There was a problem hiding this comment.
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
phoneApp/keypad.js
Outdated
| @@ -0,0 +1,91 @@ | |||
| class Keypad { | |||
| constructor() { | |||
| this.buttonsContent = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#']; | |||
There was a problem hiding this comment.
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 :)
phoneApp/userContacts.js
Outdated
| // email: 'ViktorKriv@ec.ua' | ||
| // } | ||
| //]; | ||
| this.columnHeadings = ['Name', 'Last name', 'Email']; |
There was a problem hiding this comment.
please move such columns to static innerHTML
phoneApp/userContacts.js
Outdated
| start += `<th>${elem}</th>\n` | ||
| return start; | ||
| }, ''); | ||
| let resultThead = openThead + `${createThead}</tr></thead>`; |
There was a problem hiding this comment.
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}"> |
There was a problem hiding this comment.
the same about string concatenation
|
|
||
| table.addEventListener('click', function(e) { | ||
| if(e.target.tagName === 'TH') { | ||
| sortTable(e.target.cellIndex, e.target.textContent); |
phoneApp/userContacts.js
Outdated
| let newUsers = userJson.map((elem) => { | ||
| return { | ||
| email: elem.email, | ||
| name: elem.fullName.split(' ')[0], |
There was a problem hiding this comment.
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
No description provided.