diff --git a/src/client/components/input/drag-and-drop.tsx b/src/client/components/input/drag-and-drop.tsx index 7ec2ec3fa9..306bcad22c 100644 --- a/src/client/components/input/drag-and-drop.tsx +++ b/src/client/components/input/drag-and-drop.tsx @@ -28,22 +28,24 @@ const {useState, useCallback} = React; * The Achievement interface, defining the properties of an achievement. * @typedef * @property {string} name - The name of the achievement. -* @property {string} src - The source URL of the achievement's badge image. -* @property {string} id - The ID of the achievement. +* @property {string} badgeUrl - The source URL of the achievement's badge image. +* @property {number} id - The ID of the achievement. */ type Achievement = { name: string; - src: string; - id: string; + badgeUrl: string | null; + id: number; }; /** * Props for DragAndDropImage component * @typedef {Object} Props * @property {string} name - The name of the DragAndDrop component. + * @property {Achievement} initialAchievement - The initial achievement to display in the card. */ type Props = { name: string; + initialAchievement?: Achievement; }; /** @@ -53,16 +55,14 @@ type Props = { * @param {Props} props - The props object containing the following: * @returns {JSX.Element} A React component that displays a drag-and-drop card for an achievement. */ -function DragAndDrop({name}: Props): JSX.Element { - const [achievement, setAchievement] = useState({ - name: 'drag badge to set', - src: '/images/blankbadge.svg' - }); +function DragAndDrop({name, initialAchievement}: Props): JSX.Element { + const [achievement, setAchievement] = useState(initialAchievement); const handleClick = useCallback((event: React.MouseEvent) => { event.preventDefault(); setAchievement({ - name: 'drag badge to set', - src: '/images/blankbadge.svg' + badgeUrl: '/images/blankbadge.svg', + id: null, + name: 'drag badge to set' }); }); const handleDragOver = useCallback((event: React.DragEvent) => { @@ -78,7 +78,11 @@ function DragAndDrop({name}: Props): JSX.Element { catch (error) { return; } - setAchievement(data); + setAchievement({ + badgeUrl: data.src, + id: data.id, + name: data.name + }); }); return ( @@ -98,7 +102,7 @@ function DragAndDrop({name}: Props): JSX.Element {
@@ -111,7 +115,19 @@ function DragAndDrop({name}: Props): JSX.Element { DragAndDrop.displayName = 'DragAndDrop'; DragAndDrop.propTypes = { + initialAchievement: PropTypes.shape({ + badgeUrl: PropTypes.string, + id: PropTypes.number, + name: PropTypes.string.isRequired + }), name: PropTypes.string.isRequired }; +DragAndDrop.defaultProps = { + initialAchievement: { + badgeUrl: '/images/blankbadge.svg', + id: null, + name: 'drag badge to set' + } +}; export default DragAndDrop; diff --git a/src/client/components/pages/parts/editor-achievements.js b/src/client/components/pages/parts/editor-achievements.js index e09b994808..903d0d9399 100644 --- a/src/client/components/pages/parts/editor-achievements.js +++ b/src/client/components/pages/parts/editor-achievements.js @@ -39,6 +39,7 @@ class EditorAchievementTab extends React.Component { */ constructor(props) { super(props); + this.currAchievement = props.currAchievement; this.state = { achievement: props.achievement, editor: props.editor @@ -91,9 +92,18 @@ class EditorAchievementTab extends React.Component { method="post" > - - - + + +