-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
change search ux #600
Merged
+57
−98
Merged
change search ux #600
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7abf530
change search ux
sosukesuzuki e643443
split search function to module.
sosukesuzuki 2364348
fix indent
sosukesuzuki 10e7504
add className 'searchInput'
sosukesuzuki 805c39e
refactor search function
sosukesuzuki fc4c471
fix spacing for eslint
sosukesuzuki 290e6ab
change arg findByTag
sosukesuzuki 9496ab8
fix spacings
sosukesuzuki 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import _ from 'lodash' | ||
|
||
export default function searchFromNotes (data, search) { | ||
let notes = data.noteMap.map((note) => note) | ||
if (search.trim().length === 0) return [] | ||
let searchBlocks = search.split(' ') | ||
searchBlocks.forEach((block) => { | ||
if (block.match(/^#.+/)) { | ||
notes = findByTag(notes, block) | ||
} else { | ||
notes = findByWord(notes, block) | ||
} | ||
}) | ||
return notes | ||
} | ||
|
||
function findByTag (notes, block) { | ||
const tag = block.match(/#(.+)/)[1] | ||
let regExp = new RegExp(_.escapeRegExp(tag), 'i') | ||
return notes.filter((note) => { | ||
if (!_.isArray(note.tags)) return false | ||
return note.tags.some((_tag) => { | ||
return _tag.match(regExp) | ||
}) | ||
}) | ||
} | ||
|
||
function findByWord (notes, block) { | ||
let regExp = new RegExp(_.escapeRegExp(block), 'i') | ||
return notes.filter((note) => { | ||
if (_.isArray(note.tags) && note.tags.some((_tag) => { | ||
return _tag.match(regExp) | ||
})) { | ||
return true | ||
} | ||
if (note.type === 'SNIPPET_NOTE') { | ||
return note.description.match(regExp) | ||
} else if (note.type === 'MARKDOWN_NOTE') { | ||
return note.content.match(regExp) | ||
} | ||
return false | ||
}) | ||
} |
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
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
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.
Thank you for changing them into the module 😄
And probably, I made a mistake 😨. I assume arranged interface is better (regarding
findByTag()
andfindByWord
). So, you should changefindByTag()
. It's better that to cut out the tag from a block inside the method.And also, you can make a method such as
findByTagOrWord(block)
to combine the methods for finding. (I'm not sure the argument name (block) is better or not 🤒)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.
Thank you for commenting! Certainly it is simple and easy to understand.