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:
natreex
2025-11-26 22:52:34 -05:00
parent e1abcd9490
commit 23f1592c22
15 changed files with 518 additions and 201 deletions

View File

@@ -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);
}
)
);