-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c319220
commit 4a363d8
Showing
6 changed files
with
145 additions
and
92 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
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,42 +1,87 @@ | ||
import React from "react" | ||
import React, {useEffect,useState,useContext} from "react" | ||
import styles from "./JsonAttributes.module.css" | ||
import { SceneContext } from "../context/SceneContext" | ||
import MenuTitle from "./MenuTitle" | ||
|
||
export default function JsonAttributes({jsonSelection}){ | ||
export default function JsonAttributes({jsonSelectionArray}){ | ||
const { | ||
setSelectedOptions | ||
} = useContext(SceneContext); | ||
const [index, setIndex] = useState(0); | ||
|
||
return ( | ||
jsonSelection != null ? ( | ||
<div className={styles["InformationContainerPos"]}> | ||
<MenuTitle title="TraitSelection" width={180} right={20} /> | ||
<div className={styles["scrollContainer"]}> | ||
{jsonSelection.name && ( | ||
<div style={{ textAlign: 'center'}}> | ||
useEffect(() => { | ||
if (jsonSelectionArray?.length >0) | ||
setSelectedOptions(jsonSelectionArray[0].options) | ||
setIndex(0); | ||
}, [jsonSelectionArray]) | ||
|
||
const nextJson = async () => { | ||
if (index >= jsonSelectionArray.length -1){ | ||
setSelectedOptions(jsonSelectionArray[0].options) | ||
setIndex(0); | ||
} | ||
else{ | ||
const newIndex = index + 1; | ||
setSelectedOptions(jsonSelectionArray[newIndex].options) | ||
setIndex(newIndex); | ||
} | ||
} | ||
const prevJson = async () => { | ||
console.log("prev") | ||
if (index <= 0){ | ||
setSelectedOptions(jsonSelectionArray[jsonSelectionArray.length].options) | ||
setIndex(jsonSelectionArray.length -1); | ||
} | ||
else{ | ||
const newIndex = index-1; | ||
setSelectedOptions(jsonSelectionArray[newIndex].options) | ||
setIndex(newIndex); | ||
} | ||
} | ||
|
||
return ( | ||
jsonSelectionArray?.length > 0 ? ( | ||
<div className={styles["InformationContainerPos"]}> | ||
<MenuTitle title="TraitSelection" width={180} right={20} /> | ||
<div className={styles["scrollContainer"]}> | ||
<div className={styles["flexSelect"]}> | ||
{jsonSelectionArray?.length > 1 ? <div // add left arrow only when array is greater than 1 | ||
className={`${styles["arrow-button"]} ${styles["left-button"]}`} | ||
onClick={prevJson} | ||
/>:<></>} | ||
{jsonSelectionArray[index].name && ( | ||
<div style={{ textAlign: 'center', flex: 1}}> | ||
<div className={styles["traitInfoTitle"]}> | ||
{jsonSelection.name} | ||
{jsonSelectionArray[index].name} | ||
</div> | ||
</div> | ||
)} | ||
{jsonSelection.thumb && ( | ||
<img | ||
src={jsonSelection.thumb} | ||
alt="Selection Thumbnail" | ||
style={{ | ||
width: '280px', | ||
height: '460px', | ||
display: 'block', | ||
margin: '20px auto 20px', | ||
}} | ||
/> | ||
)} | ||
{jsonSelection.attributes.map((attribute) => ( | ||
<div key={`json:${attribute.trait}_${attribute.name}`}> | ||
<div className={styles["traitInfoText"]}> | ||
{`${attribute.trait} : ${attribute.id}`} | ||
</div> | ||
</div> | ||
))} | ||
{jsonSelectionArray?.length > 1 ? <div //add right arrow only when array is greater than 1 | ||
className={`${styles["arrow-button"]} ${styles["right-button"]}`} | ||
onClick={nextJson} | ||
/>:<></>} | ||
</div> | ||
{jsonSelectionArray[index].thumb && ( | ||
<img | ||
src={jsonSelectionArray[index].thumb} | ||
alt="Selection Thumbnail" | ||
style={{ | ||
width: '280px', | ||
height: '460px', | ||
display: 'block', | ||
margin: '20px auto 20px', | ||
}} | ||
/> | ||
)} | ||
{jsonSelectionArray[index].attributes.map((attribute) => ( | ||
<div key={`json:${attribute.trait}_${attribute.name}`}> | ||
<div className={styles["traitInfoText"]}> | ||
{`${attribute.trait} : ${attribute.id}`} | ||
</div> | ||
</div> | ||
))} | ||
</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