Skip to content

Commit 441710a

Browse files
committed
Modified search.searvice.ts and content-search.directive.ts, fixed the initial search no result problem.
1 parent 6782849 commit 441710a

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
- 重写Electron后端,将书籍管理放入 `book.backend.ts`的类中
1111
- 将Electron的`index.ts`修改为类的形式
12-
- 给图片重新加上了`findup`方法,将`images`插件修改为异步方式
12+
- 给图片重新加上了`findup`方法,将`images`插件修改为异步方式,实现图片自动查找
1313
- 发现`router.service.ts`中的判断 `homepage` 方法有问题,加以修改
14+
- 修正了 `src/app/book/markdown-elements/toc-pagination.component.ts`中的几个问题,分页正常工作
1415
- 继续实现书籍删除、类别编辑
1516

1617
+ 2020-12-12

src/app/book/directives/content-search.directive.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class ContentSearchDirective {
2727
];
2828
const el = elRef.nativeElement;
2929

30+
this.searchService.init();
31+
3032
const changeEvent = fromEvent(el, 'change');
3133
const enterEvent = fromEvent(el, 'keydown.enter');
3234

src/app/book/services/search.service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export class SearchService {
5454
.use(stringify);
5555
}
5656

57-
5857
get bookPath() {
5958
return this.settings.bookPath;
6059
}
@@ -95,14 +94,16 @@ export class SearchService {
9594
});
9695
}
9796

98-
async search(query: string) {
97+
init = () => {
9998
if(!this.searchIndex){
100-
this.loadSummary().subscribe(paths => {
101-
this.generateSearchIndex(paths).then(() => {
102-
this.search(query);
103-
});
104-
});
99+
this.loadSummary().subscribe(paths => this.generateSearchIndex(paths));
100+
101+
return null;
105102
}
103+
}
104+
105+
async search(query: string) {
106+
this.init();
106107

107108
if (typeof query !== 'string' || query.trim() === '') {
108109
return null;

0 commit comments

Comments
 (0)