Skip to content

Commit d847bb4

Browse files
committed
Reviewed backend, fixed git clone error reflect problem, and working on delete book.
1 parent 71a9872 commit d847bb4

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

electron/db.sqlite

0 Bytes
Binary file not shown.

electron/src/book.backend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fork, ChildProcess } from 'child_process';
44

55
import { escapeFileNames, getMdList } from './fs-ops';
66
import { CRUD } from './crud';
7-
import { IIpcMessage, IItem, join as _join, IBookDownloading, IBookDownloaded } from './vendor';
7+
import { IError, IIpcMessage, IItem, join as _join, IBookDownloading, IBookDownloaded } from './vendor';
88
import { Book } from './models';
99

1010
export class BookBackend {
@@ -126,7 +126,8 @@ export class BookBackend {
126126
child.kill('SIGINT');
127127
break;
128128
case 'error-occured':
129-
const err: Error = msg.data as Error;
129+
const err: IError = msg.data as IError;
130+
130131
this.book.errMsg = err.message;
131132

132133
item = {

electron/src/git-ops.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export const clone = async (bookDir: string, bookUri: string) => {
6666
process.send(message);
6767
}
6868
})
69-
.catch(err => {
69+
.catch(error => {
7070
// 发送消息给父进程
7171
if(process.send){
72-
const message: IIpcMessage = {title: 'error-occured', data: err};
72+
const message: IIpcMessage = {title: 'error-occured', data: {message: error.message, err: error}};
7373
process.send(message);
7474
}
7575
});

electron/src/vendor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export interface IBookDownloaded {
1010
commit: string;
1111
}
1212

13+
export interface IError {
14+
message: string;
15+
err: object
16+
}
1317
export interface IIpcMessage {
1418
title: string;
15-
data: number|IBookDownloaded|Error;
19+
data: number|IBookDownloaded|IError;
1620
}
1721

1822
export const sortFn = (a: string, b: string) => {

src/app/home/components/book-list.component.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,6 @@ export class BookListComponent implements OnInit {
110110
});
111111
}
112112

113-
openAddBookDialog = () => {
114-
const dialogRef = this.dialog.open(NewBookDialog, {
115-
width: '480px',
116-
data: { cateList: this.cateList, bookList: this.bookList}
117-
});
118-
119-
dialogRef.afterClosed().subscribe(res => {
120-
if(res) this.saveBook(res);
121-
});
122-
}
123-
124113
deleteBook = (res: DeleteBookDialogResData) => {
125114
const index = this.bookList.findIndex(b => b.id === res.book.id);
126115
this.bookList.splice(index, 1);
@@ -134,6 +123,8 @@ export class BookListComponent implements OnInit {
134123
}
135124
this.crud.updateItem(query).subscribe(b => {
136125
this.bookList.push(b as Book);
126+
this.bookListDisplay = this.bookList.slice();
127+
this.cdr.detectChanges();
137128
});
138129
}
139130
else {
@@ -142,6 +133,17 @@ export class BookListComponent implements OnInit {
142133
this.bookListDisplay = this.bookList.slice();
143134
}
144135

136+
openAddBookDialog = () => {
137+
const dialogRef = this.dialog.open(NewBookDialog, {
138+
width: '480px',
139+
data: { cateList: this.cateList, bookList: this.bookList}
140+
});
141+
142+
dialogRef.afterClosed().subscribe(res => {
143+
if(res) this.saveBook(res);
144+
});
145+
}
146+
145147
saveBook = (res: NewBookDialogResData) => {
146148
const newBook = new Book();
147149
newBook.cateList = [];

0 commit comments

Comments
 (0)