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:
@@ -81,7 +81,11 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
setPlotSummary(response.globalResume);
|
||||
@@ -107,12 +111,16 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
setTone(response.tone);
|
||||
@@ -154,12 +162,16 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:update', guidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'book/guide-line',
|
||||
guidelineData,
|
||||
userToken,
|
||||
lang,
|
||||
);
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:update', guidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'book/guide-line',
|
||||
guidelineData,
|
||||
userToken,
|
||||
lang,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
errorMessage(t("guideLineSetting.saveError"));
|
||||
@@ -177,9 +189,9 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
|
||||
async function saveQuillSense(): Promise<void> {
|
||||
try {
|
||||
const response: boolean = await System.authPostToServer<boolean>(
|
||||
'quillsense/book/guide-line',
|
||||
{
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:ai:update', {
|
||||
bookId: bookId,
|
||||
plotSummary: plotSummary,
|
||||
verbTense: verbTense,
|
||||
@@ -188,10 +200,37 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
toneAtmosphere: toneAtmosphere,
|
||||
language: language,
|
||||
themes: themes,
|
||||
},
|
||||
userToken,
|
||||
lang,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:ai:update', {
|
||||
bookId: bookId,
|
||||
plotSummary: plotSummary,
|
||||
verbTense: verbTense,
|
||||
narrativeType: narrativeType,
|
||||
dialogueType: dialogueType,
|
||||
toneAtmosphere: toneAtmosphere,
|
||||
language: language,
|
||||
themes: themes,
|
||||
});
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'quillsense/book/guide-line',
|
||||
{
|
||||
bookId: bookId,
|
||||
plotSummary: plotSummary,
|
||||
verbTense: verbTense,
|
||||
narrativeType: narrativeType,
|
||||
dialogueType: dialogueType,
|
||||
toneAtmosphere: toneAtmosphere,
|
||||
language: language,
|
||||
themes: themes,
|
||||
},
|
||||
userToken,
|
||||
lang,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
successMessage(t("guideLineSetting.saveSuccess"));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user