Skip to content

Commit

Permalink
Import Notes filter fix and minor Preview updation
Browse files Browse the repository at this point in the history
Fixes new_notes updation following title or content containing objects
filtration by assigning result from .map() method back ot new_notes to
update the imported data as per the notes data mapping done within it
along with current timestamp selection or assigning a new one via Date
.toLocaleString without 'new' constructor invoking as that resulted in
local date and time string without any data on timezone which mismatched
with existing timestamp strings captured in other parts of creation and
updation of notes. Preview area below file selection under Import Notes
Modal is set to italicize Preview label and use decodeURIComponent to
decode any spacing and special characters back from their %-escape
literals.

Signed-off-by: Harshit Gupta <[email protected]>
  • Loading branch information
Git-Harshit committed Oct 15, 2023
1 parent a4e3ea1 commit 10c212f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ function App() {
new_notes = (new_notes === "") ? [] : JSON.parse(new_notes);
if (Array.isArray(new_notes) !== true) new_notes = [new_notes]; // Converting individual note into Array of that note to support importing individual note Object as well from reader.result

new_notes.map( note => (note.title || note.content) && { title:note.title, content:note.content, creation_timestamp: note["timestamp"] ? note.timestamp : note.creation_timestamp ? note.creation_timestamp : new Date().toLocaleString() } ); // Filtering data using the required fields of notes for importing, ensuring that a note is only imported if it holds a title or content data
new_notes = new_notes.map( note => (note.title || note.content) && { title:note.title, content:note.content, creation_timestamp: note["timestamp"] ? note.timestamp : ( note.creation_timestamp || Date().toLocaleString() ) } ); // Filtering data using the required fields of notes for importing, ensuring that a note is only imported if it holds a title or content data, with creation_timestamp field either re-used or set

if (notes_preview) {
if (new_notes.length > 0) {
notes_preview.innerHTML = "<br/><label>Preview:</label><br/><br/>";
new_notes.forEach( note => notes_preview.innerHTML += `<h6>${note.title}</h6><p>${note.content}</p>` );
notes_preview.innerHTML = "<label><em>Preview:</em></label><br/><br/>";
new_notes.forEach( note => notes_preview.innerHTML += `<h6>${note.title}</h6><p>${decodeURIComponent(note.content)}</p>` );
}
else notes_preview.innerText = "No notes found. Please try again using another file.";
}
Expand Down

0 comments on commit 10c212f

Please sign in to comment.