mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: sync file search
This commit is contained in:
parent
0e9125b667
commit
dca997dcff
1 changed files with 1 additions and 17 deletions
|
|
@ -32,8 +32,6 @@ export type TreeNode = {
|
|||
accessDenied?: boolean
|
||||
}
|
||||
|
||||
const SEARCH_DELAY = 250
|
||||
|
||||
function getFilterFunc(keyRegex: RegExp) {
|
||||
return function filterFunc({ name }: TreeNode) {
|
||||
return keyRegex.test(name)
|
||||
|
|
@ -73,20 +71,6 @@ function search(treeNodes: TreeNode[], searchKey: string): TreeNode[] {
|
|||
return filterDuplications(searchResults)
|
||||
}
|
||||
|
||||
function debounce<T, Args extends any[]>(
|
||||
func: (...args: Args) => T,
|
||||
delay: number,
|
||||
): (...args: Args) => Promise<T> {
|
||||
let timer: number
|
||||
return (...args) =>
|
||||
new Promise(resolve => {
|
||||
window.clearTimeout(timer)
|
||||
timer = window.setTimeout(() => resolve(func(...args)), delay)
|
||||
})
|
||||
}
|
||||
|
||||
export const debouncedSearch = debounce(search, SEARCH_DELAY)
|
||||
|
||||
function getNodes(root: TreeNode, nodes: TreeNode[] = []) {
|
||||
if (root.contents) {
|
||||
root.contents.forEach(node => {
|
||||
|
|
@ -141,7 +125,7 @@ class L2 {
|
|||
search = async (searchKey: string) => {
|
||||
this.compressed = !searchKey
|
||||
this.searchedNodes = searchKey
|
||||
? await debouncedSearch(this.l1.nodes, searchKey)
|
||||
? search(this.l1.nodes, searchKey)
|
||||
: this.getRoot().contents || []
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue