Add enable/disable management for book tools (characters, worlds, and locations)

- Introduced toggling functionality for managing `characters`, `worlds`, and `locations` tool availability per book.
- Updated `CharacterComponent`, `WorldSetting`, and `LocationComponent` with toggle switches for tool enablement.
- Added `book_tools` database table and related schema migration for storing tool settings.
- Extended API calls, models, and IPC handlers to support tool enablement states.
- Localized new strings for English with supporting descriptions and messages.
- Adjusted conditional rendering logic across components to respect tool enablement.
This commit is contained in:
natreex
2026-01-14 17:42:59 -05:00
parent 7215ac5c4f
commit e45a15225b
19 changed files with 782 additions and 341 deletions

View File

@@ -5,6 +5,7 @@ import LocationRepo, {
} from "../repositories/location.repository.js";
import System from "../System.js";
import {getUserEncryptionKey} from "../keyManager.js";
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
export interface SubElement {
id: string;
@@ -25,6 +26,11 @@ export interface LocationProps {
elements: Element[];
}
export interface LocationListResponse {
locations: LocationProps[];
enabled: boolean;
}
export interface SyncedLocation {
id: string;
name: string;
@@ -51,11 +57,16 @@ export default class Location {
* @param userId - The user's unique identifier.
* @param bookId - The book's unique identifier.
* @param lang - The language for error messages ('fr' or 'en'). Defaults to 'fr'.
* @returns An array of location properties with their elements and sub-elements.
* @returns LocationListResponse containing an array of locations and enabled flag.
*/
static getAllLocations(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): LocationProps[] {
static getAllLocations(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): LocationListResponse {
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
const enabled: boolean = bookTools ? bookTools.locations_enabled === 1 : false;
const locationRecords: LocationQueryResult[] = LocationRepo.getLocation(userId, bookId, lang);
if (!locationRecords || locationRecords.length === 0) return [];
if (!locationRecords || locationRecords.length === 0) {
return { locations: [], enabled };
}
const userKey: string = getUserEncryptionKey(userId);
const locationArray: LocationProps[] = [];
@@ -104,7 +115,7 @@ export default class Location {
}
}
}
return locationArray;
return { locations: locationArray, enabled };
}
/**
@@ -325,4 +336,5 @@ export default class Location {
return descriptionFields.join('\n');
}).join('\n\n');
}
}