Add offline mode logic for book, story, and world operations
- Integrate `OfflineContext` into book, story settings, and related components. - Add conditional logic to toggle between server API requests and offline IPC handlers (`db:book:delete`, `db:book:story:get`, `db:location:all`, etc.). - Refactor and update IPC handlers to accept structured data arguments for improved consistency (`data: object`). - Ensure stricter typings in IPC handlers and frontend functions. - Improve error handling and user feedback in both online and offline modes.
This commit is contained in:
@@ -111,10 +111,13 @@ ipcMain.handle('db:book:updateBasicInformation', createHandler<UpdateBookBasicDa
|
||||
);
|
||||
|
||||
// GET /book/guide-line - Get guideline
|
||||
interface GetGuidelineData {
|
||||
id: string;
|
||||
}
|
||||
ipcMain.handle(
|
||||
'db:book:guideline:get',
|
||||
createHandler<string, GuideLine | null>(async function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||
return await Book.getGuideLine(userId, bookId, lang);
|
||||
createHandler<GetGuidelineData, GuideLine | null>(async function(userId: string, data: GetGuidelineData, lang: 'fr' | 'en') {
|
||||
return await Book.getGuideLine(userId, data.id, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -142,10 +145,13 @@ ipcMain.handle('db:book:guideline:update', createHandler<UpdateGuideLineData, bo
|
||||
);
|
||||
|
||||
// GET /book/story - Get story data (acts + issues)
|
||||
ipcMain.handle('db:book:story:get', createHandler<string, StoryData>(
|
||||
async function(userId: string, bookId: string, lang: 'fr' | 'en'):Promise<StoryData> {
|
||||
const acts:Act[] = await Book.getActsData(userId, bookId, lang);
|
||||
const issues:Issue[] = await Book.getIssuesFromBook(userId, bookId, lang);
|
||||
interface GetStoryData {
|
||||
bookid: string;
|
||||
}
|
||||
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);
|
||||
return {
|
||||
acts,
|
||||
issues
|
||||
@@ -220,11 +226,14 @@ ipcMain.handle('db:book:plot:add', createHandler<AddPlotPointData, string>(
|
||||
);
|
||||
|
||||
// DELETE /book/plot/remove - Remove plot point
|
||||
interface RemovePlotData {
|
||||
plotId: string;
|
||||
}
|
||||
ipcMain.handle(
|
||||
'db:book:plot:remove',
|
||||
createHandler<string, boolean>(
|
||||
function(userId: string, plotPointId: string, lang: 'fr' | 'en') {
|
||||
return Book.removePlotPoint(userId, plotPointId, lang);
|
||||
createHandler<RemovePlotData, boolean>(
|
||||
function(userId: string, data: RemovePlotData, lang: 'fr' | 'en') {
|
||||
return Book.removePlotPoint(userId, data.plotId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -238,17 +247,24 @@ ipcMain.handle('db:book:issue:add', createHandler<AddIssueData, string>(
|
||||
);
|
||||
|
||||
// DELETE /book/issue/remove - Remove issue
|
||||
ipcMain.handle('db:book:issue:remove', createHandler<string, boolean>(
|
||||
function(userId: string, issueId: string, lang: 'fr' | 'en') {
|
||||
return Book.removeIssue(userId, issueId, lang);
|
||||
interface RemoveIssueData {
|
||||
bookId: string;
|
||||
issueId: string;
|
||||
}
|
||||
ipcMain.handle('db:book:issue:remove', createHandler<RemoveIssueData, boolean>(
|
||||
function(userId: string, data: RemoveIssueData, lang: 'fr' | 'en') {
|
||||
return Book.removeIssue(userId, data.issueId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// GET /book/worlds - Get worlds for book
|
||||
ipcMain.handle('db:book:worlds:get', createHandler<string, WorldProps[]>(
|
||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||
return Book.getWorlds(userId, bookId, lang);
|
||||
interface GetWorldsData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldProps[]>(
|
||||
function(userId: string, data: GetWorldsData, lang: 'fr' | 'en') {
|
||||
return Book.getWorlds(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -275,25 +291,34 @@ ipcMain.handle('db:book:world:element:add', createHandler<AddWorldElementData, s
|
||||
)
|
||||
);
|
||||
// DELETE /book/world/element/delete - Remove element from world
|
||||
ipcMain.handle('db:book:world:element:remove', createHandler<string, boolean>(
|
||||
function(userId: string, elementId: string, lang: 'fr' | 'en') {
|
||||
return Book.removeElementFromWorld(userId, elementId, lang);
|
||||
interface RemoveWorldElementData {
|
||||
elementId: string;
|
||||
}
|
||||
ipcMain.handle('db:book:world:element:remove', createHandler<RemoveWorldElementData, boolean>(
|
||||
function(userId: string, data: RemoveWorldElementData, lang: 'fr' | 'en') {
|
||||
return Book.removeElementFromWorld(userId, data.elementId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// DELETE /book/delete - Delete book
|
||||
ipcMain.handle('db:book:delete', createHandler<string, boolean>(
|
||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||
return Book.removeBook(userId, bookId, lang);
|
||||
interface DeleteBookData {
|
||||
id: string;
|
||||
}
|
||||
ipcMain.handle('db:book:delete', createHandler<DeleteBookData, boolean>(
|
||||
function(userId: string, data: DeleteBookData, lang: 'fr' | 'en') {
|
||||
return Book.removeBook(userId, data.id, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// GET /book/ai/guideline - Get AI guideline
|
||||
ipcMain.handle('db:book:guideline:ai:get', createHandler<string, GuideLineAI>(
|
||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||
return Book.getGuideLineAI(userId, bookId, lang);
|
||||
interface GetAIGuidelineData {
|
||||
id: string;
|
||||
}
|
||||
ipcMain.handle('db:book:guideline:ai:get', createHandler<GetAIGuidelineData, GuideLineAI>(
|
||||
function(userId: string, data: GetAIGuidelineData, lang: 'fr' | 'en') {
|
||||
return Book.getGuideLineAI(userId, data.id, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@@ -148,9 +148,12 @@ ipcMain.handle('db:chapter:information:add', createHandler<AddChapterInformation
|
||||
);
|
||||
|
||||
// DELETE /chapter/resume/remove - Remove chapter information
|
||||
ipcMain.handle('db:chapter:information:remove', createHandler<string, boolean>(
|
||||
function(userId: string, chapterInfoId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Chapter.removeChapterInformation(userId, chapterInfoId, lang);
|
||||
interface RemoveChapterInfoData {
|
||||
chapterInfoId: string;
|
||||
}
|
||||
ipcMain.handle('db:chapter:information:remove', createHandler<RemoveChapterInfoData, boolean>(
|
||||
function(userId: string, data: RemoveChapterInfoData, lang: 'fr' | 'en'): boolean {
|
||||
return Chapter.removeChapterInformation(userId, data.chapterInfoId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@@ -15,17 +15,23 @@ interface AddAttributeData {
|
||||
}
|
||||
|
||||
// GET /character/list - Get character list
|
||||
ipcMain.handle('db:character:list', createHandler<string, CharacterProps[]>(
|
||||
function(userId: string, bookId: string, lang: 'fr' | 'en'): CharacterProps[] {
|
||||
return Character.getCharacterList(userId, bookId, lang);
|
||||
interface GetCharacterListData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterProps[]>(
|
||||
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] {
|
||||
return Character.getCharacterList(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// GET /character/attribute - Get character attributes
|
||||
ipcMain.handle('db:character:attributes', createHandler<string, CharacterAttribute[]>(
|
||||
function(userId: string, characterId: string, lang: 'fr' | 'en'): CharacterAttribute[] {
|
||||
return Character.getAttributes(characterId, userId, lang);
|
||||
interface GetCharacterAttributesData {
|
||||
characterId: string;
|
||||
}
|
||||
ipcMain.handle('db:character:attributes', createHandler<GetCharacterAttributesData, CharacterAttribute[]>(
|
||||
function(userId: string, data: GetCharacterAttributesData, lang: 'fr' | 'en'): CharacterAttribute[] {
|
||||
return Character.getAttributes(data.characterId, userId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -47,17 +53,23 @@ ipcMain.handle('db:character:attribute:add', createHandler<AddAttributeData, str
|
||||
);
|
||||
|
||||
// DELETE /character/attribute/delete - Delete character attribute
|
||||
ipcMain.handle('db:character:attribute:delete', createHandler<string, boolean>(
|
||||
function(userId: string, attributeId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Character.deleteAttribute(userId, attributeId, lang);
|
||||
interface DeleteAttributeData {
|
||||
attributeId: string;
|
||||
}
|
||||
ipcMain.handle('db:character:attribute:delete', createHandler<DeleteAttributeData, boolean>(
|
||||
function(userId: string, data: DeleteAttributeData, lang: 'fr' | 'en'): boolean {
|
||||
return Character.deleteAttribute(userId, data.attributeId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// POST /character/update - Update character
|
||||
ipcMain.handle('db:character:update', createHandler<CharacterPropsPost, boolean>(
|
||||
function(userId: string, character: CharacterPropsPost, lang: 'fr' | 'en'): boolean {
|
||||
return Character.updateCharacter(userId, character, lang);
|
||||
interface UpdateCharacterData {
|
||||
character: CharacterPropsPost;
|
||||
}
|
||||
ipcMain.handle('db:character:update', createHandler<UpdateCharacterData, boolean>(
|
||||
function(userId: string, data: UpdateCharacterData, lang: 'fr' | 'en'): boolean {
|
||||
return Character.updateCharacter(userId, data.character, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -28,9 +28,12 @@ interface UpdateLocationData {
|
||||
}
|
||||
|
||||
// GET /location/all - Get all locations
|
||||
ipcMain.handle('db:location:all', createHandler<string, LocationProps[]>(
|
||||
function(userId: string, bookId: string, lang: 'fr' | 'en'): LocationProps[] {
|
||||
return Location.getAllLocations(userId, bookId, lang);
|
||||
interface GetAllLocationsData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationProps[]>(
|
||||
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationProps[] {
|
||||
return Location.getAllLocations(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -68,25 +71,34 @@ ipcMain.handle('db:location:update', createHandler<UpdateLocationData, UpdateLoc
|
||||
);
|
||||
|
||||
// DELETE /location/delete - Delete location section
|
||||
ipcMain.handle('db:location:delete', createHandler<string, boolean>(
|
||||
function(userId: string, locationId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationSection(userId, locationId, lang);
|
||||
interface DeleteLocationData {
|
||||
locationId: string;
|
||||
}
|
||||
ipcMain.handle('db:location:delete', createHandler<DeleteLocationData, boolean>(
|
||||
function(userId: string, data: DeleteLocationData, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationSection(userId, data.locationId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// DELETE /location/element/delete - Delete location element
|
||||
ipcMain.handle('db:location:element:delete', createHandler<string, boolean>(
|
||||
function(userId: string, elementId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationElement(userId, elementId, lang);
|
||||
interface DeleteLocationElementData {
|
||||
elementId: string;
|
||||
}
|
||||
ipcMain.handle('db:location:element:delete', createHandler<DeleteLocationElementData, boolean>(
|
||||
function(userId: string, data: DeleteLocationElementData, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationElement(userId, data.elementId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// DELETE /location/sub-element/delete - Delete location sub-element
|
||||
ipcMain.handle('db:location:subelement:delete', createHandler<string, boolean>(
|
||||
function(userId: string, subElementId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationSubElement(userId, subElementId, lang);
|
||||
interface DeleteLocationSubElementData {
|
||||
subElementId: string;
|
||||
}
|
||||
ipcMain.handle('db:location:subelement:delete', createHandler<DeleteLocationSubElementData, boolean>(
|
||||
function(userId: string, data: DeleteLocationSubElementData, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationSubElement(userId, data.subElementId, lang);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user