Add offline mode logic for main chapters and refine IPC handlers

- Integrate `OfflineContext` into `MainChapter` and related components to handle offline scenarios for chapter operations.
- Add conditional logic to toggle between server API requests and offline IPC handlers (`db:chapter:add`, `db:chapter:remove`).
- Extend `GET /book/story` endpoint to include `mainChapter` data.
- Refactor IPC handlers for chapters to accept structured data arguments with stricter typings.
- Update frontend key assignments for `BookList` component for improved rendering stability.
This commit is contained in:
natreex
2025-11-26 23:17:25 -05:00
parent 23f1592c22
commit db2c88a42d
4 changed files with 42 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Book from '../database/models/Book.js';
import type { BookProps, GuideLine, GuideLineAI, Act, Issue, WorldProps } from '../database/models/Book.js';
import Chapter from '../database/models/Chapter.js';
import type { ChapterProps } from '../database/models/Chapter.js';
interface UpdateBookBasicData {
@@ -30,6 +31,7 @@ interface UpdateGuideLineData {
interface StoryData {
acts: Act[];
issues: Issue[];
mainChapter: ChapterProps[];
}
interface UpdateStoryData {
@@ -144,7 +146,7 @@ ipcMain.handle('db:book:guideline:update', createHandler<UpdateGuideLineData, bo
)
);
// GET /book/story - Get story data (acts + issues)
// GET /book/story - Get story data (acts + issues + mainChapter)
interface GetStoryData {
bookid: string;
}
@@ -152,9 +154,11 @@ ipcMain.handle('db:book:story:get', createHandler<GetStoryData, StoryData>(
async function(userId: string, data: GetStoryData, lang: 'fr' | 'en'):Promise<StoryData> {
const acts:Act[] = await Book.getActsData(userId, data.bookid, lang);
const issues:Issue[] = await Book.getIssuesFromBook(userId, data.bookid, lang);
const mainChapter:ChapterProps[] = Chapter.getAllChaptersFromABook(userId, data.bookid, lang);
return {
acts,
issues
issues,
mainChapter
};
}
)

View File

@@ -115,10 +115,13 @@ ipcMain.handle('db:chapter:add', createHandler<AddChapterData, string>(
);
// DELETE /chapter/remove - Remove chapter
ipcMain.handle('db:chapter:remove', createHandler<string, boolean>(
function(userId: string, chapterId: string, lang: 'fr' | 'en'): boolean {
console.log(userId,chapterId,lang)
return Chapter.removeChapter(userId, chapterId, lang);
interface RemoveChapterData {
chapterId: string;
bookId?: string;
}
ipcMain.handle('db:chapter:remove', createHandler<RemoveChapterData, boolean>(
function(userId: string, data: RemoveChapterData, lang: 'fr' | 'en'): boolean {
return Chapter.removeChapter(userId, data.chapterId, lang);
}
)
);