Add error handling, enhance syncing, and refactor deletion logic

- Introduce new error messages for syncing and book deletion in `en.json`.
- Update `DeleteBook` to support local-only deletion and synced book management.
- Refine offline/online behavior with `deleteLocalToo` checkbox and update related state handling.
- Extend repository and IPC methods to handle optional IDs for updates.
- Add `SyncQueueContext` for queueing offline changes and improving synchronization workflows.
- Enhance refined text generation logic in `DraftCompanion` and `GhostWriter` components.
- Replace PUT with PATCH for world updates to align with API expectations.
- Streamline `AlertBox` by integrating dynamic translation keys for deletion prompts.
This commit is contained in:
natreex
2026-01-10 15:50:03 -05:00
parent 060693f152
commit 7f34421212
26 changed files with 506 additions and 100 deletions

View File

@@ -53,28 +53,33 @@ interface CreateBookData {
interface AddIncidentData {
bookId: string;
name: string;
incidentId?: string;
}
interface AddPlotPointData {
bookId: string;
name: string;
incidentId: string;
plotPointId?: string;
}
interface AddIssueData {
bookId: string;
name: string;
issueId?: string;
}
interface AddWorldData {
bookId: string;
worldName: string;
id?: string;
}
interface AddWorldElementData {
worldId: string;
elementName: string;
elementType: number;
id?: string;
}
interface SetAIGuideLineData {
@@ -235,7 +240,7 @@ ipcMain.handle(
'db:book:incident:add',
createHandler<AddIncidentData, string>(
function(userId: string, data: AddIncidentData, lang: 'fr' | 'en') {
return Book.addNewIncident(userId, data.bookId, data.name, lang);
return Book.addNewIncident(userId, data.bookId, data.name, lang, data.incidentId);
}
)
);
@@ -261,7 +266,8 @@ ipcMain.handle('db:book:plot:add', createHandler<AddPlotPointData, string>(
data.bookId,
data.incidentId,
data.name,
lang
lang,
data.plotPointId
);
}
)
@@ -283,7 +289,7 @@ ipcMain.handle(
// POST /book/issue/add - Add issue
ipcMain.handle('db:book:issue:add', createHandler<AddIssueData, string>(
function(userId: string, data: AddIssueData, lang: 'fr' | 'en') {
return Book.addNewIssue(userId, data.bookId, data.name, lang);
return Book.addNewIssue(userId, data.bookId, data.name, lang, data.issueId);
}
)
);
@@ -314,7 +320,7 @@ ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldProps[]>(
// POST /book/world/add - Add world
ipcMain.handle('db:book:world:add', createHandler<AddWorldData, string>(
function(userId: string, data: AddWorldData, lang: 'fr' | 'en') {
return Book.addNewWorld(userId, data.bookId, data.worldName, lang);
return Book.addNewWorld(userId, data.bookId, data.worldName, lang, data.id);
}
)
);
@@ -327,7 +333,8 @@ ipcMain.handle('db:book:world:element:add', createHandler<AddWorldElementData, s
data.worldId,
data.elementName,
data.elementType.toString(),
lang
lang,
data.id
);
}
)

View File

@@ -21,6 +21,7 @@ interface AddChapterData {
bookId: string;
title: string;
chapterOrder: number;
chapterId?: string;
}
interface UpdateChapterData {
@@ -35,6 +36,7 @@ interface AddChapterInformationData {
bookId: string;
plotId: string | null;
incidentId: string | null;
chapterInfoId?: string;
}
interface GetChapterContentData {
@@ -109,7 +111,7 @@ ipcMain.handle('db:chapter:last', createHandler<string, ChapterProps | null>(
// POST /chapter/add - Add new chapter
ipcMain.handle('db:chapter:add', createHandler<AddChapterData, string>(
function(userId: string, data: AddChapterData, lang: 'fr' | 'en'): string {
return Chapter.addChapter(userId, data.bookId, data.title, 0, data.chapterOrder, lang);
return Chapter.addChapter(userId, data.bookId, data.title, 0, data.chapterOrder, lang, data.chapterId);
}
)
);
@@ -144,7 +146,8 @@ ipcMain.handle('db:chapter:information:add', createHandler<AddChapterInformation
data.bookId,
data.plotId,
data.incidentId,
lang
lang,
data.chapterInfoId
);
}
)

View File

@@ -6,12 +6,14 @@ import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../
interface AddCharacterData {
character: CharacterPropsPost;
bookId: string;
id?: string;
}
interface AddAttributeData {
characterId: string;
type: string;
name: string;
id?: string;
}
// GET /character/list - Get character list
@@ -39,7 +41,7 @@ ipcMain.handle('db:character:attributes', createHandler<GetCharacterAttributesDa
// POST /character/add - Add new character
ipcMain.handle('db:character:create', createHandler<AddCharacterData, string>(
function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string {
return Character.addNewCharacter(userId, data.character, data.bookId, lang);
return Character.addNewCharacter(userId, data.character, data.bookId, lang, data.id);
}
)
);
@@ -47,7 +49,7 @@ ipcMain.handle('db:character:create', createHandler<AddCharacterData, string>(
// POST /character/attribute/add - Add attribute to character
ipcMain.handle('db:character:attribute:add', createHandler<AddAttributeData, string>(
function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string {
return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang);
return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang, data.id);
}
)
);

View File

@@ -11,16 +11,19 @@ interface UpdateLocationResponse {
interface AddLocationSectionData {
locationName: string;
bookId: string;
id?: string;
}
interface AddLocationElementData {
locationId: string;
elementName: string;
id?: string;
}
interface AddLocationSubElementData {
elementId: string;
subElementName: string;
id?: string;
}
interface UpdateLocationData {
@@ -41,7 +44,7 @@ ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationPro
// POST /location/section/add - Add location section
ipcMain.handle('db:location:section:add', createHandler<AddLocationSectionData, string>(
function(userId: string, data: AddLocationSectionData, lang: 'fr' | 'en'): string {
return Location.addLocationSection(userId, data.locationName, data.bookId, lang);
return Location.addLocationSection(userId, data.locationName, data.bookId, lang, data.id);
}
)
);
@@ -49,7 +52,7 @@ ipcMain.handle('db:location:section:add', createHandler<AddLocationSectionData,
// POST /location/element/add - Add location element
ipcMain.handle('db:location:element:add', createHandler<AddLocationElementData, string>(
function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en'): string {
return Location.addLocationElement(userId, data.locationId, data.elementName, lang);
return Location.addLocationElement(userId, data.locationId, data.elementName, lang, data.id);
}
)
);
@@ -57,7 +60,7 @@ ipcMain.handle('db:location:element:add', createHandler<AddLocationElementData,
// POST /location/sub-element/add - Add location sub-element
ipcMain.handle('db:location:subelement:add', createHandler<AddLocationSubElementData, string>(
function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en'): string {
return Location.addLocationSubElement(userId, data.elementId, data.subElementName, lang);
return Location.addLocationSubElement(userId, data.elementId, data.subElementName, lang, data.id);
}
)
);