Refactor character, chapter, and story components to support offline mode
- Add `OfflineContext` and `BookContext` to components for offline state management. - Introduce conditional logic to toggle between server API requests and offline IPC handlers for CRUD operations. - Refine `TextEditor`, `DraftCompanion`, and other components to disable actions or features unavailable in offline mode. - Improve error handling and user feedback in both online and offline scenarios.
This commit is contained in:
@@ -88,7 +88,11 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:remove', deleteData);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/remove', deleteData, token, lang);
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:remove', deleteData);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/remove', deleteData, token, lang);
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
errorMessage(t("mainChapter.errorDelete"));
|
||||
@@ -120,7 +124,11 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
if (isCurrentlyOffline()) {
|
||||
responseId = await window.electron.invoke<string>('db:chapter:add', chapterData);
|
||||
} else {
|
||||
responseId = await System.authPostToServer<string>('chapter/add', chapterData, token);
|
||||
if (book?.localBook) {
|
||||
responseId = await window.electron.invoke<string>('db:chapter:add', chapterData);
|
||||
} else {
|
||||
responseId = await System.authPostToServer<string>('chapter/add', chapterData, token);
|
||||
}
|
||||
}
|
||||
if (!responseId) {
|
||||
errorMessage(t("mainChapter.errorAdd"));
|
||||
|
||||
Reference in New Issue
Block a user