-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hetav Desai | FrontEnd Project 1 Submission #1
Open
desaihetav
wants to merge
18
commits into
getYourMentor-org:main
Choose a base branch
from
desaihetav:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
44af1d0
desktop ui developed
desaihetav bff66aa
feat: render notes list from array of objects
desaihetav bd97b22
feat: display selected note on the right container
desaihetav 9dc4100
feat: autosave on change
desaihetav da751ed
feat: add new note and auto delete empty notes
desaihetav ae00045
fix: auto delete empty note
desaihetav 5430335
refactor: better variable name and placeholders
desaihetav ab55b63
added icon buttons
desaihetav f5b6eed
fix: set and get from localStorage
desaihetav 6910646
fix: delete edge cases
desaihetav 8e9d255
add empty state
desaihetav cedfbb4
fix: welcome note initialise
desaihetav 4708be6
improve: empty state display condition
desaihetav e82142b
feat: dark theme + responsiveness
desaihetav 74dc89c
fix: note title responsiveness and dark mode flash
desaihetav bd67c35
chore: css
desaihetav bbbb7de
refactor: follow clean code practices
desaihetav 281e39d
fix: button responsiveness
desaihetav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
var notesList = document.querySelector(".js-notes-list"); | ||
var noteItem = document.querySelector(".js-note-item"); | ||
var emptyState = document.querySelector(".js-empty-state"); | ||
|
||
var selectedNoteIndex = 0; | ||
var notes = []; | ||
|
||
toggleSwitch = document.querySelector(".theme-switch .toggle-theme-checkbox"); | ||
|
||
function switchTheme(e) { | ||
if (e.target.checked) { | ||
document.documentElement.setAttribute("data-theme", "dark"); | ||
localStorage.setItem("theme", "dark"); | ||
} else { | ||
document.documentElement.setAttribute("data-theme", "light"); | ||
localStorage.setItem("theme", "light"); | ||
} | ||
} | ||
|
||
if (currentTheme) { | ||
toggleSwitch.checked = true; | ||
} | ||
|
||
toggleSwitch.addEventListener("change", switchTheme, false); | ||
|
||
function initializeNotes() { | ||
var notesArr = localStorage.getItem("notes"); | ||
notes = JSON.parse(notesArr); | ||
if (notes === null || notes.length === 0) { | ||
notes = [ | ||
{ | ||
title: "Welcome to NotesHD!", | ||
note: `This is a sample note, please feel free to edit or delete this note and get started with creating your own notes!`, | ||
}, | ||
]; | ||
} else { | ||
notes = JSON.parse(notesArr); | ||
} | ||
} | ||
|
||
function getNotesCount() { | ||
return notes.length; | ||
} | ||
|
||
function isLastNoteEmpty() { | ||
if ( | ||
notes[getNotesCount() - 1].title === "" && | ||
notes[getNotesCount() - 1].note === "" | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function titleChangeHandler(currentIndex) { | ||
var noteTitle = document.querySelector(".note-title"); | ||
currentIndex = Number(currentIndex); | ||
notes[currentIndex].title = noteTitle.innerHTML; | ||
|
||
renderNotesList(false); | ||
} | ||
|
||
function noteChangeHandler(currentIndex) { | ||
var notenote = document.querySelector(".js-note-note"); | ||
currentIndex = Number(currentIndex); | ||
notes[currentIndex].note = notenote.value; | ||
renderNotesList(false); | ||
} | ||
|
||
function addNote() { | ||
var noOfNotes = notes.length; | ||
desaihetav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (noOfNotes) { | ||
if (!isLastNoteEmpty()) { | ||
notes.push({ | ||
title: "", | ||
note: "", | ||
}); | ||
} else { | ||
alert("You already have an empty note!"); | ||
} | ||
} else { | ||
notes.push({ | ||
title: "", | ||
note: "", | ||
}); | ||
} | ||
renderNoteWithIndex(noOfNotes, false); | ||
} | ||
|
||
function deleteNote(currentIndex) { | ||
currentIndex = Number(currentIndex); | ||
notes.splice(currentIndex, 1); | ||
renderNoteWithIndex(0); | ||
} | ||
|
||
function deleteEmpty() { | ||
notes.map((item, currentIndex) => { | ||
if (item.title === "" && item.note === "") { | ||
notes.splice(currentIndex, 1); | ||
} | ||
}); | ||
} | ||
|
||
function renderNotesList() { | ||
if (notes.length != 0) { | ||
var notesListInner = ""; | ||
notes.map((item, currentIndex) => { | ||
notesListInner += ` | ||
<div id=${currentIndex} class="note-list-item${ | ||
selectedNoteIndex === currentIndex ? "-selected" : "" | ||
}" onClick="renderNoteWithIndex(this.id)"> | ||
<h3 class="note-list-item-title">${ | ||
item.title === "" ? "Untitled" : item.title | ||
}</h3> | ||
<p class="note-list-item-note">${ | ||
item.note === "" ? "Note" : item.note | ||
}</p> | ||
</div> | ||
`; | ||
}); | ||
} else { | ||
var notesListInner = `No notes to display`; | ||
} | ||
notesList.innerHTML = notesListInner; | ||
localStorage.setItem("notes", JSON.stringify(notes)); | ||
} | ||
|
||
function renderNoteWithIndex(currentIndex, shouldClearEmpty = true) { | ||
currentIndex = Number(currentIndex); | ||
selectedNoteIndex = currentIndex; | ||
|
||
shouldClearEmpty && deleteEmpty(); | ||
|
||
var noteItemInner; | ||
if (notes.length != 0) { | ||
noteItemInner = ` | ||
<button id=${currentIndex} class="btn delete-btn" onclick="deleteNote(this.id)"> | ||
<img src="/images/trash.svg" class="btn-icon" alt="delete current note"/> | ||
<span>Delete</span> | ||
</button> | ||
<div contenteditable="true" | ||
id=${currentIndex} | ||
type="text" | ||
placeholder="Untitled" | ||
class="note-title div-edit" | ||
onInput="titleChangeHandler(this.id)">${notes[currentIndex].title}</div> | ||
<textarea | ||
id=${currentIndex} | ||
type="text" | ||
placeholder="Note" | ||
class="note-note js-note-note" | ||
onInput="noteChangeHandler(this.id)" | ||
>${notes[currentIndex].note}</textarea> | ||
`; | ||
} else { | ||
noteItemInner = ` | ||
<div class="empty-state js-empty-state"> | ||
<img src="images/file.svg" class="image" /> | ||
<h2>No Notes Created</h2> | ||
<p>Quickly jot that thought down, before it's gone!</p> | ||
</div> | ||
`; | ||
} | ||
noteItem.innerHTML = noteItemInner; | ||
|
||
renderNotesList(); | ||
} | ||
|
||
initializeNotes(); | ||
renderNoteWithIndex(0); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!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="./styles.css" /> | ||
<title>NotesHD | Hetav Desai</title> | ||
</head> | ||
<body> | ||
<script src="theme.js" type="text/javascript"></script> | ||
<div class="container"> | ||
<section class="left"> | ||
<div class="header"> | ||
<h2 class="notes-list-heading">Notes HD</h2> | ||
<label class="theme-switch-wrapper"> | ||
<div class="theme-switch"> | ||
<input | ||
type="checkbox" | ||
class="toggle-theme-checkbox" | ||
aria-label="toggle theme" | ||
/> | ||
<div class="slider round"></div> | ||
</label> | ||
</div> | ||
</div> | ||
<div class="notes-list js-notes-list"> | ||
<!-- <div class="note-list-item"> | ||
<h3 class="title">Title</h3> | ||
<p class="note">note</p> | ||
</div> | ||
<div class="note-list-item-selected"> | ||
<h3 class="note-list-item-title">Title</h3> | ||
<p class="note-list-item-note">note</p> | ||
</div> --> | ||
</div> | ||
<button class="btn add-btn" onclick="addNote()"> | ||
<img src="/images/plus.svg" class="btn-icon" alt="add new note" /> | ||
<span>New Note</span> | ||
</button> | ||
</section> | ||
<section class="right"> | ||
<div class="note-item js-note-item"> | ||
<!-- <input type="text" placeholder="Title" class="note-title"></input> --> | ||
<!-- <textarea | ||
type="text" | ||
placeholder="Note note" | ||
class="note-note" | ||
></textarea> | ||
<small class="small-text">Last modified at 06:00 p.m.</small> --> | ||
</div> | ||
</section> | ||
</div> | ||
<script src="app.js" type="text/javascript"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have already stored this DOM element at the top. You can use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that I was trying to store a few elements like this one even before they were rendered and hence they would return null when trying to store on top. Got rid of such statements on top and used them where they were required, after they had been rendered.