Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
p1kalys authored Oct 3, 2023
0 parents commit a332765
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>My Notes App</title>
</head>
<body>
<div class="container">
<div class="input-box">
<input type="text" placeholder="Title" id="addTitle" class="main">
<textarea name="" id="addText" cols="30" rows="10" placeholder="Take a note..."></textarea>
<button id="addNote">Add Note</button>

</div>

<div id="notes">

</div>
</div>

<script src="script.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const addTitle = document.getElementById('addTitle');
const addText = document.getElementById('addText');
const addNoteButton = document.getElementById('addNote');
const notesDiv = document.getElementById('notes');

showNotes();
// local storage vs session storage
// JSON: JavaScript Object Notation

function addNotes(){
let notes = localStorage.getItem('notes');
if(notes === null){
notes = [];
}else{
notes = JSON.parse(notes);
}

if(addText.value == ''){
alert('Add your note');
return;
}

const noteObj = {
title: addTitle.value,
text: addText.value,
}
addTitle.value = '';
addText.value = '';
notes.push(noteObj);
localStorage.setItem('notes', JSON.stringify(notes));
showNotes();
}

function showNotes(){
let notesHTML = '';
let notes = localStorage.getItem('notes');
if(notes === null){
return;
}else{
notes = JSON.parse(notes);
}
for(let i=0; i<notes.length; i++){
notesHTML += `<div class="note">
<button class="deleteNote" id=${i} onclick="deleteNote(${i})">Delete</button>
<span class="title">${notes[i].title === "" ? 'Note' : notes[i].title}</span>
<div class="text">${notes[i].text}</div>
</div>
`
}
notesDiv.innerHTML = notesHTML;
}

function deleteNote(ind){
let notes = localStorage.getItem('notes');
if(notes === null){
return;
}else{
notes = JSON.parse(notes);
}
notes.splice(ind, 1);
localStorage.setItem('notes', JSON.stringify(notes));
showNotes();
}
addNoteButton.addEventListener('click', addNotes);



/*
1. delete notes: implementation delete array
2. Archieve Notes: implementation archieve array
3. sorting filter, iterate through all the notes, and check
4. reminder
5. edit note
*/
64 changes: 64 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}

.container{
min-height: 100vh;
width: 100vw;
padding: 23px;
background-color: #ffffff;
}

#input-box{
padding: 5%;
}

input, textarea{
width: 100%;
padding: 10px;
background-color: transparent;
border: 1px solid #a1a0a0;
outline: none;
margin-top: 10px;
color: rgb(21, 21, 21);
}


button{
background: transparent;
margin-top: 5px;
color: rgb(32, 32, 32);
padding: 8px 12px;
border: 1px solid #a1a0a0;
}

button:hover{
cursor: pointer;
}

#notes{
padding: 23px;
display: flex;
flex-wrap: wrap;
/* justify-content: space-evenly; */
}
.note{
width: 300px;
color: #282828;
overflow-wrap: break-word;
margin: 12px;
padding: 12px;
border: 1px solid #a1a0a0;
background: transparent;
}

.deleteNote{
float: right;
}

#notes span {
font-weight: bold;
}

0 comments on commit a332765

Please sign in to comment.