Files
ERitors-Scribe-Desktop/electron/ipc/location.ipc.ts
natreex 7f34421212 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.
2026-01-10 15:50:03 -05:00

108 lines
3.7 KiB
TypeScript

import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Location from '../database/models/Location.js';
import type { LocationProps } from '../database/models/Location.js';
interface UpdateLocationResponse {
valid: boolean;
message: string;
}
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 {
locations: LocationProps[];
}
// GET /location/all - Get all locations
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);
}
)
);
// 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, data.id);
}
)
);
// 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, data.id);
}
)
);
// 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, data.id);
}
)
);
// POST /location/update - Update location section
ipcMain.handle('db:location:update', createHandler<UpdateLocationData, UpdateLocationResponse>(
function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en'): UpdateLocationResponse {
return Location.updateLocationSection(userId, data.locations, lang);
}
)
);
// DELETE /location/delete - Delete location section
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
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
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);
}
)
);