Add offline mode logic for chapter operations and refactor IPC handlers

- Integrate `OfflineContext` into `TextEditor` and `ScribeChapterComponent` to handle offline scenarios for chapter CRUD operations.
- Add conditional logic to switch between server API requests and offline IPC handlers (`db:chapter:add`, `db:chapter:remove`, `db:chapter:content:save`, `db:chapter:update`).
- Refactor and rename IPC handlers (`db:chapter:create` to `db:chapter:add`, `db:chapter:delete` to `db:chapter:remove`) for consistency.
- Update UI to disable certain actions when offline (e.g., GhostWriter button).
This commit is contained in:
natreex
2025-11-26 22:03:22 -05:00
parent 9648d9e9be
commit e1abcd9490
3 changed files with 48 additions and 22 deletions

View File

@@ -123,11 +123,20 @@ export default function ScribeChapterComponent() {
async function handleChapterUpdate(chapterId: string, title: string, chapterOrder: number): Promise<void> {
try {
const response: boolean = await System.authPostToServer<boolean>('chapter/update', {
chapterId: chapterId,
chapterOrder: chapterOrder,
title: title,
}, userToken, lang);
let response: boolean;
if (isCurrentlyOffline()) {
response = await window.electron.invoke<boolean>('db:chapter:update',{
chapterId: chapterId,
chapterOrder: chapterOrder,
title: title,
})
} else {
response = await System.authPostToServer<boolean>('chapter/update', {
chapterId: chapterId,
chapterOrder: chapterOrder,
title: title,
}, userToken, lang);
}
if (!response) {
errorMessage(t("scribeChapterComponent.errorChapterUpdate"));
return;
@@ -159,10 +168,14 @@ export default function ScribeChapterComponent() {
async function handleDeleteChapter(): Promise<void> {
try {
setDeleteConfirmationMessage(false);
const response: boolean = await System.authDeleteToServer<boolean>('chapter/remove', {
bookId: book?.bookId,
chapterId: removeChapterId,
}, userToken, lang);
let response:boolean = false;
if (isCurrentlyOffline()) {
response = await window.electron.invoke<boolean>('db:chapter:remove', removeChapterId)
} else {
response = await System.authDeleteToServer<boolean>('chapter/remove', {
chapterId: removeChapterId,
}, userToken, lang);
}
if (!response) {
errorMessage(t("scribeChapterComponent.errorChapterDelete"));
return;
@@ -189,7 +202,7 @@ export default function ScribeChapterComponent() {
try {
let chapterId:string|null = null;
if (isCurrentlyOffline()){
chapterId = await window.electron.invoke<string>('db:chapter:create', {
chapterId = await window.electron.invoke<string>('db:chapter:add', {
bookId: book?.bookId,
chapterOrder: chapterOrder,
title: chapterTitle