Refactor ScribeChapterComponent and offline handlers for seamless local and server operations
- Add stricter typings (`RefObject`) and improve type safety. - Introduce conditional logic for `localBook` to
This commit is contained in:
@@ -86,10 +86,9 @@ export default function BookList() {
|
||||
setBookGuide(true);
|
||||
}
|
||||
}, [groupedBooks]);
|
||||
|
||||
// Charger les livres quand les conditions sont remplies
|
||||
|
||||
useEffect((): void => {
|
||||
const shouldFetchBooks =
|
||||
const shouldFetchBooks:boolean|"" =
|
||||
(session.isConnected || accessToken) &&
|
||||
(!isCurrentlyOffline() || offlineMode.isDatabaseInitialized);
|
||||
|
||||
@@ -119,7 +118,6 @@ export default function BookList() {
|
||||
setBookGuide(false);
|
||||
}
|
||||
} else {
|
||||
// Mode offline: stocker dans localStorage
|
||||
const completedGuides = JSON.parse(localStorage.getItem('completedGuides') || '[]');
|
||||
if (!completedGuides.includes('new-first-book')) {
|
||||
completedGuides.push('new-first-book');
|
||||
@@ -229,6 +227,7 @@ export default function BookList() {
|
||||
|
||||
async function getBook(bookId: string): Promise<void> {
|
||||
try {
|
||||
let localBookOnly: boolean = false;
|
||||
let bookResponse: BookListProps|null = null;
|
||||
if (isCurrentlyOffline()){
|
||||
if (!offlineMode.isDatabaseInitialized) {
|
||||
@@ -236,10 +235,18 @@ export default function BookList() {
|
||||
return;
|
||||
}
|
||||
bookResponse = await window.electron.invoke('db:book:bookBasicInformation', bookId)
|
||||
if (bookResponse) {
|
||||
localBookOnly = true;
|
||||
}
|
||||
} else {
|
||||
bookResponse = await System.authGetQueryToServer<BookListProps>(`book/basic-information`, accessToken, lang, {
|
||||
id: bookId
|
||||
});
|
||||
const isOfflineBook: SyncedBook | undefined = localOnlyBooks.find((book: SyncedBook):boolean => book.id === bookId);
|
||||
if (isOfflineBook) {
|
||||
bookResponse = await window.electron.invoke('db:book:bookBasicInformation', bookId)
|
||||
localBookOnly = true;
|
||||
}
|
||||
if (!bookResponse) {
|
||||
bookResponse = await System.authGetQueryToServer<BookListProps>(`book/basic-information`, accessToken, lang, {id: bookId});
|
||||
}
|
||||
}
|
||||
if (!bookResponse) {
|
||||
errorMessage(t("bookList.errorBookDetails"));
|
||||
@@ -256,6 +263,7 @@ export default function BookList() {
|
||||
publicationDate: bookResponse?.desiredReleaseDate || '',
|
||||
desiredWordCount: bookResponse?.desiredWordCount || 0,
|
||||
totalWordCount: 0,
|
||||
localBook: localBookOnly,
|
||||
coverImage: bookResponse?.coverImage ? 'data:image/jpeg;base64,' + bookResponse.coverImage : '',
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user