Skip to content

Commit

Permalink
Add delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bduhbya committed Sep 9, 2024
1 parent 1e6cfc9 commit 73cb02a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/components/CombatTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ const CombatTracker: React.FC<CombatTrackerProps> = ({ SetCharacterFile }) => {
setCombatCharacters(newCombatCharacters);
};

const handleCharacterDelete = (index: number) => {
const newCombatCharacters = [...combatCharacters];
if (newCombatCharacters[index].active) {
// If the character being deleted is the active character, set the next character as active
newCombatCharacters[(index + 1) % newCombatCharacters.length].active = true;
}
newCombatCharacters.splice(index, 1);
setCombatCharacters(newCombatCharacters);
};

const handleCharacterClick = (
character: Character,
SetCharacterFile: (file: File) => void,
Expand Down Expand Up @@ -184,6 +194,7 @@ const CombatTracker: React.FC<CombatTrackerProps> = ({ SetCharacterFile }) => {
{strings.currentCharacterColumnLabel}
</th>
<th className="border p-2">{strings.characterNameColumnLabel}</th>
<th className="border p-2">{strings.actionsLabel}</th>
<th className="border p-2">{strings.initiativeColumnLabel}</th>
</tr>
</thead>
Expand All @@ -201,6 +212,14 @@ const CombatTracker: React.FC<CombatTrackerProps> = ({ SetCharacterFile }) => {
{character.active && <CheckmarkIconPositive />}
</td>
<td className="border p-2">{character.name}</td>
<td className="border p-2">
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded-full mb-4 mr-4"
onClick={() => handleCharacterDelete(index)}
>
{strings.deleteString}
</button>
</td>
<td className="border p-2">
<input
type="number"
Expand Down
2 changes: 2 additions & 0 deletions src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const strings = {
// Common strings
cancelString: "Cancel",
deleteString: "Delete",

// CombatTracker strings
addToCombatButton: "Add Character to Combat",
Expand All @@ -15,6 +16,7 @@ const strings = {
fileParsingError: "Unable to parse JSON file",
moveUpLabel: "Move Up",
moveDownLabel: "Move Down",
actionsLabel: "Actions",

// InitiativeInputDialog strings
initiativePrompt: "Enter Initiative",
Expand Down

0 comments on commit 73cb02a

Please sign in to comment.