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

@@ -28,6 +28,7 @@ interface CharacterDetailProps {
attrId: string,
) => void;
handleSaveCharacter: () => void;
handleDeleteCharacter: (characterId: string) => Promise<void>;
}
const initialCharacterState: CharacterProps = {
@@ -163,7 +164,41 @@ export function CharacterComponent({showToggle = true}: {showToggle?: boolean},
}
}
}
async function handleDeleteCharacter(characterId: string): Promise<void> {
try {
let response: boolean;
if (isCurrentlyOffline() || book?.localBook) {
response = await window.electron.invoke<boolean>('db:character:delete', {
characterId: characterId,
});
} else {
response = await System.authDeleteToServer<boolean>('character/delete', {
characterId: characterId,
}, session.accessToken, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === book?.bookId)) {
addToQueue('db:character:delete', {
characterId: characterId,
});
}
}
if (!response) {
errorMessage(t("characterComponent.errorDeleteCharacter"));
return;
}
setCharacters(characters.filter((c: CharacterProps): boolean => c.id !== characterId));
setSelectedCharacter(null);
successMessage(t("characterComponent.successDelete"));
} catch (e: unknown) {
if (e instanceof Error) {
errorMessage(e.message);
} else {
errorMessage(t("common.unknownError"));
}
}
}
async function addNewCharacter(updatedCharacter: CharacterProps): Promise<void> {
if (!updatedCharacter.name) {
errorMessage(t("characterComponent.errorNameRequired"));
@@ -394,6 +429,7 @@ export function CharacterComponent({showToggle = true}: {showToggle?: boolean},
handleRemoveElement={handleRemoveElement}
handleCharacterChange={handleCharacterChange}
handleSaveCharacter={handleSaveCharacter}
handleDeleteCharacter={handleDeleteCharacter}
/>
) : (
<CharacterList