-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9 implement character display component (#10)
* Start character display * Send file hook * basic character display * make initiative editable * process input after enter key * Remove dynamic data * Format * Add delete functionality
- Loading branch information
Showing
9 changed files
with
163 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run Main App", | ||
"type": "shell", | ||
"command": "npm run dev", | ||
"runOptions": { | ||
"runOn": "default" | ||
}, | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
} | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useState } from "react"; | ||
// import strings from "@/strings"; | ||
|
||
export interface CharacterDisplayProps { | ||
sourceFile: File | null; | ||
} | ||
|
||
export const CharacterDisplay: React.FC<CharacterDisplayProps> = ({ | ||
sourceFile, | ||
}) => { | ||
const [characterData, setCharacterData] = useState<JSON | null>(null); | ||
|
||
if (sourceFile !== null) { | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
try { | ||
const jsonData = JSON.parse(reader.result as string); | ||
setCharacterData(jsonData); | ||
} catch (error) { | ||
console.error("Error parsing JSON file:", error); | ||
} | ||
}; | ||
reader.readAsText(sourceFile); | ||
} | ||
|
||
if (characterData === null) { | ||
return ( | ||
<div className="flex flex-col items-center justify-center"> | ||
<p className="text-black dark:text-white">No file selected</p> | ||
</div> | ||
); | ||
} else { | ||
const tableRows = Object.keys(characterData).map((key) => ( | ||
<tr key={key}> | ||
<td className="font-bold"> {key}: </td> | ||
<td>{characterData[key]}</td> | ||
</tr> | ||
)); | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center"> | ||
{characterData !== null && <div>{tableRows}</div>} | ||
</div> | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
export class Character { | ||
name!: string; | ||
initiative!: number; | ||
initiativeDisplay!: number; | ||
fileReference!: File; | ||
active!: boolean; | ||
// TODO: remove this field and read the dynamic data from the fileReference | ||
dynamicData!: Record<string, string | number>; // Object to store dynamic data fields | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters