11import { notes , categories , icons } from './data.js' ;
2- import { makeID , getDatesFromText } from "./functions.js" ;
3- // import { makeID } from "./functions";
2+ import { makeRandomID , getDatesFromText } from "./functions.js" ;
3+
44
55let statisticsTable = document . getElementById ( 'stats-table' ) ,
66 notesTable = document . getElementById ( 'active-archive-table' ) ;
77
8+ let activeNoteTableShown = true ;
9+
810
911function loadIconsIntoHeader ( ) {
1012 Array . from ( document . getElementsByClassName ( 'header-icon' ) ) . forEach ( col => {
@@ -31,16 +33,19 @@ function buildForm(name, created, category, content){
3133
3234 form . onsubmit = ( event ) => {
3335 event . preventDefault ( ) ;
34-
35- createNote ( {
36- id : makeID ( 10 ) ,
36+ let note = {
37+ id : makeRandomID ( 10 ) ,
3738 name : event . target . name . value ,
3839 created : new Date ( ) ,
3940 category : event . target . categories . value ,
4041 content : event . target . content . value ,
4142 dates : getDatesFromText ( event . target . content . value ) ,
4243 archived : false
43- } ) ;
44+ }
45+
46+ createNote ( note ) ;
47+
48+ document . getElementsByClassName ( 'wrapper-div' ) [ 0 ] . remove ( ) ;
4449 } ;
4550
4651
@@ -68,11 +73,11 @@ function deleteNote(noteID){
6873
6974function refreshTables ( ) {
7075 clearAllTables ( ) ;
76+ buildNotesTable ( ) ;
7177 buildStatisticTable ( ) ;
72- // buildNotesTable();
7378}
7479function clearAllTables ( ) {
75- // clearInnerHTML(notesTable);
80+ clearInnerHTML ( notesTable ) ;
7681 clearInnerHTML ( statisticsTable ) ;
7782}
7883function clearInnerHTML ( parent ) {
@@ -123,15 +128,41 @@ function buildStatTr(category, active, total){
123128}
124129
125130function buildNotesTable ( ) {
131+ notes . forEach ( note => {
132+ if ( ! note . archived === activeNoteTableShown )
133+ notesTable . innerHTML += buildNotesTr ( note ) ;
134+ } )
126135
127136}
137+ function buildNotesTr ( note ) {
138+ return `
139+ <tr>
140+ <td className="category-icon">${ categories [ note . category ] } </td>
141+ <td className="name">${ note . name } </td>
142+ <td className="created">${ note . created . toLocaleDateString ( ) } </td>
143+ <td className="category1">${ note . category } </td>
144+ <td className="content">${ note . content } </td>
145+ <td className="dates">${ note . dates } </td>
146+ <td className="row-icon edit"></td>
147+ <td className="row-icon archive"></td>
148+ <td className="row-icon delete"></td>
149+ </tr>
150+ ` ;
151+ }
128152
129153export {
130154 refreshTables ,
131155 loadIconsIntoHeader ,
132156 notes
133157}
134158
159+ function switchTables ( ) {
160+ activeNoteTableShown = ! activeNoteTableShown ;
161+ clearInnerHTML ( notesTable ) ;
162+ buildNotesTable ( ) ;
163+ document . getElementsByClassName ( 'header-icon archive' ) [ 0 ] . innerHTML = ( activeNoteTableShown ) ? icons . ARCHIVE_ICON : icons . UNARCHIVE_ICON ;
164+ }
135165
166+ document . getElementById ( "table-switcher" ) . addEventListener ( "click" , switchTables ) ;
136167document . getElementById ( "create-note-button" ) . addEventListener ( "click" , buildForm ) ;
137- document . getElementById ( "build-stats" ) . addEventListener ( "click" , refreshTables ) ;
168+ // document.getElementById("build-stats").addEventListener("click", refreshTables);
0 commit comments