Skip to content

this is my site#5

Open
haimre wants to merge 60 commits into
ofirdagan:mainfrom
haimre:main
Open

this is my site#5
haimre wants to merge 60 commits into
ofirdagan:mainfrom
haimre:main

Conversation

@haimre
Copy link
Copy Markdown

@haimre haimre commented Feb 3, 2022

a basic vanilla TODO list app

Comment thread 1-Vanilla/index.html Outdated
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<!--import icon font-->
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

where did u take the template of index.html from?

Comment thread 1-Vanilla/index.html Outdated
<div style='display:flex;align-self: flex-start; margin:5px'>description: <input id='description-input' class='description-input' style='height:50px' type='textarea'/></div>
</div>
<div class='menu-buttons'>
<!-- <button class='clear-button' onclick='clear_menu()'>clear</button>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what's this?

Comment thread 1-Vanilla/index.js Outdated
@@ -0,0 +1,170 @@
var edited_id = 'empty';
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we don't use var anymore. use either const or let.
const for pointers/primitive that won't change.
let for pointers/primitive that you will need to change their values

Comment thread 1-Vanilla/index.html Outdated
<div class='item'>
<div style='margin:5px'>title: <input id='title-input' required class='title-input' type='text'/></div>
<div style='margin:5px'>subtitle: <input id='subtitle-input' class='subtitle-input' type='text'/></div>
<div style='display:flex;align-self: flex-start; margin:5px'>description: <input id='description-input' class='description-input' style='height:50px' type='textarea'/></div>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  • put all of your css rules inside css files and not inline.
  • make description a multiline text input aka textarea so I will be able to write a long todo (more than 1 long line)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

did u fix this? (second bullet point)

Comment thread 1-Vanilla/index.html Outdated
<ul id='list' class='todo-list'>
<!-- to be added dynamically-->
</ul>
<button class='add-button' onclick="add_button(this)">add new todo item</button>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

make it so hitting enter will also add a new todo

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

did u do that?

Comment thread 1-Vanilla/index.js Outdated
function add_item(){
let title = document.getElementById('title-input').value
if (title ==''){
console.log('cant add an item without a title')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the console is not user facing, i.e a normal user will never see these messages. use alert instead.
In the future we'll improve it and we will use different mechanism for alerting the user that he did something wrong. for now alert is good enough

Comment thread 1-Vanilla/index.js Outdated
document.getElementById('menu-button').innerText = 'add item'

// dont forget to change the id variable
id++
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

an incrementing id param is usually not a good idea. it might work for now but once we'll introduce server or even local storage, it will become a sync nightmare. instead we use GUID for ids.
read more about it here:
https://dba.stackexchange.com/questions/264/guid-vs-int-which-is-better-as-a-primary-key

Comment thread 1-Vanilla/index.js Outdated
let itemTextElement = document.createElement('div')
itemTextElement.className = 'todo-item-text'
// item title
let titleElement = document.createElement('div')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

i don't understand the indentation here.

Comment thread 1-Vanilla/index.js Outdated
itemElement.appendChild(itemTextElement)
itemElement.appendChild(itemButtonsElement)

// the itemElement should look like this example:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we don't use comments in our code. instead the code needs to tell the story in the most clear and easy to understand way possible.

in the words of uncle bob:
"A comment is a failure to express yourself in code. If you fail, then write a comment; but try not to fail"

Comment thread 1-Vanilla/index.js Outdated
list.appendChild(itemElement)

// reset menu display
document.getElementById('title-input').value = ''
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

document.getElementById(X).value is something that you have a lot of.. think of a way to shorten it for example
setElementValue(x) or even just setValue(X)

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.

2 participants