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:
@@ -74,9 +74,13 @@ export function Story(props: any, ref: any) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
setActs(response.acts);
|
||||
@@ -136,7 +140,11 @@ export function Story(props: any, ref: any) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<boolean>('db:book:story:update', storyData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>('book/story', storyData, userToken, lang);
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:story:update', storyData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>('book/story', storyData, userToken, lang);
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
errorMessage(t("story.errorSave"))
|
||||
|
||||
Reference in New Issue
Block a user