Skip to content

Commit

Permalink
Integrated with codex.notes (issue #133).
Browse files Browse the repository at this point in the history
  • Loading branch information
gigafiga21 committed Feb 8, 2018
1 parent 6306122 commit c6fee2b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion public/build/bundle.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion public/javascripts/aside.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export default class Aside {
return;
}

codex.notes.searcher.pushData(noteData);

let notesMenu;

if (isRootFolder) {
Expand Down Expand Up @@ -337,7 +339,10 @@ export default class Aside {
notesMenu.forEach( menu => {
let existingNote = menu.querySelector('[data-id="' + itemId + '"]');

if (existingNote) existingNote.remove();
if (existingNote) {
existingNote.remove();
codex.notes.searcher.removeData(itemId);
}
});
}

Expand Down
42 changes: 34 additions & 8 deletions public/javascripts/searcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,52 @@ export default class Searcher {
* Where to search
* @type {Array}
*/
this.dataset = null;
this.dataset = [];
}

/**
* Set data where search will be done
* @param {Array} data - array to set
* Push note data to array where search will be done
* @param {Object} data - data to push to the dataset
*/
set data( data ) {
this.dataset = data;
pushData( data ) {
let existingDataIndex = this.dataset.length;

this.dataset.forEach((item, index) => {
if (item._id == data._id) {
existingDataIndex = index;
return;
}
});

this.dataset.splice(existingDataIndex, 1, data);
}

/**
* Remove note data from array where search will be done
* @param {Object} data - data to remove from the dataset
*/
removeData( dataId ) {
let existingDataIndex = this.dataset.length;

this.dataset.forEach((item, index) => {
if (item._id == dataId) {
existingDataIndex = index;
return;
}
});

this.dataset.splice(existingDataIndex, 1);
}

/**
* Set data where search will be done
* @param {Array} data - array to set
* Find data in the dataset array
* @param {String} item - item to find
*/
search( item ) {
let found = [];

this.dataset.forEach((element) => {
if (element.indexOf(item) == 0) {
if (element.title.indexOf(item) == 0) {
found.push(element);
}
});
Expand Down
11 changes: 11 additions & 0 deletions public/stylesheets/components/searcher.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.searcher {

&__input {

}

&__found {

}

}
8 changes: 8 additions & 0 deletions src/views/aside.pug
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@
.aside__section-title Notes
.notes-list
ul.notes-list__content(name="js-folder-notes-menu")


//-
//- Search
//-
.searcher
.searcher__input
.searcher__found

0 comments on commit c6fee2b

Please sign in to comment.