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:
@@ -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);
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user