Add character deletion functionality with confirmation workflow

- Added `handleDeleteCharacter` method to handle character deletion with confirmation prompts.
- Updated `CharacterComponent` and `CharacterDetail` to include delete button and related logic.
- Localized new strings for character deletion (e.g., confirmation prompts, success/error messages).
- Enhanced database repository methods (`deleteCharacter`) to handle character deletion securely.
- Improved synchronization workflows to accommodate character deletion.
This commit is contained in:
natreex
2026-01-22 15:09:04 -05:00
parent 9461eb6120
commit 4e462670a9
16 changed files with 383 additions and 59 deletions

View File

@@ -198,6 +198,32 @@ export default class CharacterRepo {
}
}
/**
* Deletes a character and all its related data (attributes) from the database.
* @param userId - The unique identifier of the user
* @param characterId - The unique identifier of the character to delete
* @param lang - The language for error messages ('fr' or 'en')
* @returns True if the deletion was successful, false otherwise
*/
static deleteCharacter(userId: string, characterId: string, lang: 'fr' | 'en' = 'fr'): boolean {
try {
const db: Database = System.getDb();
const deleteAttributesQuery: string = 'DELETE FROM `book_characters_attributes` WHERE `character_id`=? AND `user_id`=?';
db.run(deleteAttributesQuery, [characterId, userId]);
const deleteCharacterQuery: string = 'DELETE FROM `book_characters` WHERE `character_id`=? AND `user_id`=?';
const result: RunResult = db.run(deleteCharacterQuery, [characterId, userId]);
return result.changes > 0;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de supprimer le personnage.` : `Unable to delete character.`);
} else {
console.error("An unknown error occurred.");
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
}
/**
* Deletes a character attribute from the database.
* @param userId - The unique identifier of the user